@@ -2738,78 +2738,76 @@ export function getCompletionEntriesFromSymbols(
2738
2738
2739
2739
function shouldIncludeSymbol ( symbol : Symbol , symbolToSortTextMap : SymbolSortTextMap ) : boolean {
2740
2740
let allFlags = symbol . flags ;
2741
- if ( ! isSourceFile ( location ) ) {
2742
- // export = /**/ here we want to get all meanings, so any symbol is ok
2743
- if ( isExportAssignment ( location . parent ) ) {
2744
- return true ;
2741
+ // export = /**/ here we want to get all meanings, so any symbol is ok
2742
+ if ( location . parent && isExportAssignment ( location . parent ) ) {
2743
+ return true ;
2744
+ }
2745
+ // Filter out variables from their own initializers
2746
+ // `const a = /* no 'a' here */`
2747
+ if ( closestSymbolDeclaration && tryCast ( closestSymbolDeclaration , isVariableDeclaration ) ) {
2748
+ if ( symbol . valueDeclaration === closestSymbolDeclaration ) {
2749
+ return false ;
2745
2750
}
2746
- // Filter out variables from their own initializers
2747
- // `const a = /* no 'a' here */`
2748
- if ( closestSymbolDeclaration && tryCast ( closestSymbolDeclaration , isVariableDeclaration ) ) {
2749
- if ( symbol . valueDeclaration === closestSymbolDeclaration ) {
2751
+ // const { a } = /* no 'a' here */;
2752
+ if ( isBindingPattern ( closestSymbolDeclaration . name ) && closestSymbolDeclaration . name . elements . some ( e => e === symbol . valueDeclaration ) ) {
2753
+ return false ;
2754
+ }
2755
+ }
2756
+
2757
+ // Filter out current and latter parameters from defaults
2758
+ // `function f(a = /* no 'a' and 'b' here */, b) { }` or
2759
+ // `function f<T = /* no 'T' and 'T2' here */>(a: T, b: T2) { }`
2760
+ const symbolDeclaration = symbol . valueDeclaration ?? symbol . declarations ?. [ 0 ] ;
2761
+ if ( closestSymbolDeclaration && symbolDeclaration ) {
2762
+ if ( isParameter ( closestSymbolDeclaration ) && isParameter ( symbolDeclaration ) ) {
2763
+ const parameters = closestSymbolDeclaration . parent . parameters ;
2764
+ if ( symbolDeclaration . pos >= closestSymbolDeclaration . pos && symbolDeclaration . pos < parameters . end ) {
2750
2765
return false ;
2751
2766
}
2752
- // const { a } = /* no 'a' here */;
2753
- if ( isBindingPattern ( closestSymbolDeclaration . name ) && closestSymbolDeclaration . name . elements . some ( e => e === symbol . valueDeclaration ) ) {
2767
+ }
2768
+ else if ( isTypeParameterDeclaration ( closestSymbolDeclaration ) && isTypeParameterDeclaration ( symbolDeclaration ) ) {
2769
+ if ( closestSymbolDeclaration === symbolDeclaration && contextToken ?. kind === SyntaxKind . ExtendsKeyword ) {
2770
+ // filter out the directly self-recursive type parameters
2771
+ // `type A<K extends /* no 'K' here*/> = K`
2754
2772
return false ;
2755
2773
}
2756
- }
2757
-
2758
- // Filter out current and latter parameters from defaults
2759
- // `function f(a = /* no 'a' and 'b' here */, b) { }` or
2760
- // `function f<T = /* no 'T' and 'T2' here */>(a: T, b: T2) { }`
2761
- const symbolDeclaration = symbol . valueDeclaration ?? symbol . declarations ?. [ 0 ] ;
2762
- if ( closestSymbolDeclaration && symbolDeclaration ) {
2763
- if ( isParameter ( closestSymbolDeclaration ) && isParameter ( symbolDeclaration ) ) {
2764
- const parameters = closestSymbolDeclaration . parent . parameters ;
2765
- if ( symbolDeclaration . pos >= closestSymbolDeclaration . pos && symbolDeclaration . pos < parameters . end ) {
2774
+ if ( isInTypeParameterDefault ( contextToken ) && ! isInferTypeNode ( closestSymbolDeclaration . parent ) ) {
2775
+ const typeParameters = closestSymbolDeclaration . parent . typeParameters ;
2776
+ if ( typeParameters && symbolDeclaration . pos >= closestSymbolDeclaration . pos && symbolDeclaration . pos < typeParameters . end ) {
2766
2777
return false ;
2767
2778
}
2768
2779
}
2769
- else if ( isTypeParameterDeclaration ( closestSymbolDeclaration ) && isTypeParameterDeclaration ( symbolDeclaration ) ) {
2770
- if ( closestSymbolDeclaration === symbolDeclaration && contextToken ?. kind === SyntaxKind . ExtendsKeyword ) {
2771
- // filter out the directly self-recursive type parameters
2772
- // `type A<K extends /* no 'K' here*/> = K`
2773
- return false ;
2774
- }
2775
- if ( isInTypeParameterDefault ( contextToken ) && ! isInferTypeNode ( closestSymbolDeclaration . parent ) ) {
2776
- const typeParameters = closestSymbolDeclaration . parent . typeParameters ;
2777
- if ( typeParameters && symbolDeclaration . pos >= closestSymbolDeclaration . pos && symbolDeclaration . pos < typeParameters . end ) {
2778
- return false ;
2779
- }
2780
- }
2781
- }
2782
2780
}
2781
+ }
2783
2782
2784
- // External modules can have global export declarations that will be
2785
- // available as global keywords in all scopes. But if the external module
2786
- // already has an explicit export and user only wants to user explicit
2787
- // module imports then the global keywords will be filtered out so auto
2788
- // import suggestions will win in the completion
2789
- const symbolOrigin = skipAlias ( symbol , typeChecker ) ;
2790
- // We only want to filter out the global keywords
2791
- // Auto Imports are not available for scripts so this conditional is always false
2792
- if (
2793
- ! ! sourceFile . externalModuleIndicator
2794
- && ! compilerOptions . allowUmdGlobalAccess
2795
- && symbolToSortTextMap [ getSymbolId ( symbol ) ] === SortText . GlobalsOrKeywords
2796
- && ( symbolToSortTextMap [ getSymbolId ( symbolOrigin ) ] === SortText . AutoImportSuggestions
2797
- || symbolToSortTextMap [ getSymbolId ( symbolOrigin ) ] === SortText . LocationPriority )
2798
- ) {
2799
- return false ;
2800
- }
2783
+ // External modules can have global export declarations that will be
2784
+ // available as global keywords in all scopes. But if the external module
2785
+ // already has an explicit export and user only wants to user explicit
2786
+ // module imports then the global keywords will be filtered out so auto
2787
+ // import suggestions will win in the completion
2788
+ const symbolOrigin = skipAlias ( symbol , typeChecker ) ;
2789
+ // We only want to filter out the global keywords
2790
+ // Auto Imports are not available for scripts so this conditional is always false
2791
+ if (
2792
+ ! ! sourceFile . externalModuleIndicator
2793
+ && ! compilerOptions . allowUmdGlobalAccess
2794
+ && symbolToSortTextMap [ getSymbolId ( symbol ) ] === SortText . GlobalsOrKeywords
2795
+ && ( symbolToSortTextMap [ getSymbolId ( symbolOrigin ) ] === SortText . AutoImportSuggestions
2796
+ || symbolToSortTextMap [ getSymbolId ( symbolOrigin ) ] === SortText . LocationPriority )
2797
+ ) {
2798
+ return false ;
2799
+ }
2801
2800
2802
- allFlags |= getCombinedLocalAndExportSymbolFlags ( symbolOrigin ) ;
2801
+ allFlags |= getCombinedLocalAndExportSymbolFlags ( symbolOrigin ) ;
2803
2802
2804
- // import m = /**/ <-- It can only access namespace (if typing import = x. this would get member symbols and not namespace)
2805
- if ( isInRightSideOfInternalImportEqualsDeclaration ( location ) ) {
2806
- return ! ! ( allFlags & SymbolFlags . Namespace ) ;
2807
- }
2803
+ // import m = /**/ <-- It can only access namespace (if typing import = x. this would get member symbols and not namespace)
2804
+ if ( isInRightSideOfInternalImportEqualsDeclaration ( location ) ) {
2805
+ return ! ! ( allFlags & SymbolFlags . Namespace ) ;
2806
+ }
2808
2807
2809
- if ( isTypeOnlyLocation ) {
2810
- // It's a type, but you can reach it by namespace.type as well
2811
- return symbolCanBeReferencedAtTypeLocation ( symbol , typeChecker ) ;
2812
- }
2808
+ if ( isTypeOnlyLocation ) {
2809
+ // It's a type, but you can reach it by namespace.type as well
2810
+ return symbolCanBeReferencedAtTypeLocation ( symbol , typeChecker ) ;
2813
2811
}
2814
2812
2815
2813
// expressions are value space (which includes the value namespaces)
0 commit comments