Skip to content
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

allow calling goToDef on modifiers of named declarations #60384

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

iisaduan
Copy link
Member

@iisaduan iisaduan commented Oct 31, 2024

Fixes #60308.

There are some symbols where goToDef/goToType previously did not return a definition. For those cases, I have not changed the behavior, this PR just makes it so that calling goTo(Type)Definition on a modifier will do the same behavior as if the call was triggered on the name.

The first commit refactors some existing goToDefinition keyword cases. It may be easier to review by looking at the first commit, and then the rest of the commits without the first one.

@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Oct 31, 2024
Copy link
Contributor

@mjbvz mjbvz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into this!

switch (node.kind) {
case SyntaxKind.ReturnKeyword:
findFunctionDecl = n => {
return isClassStaticBlockDeclaration(n)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like it's very much a special-case. Are you trying to just not break some sort of test case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was existing code, so I'm not sure if there are more cases that would be an issue, but it breaks https://github.com/microsoft/TypeScript/blob/main/tests/cases/fourslash/goToDefinitionReturn5.ts

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably just fine to update the baseline there.

Comment on lines +180 to +183
if (findFunctionDecl) {
const functionDeclaration = findAncestor(node, findFunctionDecl) as FunctionLikeDeclaration | undefined;
const isCorrectDeclaration = functionDeclaration && (!checkFunctionDeclaration || checkFunctionDeclaration(functionDeclaration));
return isCorrectDeclaration ? [createDefinitionFromSignatureDeclaration(typeChecker, functionDeclaration)] : undefined;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kind of find the indirection here hard to follow. I can see wanting to find some common logic, but I'd suggest just writing it out explicitly in each branch for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, the idea that you wouldn't want to still jump to the nearest function even if it's not async or a generator is something I'm not so sure of. So the idea that you need a checkFunctionDeclaration to validate that you got a function of the right kind feels like it would break down unnecessarily during refactoring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
Status: Waiting on author
Development

Successfully merging this pull request may close these issues.

Allow running go to definition on export and other keywords
5 participants