Repository navigation
Expand find-all-references to more keywords #51232
Description
Background
Today, document highlights/occurrences has special support for when a developer's cursor is over a keyword.
For example, let's say you had your cursor /*$*/ in the following code.
if (foo()) {
// ...
}
else if (bar()) {
// ...
}
else/*$*/ {
// ...
}TypeScript is able to provide what's called "document highlights" (formerly called "occurrences") for the editor to highlight as visual clues. Typically, these keywords will be displayed with a lighter background/foreground in the editor, and the highlights we provide in the above case are denoted with [|these range markers|].
[|if|] (foo()) {
// ...
}
[|else if|] (bar()) {
// ...
}
[|else|] {
// ...
}
Yes, the
else ifis specially highlighted together!
It would be great if find-all-references worked similarly. Editors often has key bindings for iterating through the current set of document highlights (on VS Code this is Go to Next Symbol Highlight - for Windows, the keybinding is F7 and Shift+F7, and in VS, it's Ctrl+Shift+Up/Down); however, these keyboard shortcuts are pretty undiscoverable. Document highlights are a subtle enough hint that users may not even know they exist. So find-all-references has the potential to be a nice delighter for a more-often-used action.
What Would it Support?
I don't know the full list of things document highlights currently supports; however, from what I do know, here's a list of what I think would be useful, ranked loosely by utility.
-
returnkeywords in a specific function scope -
throwkeywords in a specific function ortryblock scope -
breakandcontinuekeywords in a specific loop construct,switchstatement, or labeled statement -
awaitkeywords in a specific function scope -
yieldkeywords in a specific function scope -
exportkeywords in a module or namespace -
caseanddefaultclauses in aswitchstatement - Chained
if/elsebranches -
importkeywords in a module or namespace - Accessibility modifiers in a class (e.g.
public,private,protected,readonly)
Specifics
Many of these are already implemented in document highights/occurrences. The only place I could think that these might differ is whether find-all-references would include the "owning" node in many of these contexts.
For example, today, find-all-references on a case keyword in a switch highlights all of the following:
- All the other
caseclause keywords - The
defaultkeyword for thedefaultclause - The
switchkeyword itself - All of the corresponding
breakstatements
So in the following document highlights request
innerLabel: {
outerLabel: switch (a) {
case 0:
break innerLabel;
/*$*/case 1:
break outerLabel;
default:
break;
}
}you would get
innerLabel: {
outerLabel: [|switch|] (a) {
[|case|] 0:
[|break|] innerLabel;
[|case|] 1:
break outerLabel;
[|default|]:
[|break|];
}
}So should find-all-references on that case actually return all of those? Or should it provide only the other case clauses?
Activity
[-]Expand find-all-references to keywords, based on document highlights[/-][+]Expand find-all-references to more keywords[/+]