Skip to content

organizeImports: Avoid using full FindAllReferences #22102

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

Merged
2 commits merged into from
Feb 23, 2018
Merged

Conversation

ghost
Copy link

@ghost ghost commented Feb 21, 2018

For imports, all we really need is getPossibleSymbolReferencePositions followed by checking for exact symbol match. FindAllReferences would look for related symbols, but we don't actually want those in this case.

@ghost ghost requested a review from amcasey February 21, 2018 22:51
@@ -709,6 +709,16 @@ namespace ts.FindAllReferences.Core {
return exposedByParent ? scope.getSourceFile() : scope;
}

/** Used as a quick check for whether a symbol is used at all in a file (besides its definition). */
export function isSymbolReferencedInFile(definition: Identifier, checker: TypeChecker, sourceFile: SourceFile) {
Copy link
Member

Choose a reason for hiding this comment

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

It probably wouldn't hurt to test this method.

Copy link
Author

Choose a reason for hiding this comment

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

throwIfCancellationRequested: () => { /*noop*/ },
}).filter(e => e.type === "node" && e.node.getSourceFile() === sourceFile);
return entries.length > 1;
return jsxContext && identifier.text === jsxNamespace || FindAllReferences.Core.isSymbolReferencedInFile(identifier, typeChecker, sourceFile);
Copy link
Member

Choose a reason for hiding this comment

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

Personally, I find it helpful to use parentheses when combining binary operators with different precedence.

@amcasey
Copy link
Member

amcasey commented Feb 22, 2018

FYI @mhegazy

@ghost ghost merged commit e8fb587 into master Feb 23, 2018
@ghost ghost deleted the isSymbolReferencedInFile branch February 23, 2018 00:26
@ghost ghost mentioned this pull request Feb 23, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants