TypeScript: Smart select does not select TypeScript object type
- VSCode Version: latest
- OS Version: macOS latest
Steps to Reproduce:
- Paste this into a TypeScript file
type Foo = { /** comment */ status: number; }; - Place cursor just before
status - Run command “expand selection” 4 times
Expected: only the object should be selected:

Actual: the whole type is selected:


Does this issue occur when all extensions are disabled?: Yes
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 17 (10 by maintainers)
Commits related to this issue
- ⚗️ Add test case for JSDoc smart selection (#39618) Signed-off-by: Babak K. Shandiz <babak.k.shandiz@gmail.com> — committed to babakks/TypeScript by babakks 2 years ago
- ⚗️ Add test baseline for JSDoc smart selection (#39618) Signed-off-by: Babak K. Shandiz <babak.k.shandiz@gmail.com> — committed to babakks/TypeScript by babakks 2 years ago
- 🐛 Fix smart selection of propery signatures having JSDoc comments (#49804) * 🐛 Avoid grouping JSDoc nodes of propery signatures with others in smart selection Signed-off-by: Babak K. Shandiz <ba... — committed to microsoft/TypeScript by babakks 2 years ago
@saigeethakandepallicherukuru please go ahead!
Everyone else: Sorry to have not responded before, but No Assignee (up at the top on the right) means no TS team member is working on the bug and it’s up for grabs. Unless there’s already an open PR, it’s a pretty safe bet that no one else is working on any particular bug.
Yep, that confirms the problem is ours. All that code is here. If you add a new test copying the format of this one, you should be able to debug that code and see what’s going on:
I tried to trace the problem on the VS Code side and found some clues that the problem lies within the TS language server.
Problematic case
This is the input code block that I used:
I put the caret at the beginning of the
statusfield (position 5:3) and invoked theExpand Selectioncommand. This is the (flattened) tree of ranges and their parents returned from the TypeScript language server (for any range its parent sits at the next line):VS Code editor expects parents to include their child, but this is broken at the third line (here indicated by the
*). VS Code’s behavior is to drop all ranges due to this inconsistency.Healthy case
I also tried this with the healthy code sample below:
Again, I put the caret at the beginning of the
statusfield (position 4:3) and invoked theExpand Selectioncommand. This is the array of resulting ranges, which satisfies the parent-child criterion:Another healthy case
As I checked, the problem does not raise when the commented line begins with double-slash (//), like this:
This is the resulting ranges:
@andrewbranch If the fix should be done on TS, I’d appreciate any hints to begin with since I’m new to the codebase.
TypeScript is not specific to TS files. We power all of the JavaScript features in VS Code. Smart select should work exactly the same between JS and TS files. However, VS Code has multiple smart selection providers—we are just one of them for JS and TS—and it merges their results, which is why I said it might end up being a VS Code bug. But the fact that it happens in JS doesn’t tell us anything about who the bug belongs to.