-
Notifications
You must be signed in to change notification settings - Fork 12.8k
fix(51225): Go-to-definition on case or default should jump to the containing switch statement if available. #51236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@microsoft-github-policy-service agree |
1613057
to
7b3a71a
Compare
Can you add one more test? switch (null) {
case null:
export /*start*/default 123;
} Validate that it doesn't jump to the |
Is it normal that b and goes to c? This is how it works now and looks like a bug. It is expected that there will be no go to anywhere. |
It's questionable, but I wouldn't get hung up on fixing that specific case. |
256cc27
to
26decab
Compare
…ntaining switch statement if available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good but the tests dont verify contextSpan is coming out correct.
Also should context be switch keyword plus expression or just expression.. Probably expression is fine but i am not sure if editor works out ok if context span is mutually exclusive with definition span.. (dont think we have had that)
# Conflicts: # src/services/goToDefinition.ts
@sheetalkamat I changed contextSpan to keyword + expression, but i can't find any examples for testing contextSpan with fourslash |
Good to go @sheetalkamat? |
Any progress? @sheetalkamat |
@typescript-bot pack this |
I am working on framework to test contextSpan with goto def which we should merge and then rebase this PR so its clearer on what is the context that is being set for contextSpan. Will link PR here once i have it ready |
@sviat9440 #52576 is up and once that is merged you should be able to update your PR with the baselines that verify context, |
#52576 is merged. Feel free to merge changes from main and baseline |
@@ -0,0 +1,17 @@ | |||
// === goToDefinition === | |||
// === /tests/cases/fourslash/goToDefinitionSwitchCase1.ts === | |||
// [|{| contextId: 0 |}switch|] (<|null|>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think contextSpan should be switch (null)
instead of just null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was the previous commit correct then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kind of.. probably needs closing paren as well part of context ?
src/services/goToDefinition.ts
Outdated
name, | ||
containerKind: undefined!, | ||
containerName: "", | ||
contextSpan: createTextSpanFromBounds(keyword.getStart(sourceFile), statement.caseBlock.getFullStart()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be moved to getContextNode
which handled SwitchStatement
then ...FindAllReferences.getContextSpan()
so that all places where we will use context span are in single place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at createDefinitionInfoFromName above, it looks like the right way to use this is first to call getContextNode to get the start/end tokens, then to use toContextSpan to turn it into a context span (see code below). Unfortunately, my getFullStart
hack (which grabs the closing paren) gets lost since getContextNode returns a node pair, not a location pair. And toContextSpan currently always calls getEnd, but my hack uses getFullStart.
const keyword = FindAllReferences.getContextNode(statement)!;
const textSpan = createTextSpanFromNode(isContextWithStartAndEndNode(keyword) ? keyword.start : keyword, sourceFile)
return {
fileName: sourceFile.fileName,
textSpan,
kind: ScriptElementKind.keyword,
name: "switch",
containerKind: undefined!,
containerName: "",
...FindAllReferences.toContextSpan(textSpan, sourceFile, keyword),
isLocal: true,
isAmbient: false,
unverified: false,
failedAliasResolution: undefined,
};
Any ideas? I'm going to try hacking toContextSpan to special case switches to see how bad that is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, the hack isn't too bad; there's a special case for strin gliterals there already, so I added it after that.
rename back to switch -- there's no point in unused abstraction.
Fixes #51225