-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Conversation
@@ -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) { |
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.
It probably wouldn't hurt to test this method.
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.
src/services/organizeImports.ts
Outdated
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); |
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.
Personally, I find it helpful to use parentheses when combining binary operators with different precedence.
FYI @mhegazy |
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.