@@ -168,6 +168,8 @@ import {
168168 isImportKeyword ,
169169 isImportSpecifier ,
170170 isInComment ,
171+ isIndexSignatureDeclaration ,
172+ isInferTypeNode ,
171173 isInitializedProperty ,
172174 isInJSFile ,
173175 isInRightSideOfInternalImportEqualsDeclaration ,
@@ -235,6 +237,7 @@ import {
235237 isTypeOfExpression ,
236238 isTypeOnlyImportDeclaration ,
237239 isTypeOnlyImportOrExportDeclaration ,
240+ isTypeParameterDeclaration ,
238241 isTypeReferenceType ,
239242 isValidTypeOnlyAliasUseSite ,
240243 isVariableDeclaration ,
@@ -292,6 +295,7 @@ import {
292295 ObjectType ,
293296 ObjectTypeDeclaration ,
294297 or ,
298+ ParameterDeclaration ,
295299 ParenthesizedTypeNode ,
296300 positionBelongsToNode ,
297301 positionIsASICandidate ,
@@ -360,6 +364,7 @@ import {
360364 TypeLiteralNode ,
361365 TypeNode ,
362366 TypeOnlyImportDeclaration ,
367+ TypeParameterDeclaration ,
363368 TypeQueryNode ,
364369 TypeReferenceNode ,
365370 unescapeLeadingUnderscores ,
@@ -2389,7 +2394,7 @@ export function getCompletionEntriesFromSymbols(
23892394 includeSymbol = false
23902395) : UniqueNameSet {
23912396 const start = timestamp ( ) ;
2392- const variableDeclaration = getVariableDeclaration ( location ) ;
2397+ const variableOrParameterDeclaration = getVariableOrParameterDeclaration ( contextToken ) ;
23932398 const useSemicolons = probablyUsesSemicolons ( sourceFile ) ;
23942399 const typeChecker = program . getTypeChecker ( ) ;
23952400 // Tracks unique names.
@@ -2463,10 +2468,27 @@ export function getCompletionEntriesFromSymbols(
24632468 }
24642469 // Filter out variables from their own initializers
24652470 // `const a = /* no 'a' here */`
2466- if ( variableDeclaration && symbol . valueDeclaration === variableDeclaration ) {
2471+ if ( tryCast ( variableOrParameterDeclaration , isVariableDeclaration ) && symbol . valueDeclaration === variableOrParameterDeclaration ) {
24672472 return false ;
24682473 }
24692474
2475+ // Filter out parameters from their own initializers
2476+ // `function f(a = /* no 'a' and 'b' here */, b) { }` or
2477+ // `function f<T = /* no 'T' here */>(a: T) { }`
2478+ const symbolDeclaration = symbol . valueDeclaration ?? symbol . declarations ?. [ 0 ] ;
2479+ if ( variableOrParameterDeclaration && symbolDeclaration && (
2480+ ( isTypeParameterDeclaration ( variableOrParameterDeclaration ) && isTypeParameterDeclaration ( symbolDeclaration ) ) ||
2481+ ( isParameter ( variableOrParameterDeclaration ) && isParameter ( symbolDeclaration ) )
2482+ ) ) {
2483+ const symbolDeclarationPos = symbolDeclaration . pos ;
2484+ const parameters = isParameter ( variableOrParameterDeclaration ) ? variableOrParameterDeclaration . parent . parameters :
2485+ isInferTypeNode ( variableOrParameterDeclaration . parent ) ? undefined :
2486+ variableOrParameterDeclaration . parent . typeParameters ;
2487+ if ( symbolDeclarationPos >= variableOrParameterDeclaration . pos && parameters && symbolDeclarationPos < parameters . end ) {
2488+ return false ;
2489+ }
2490+ }
2491+
24702492 // External modules can have global export declarations that will be
24712493 // available as global keywords in all scopes. But if the external module
24722494 // already has an explicit export and user only wants to user explicit
@@ -5442,17 +5464,22 @@ function isModuleSpecifierMissingOrEmpty(specifier: ModuleReference | Expression
54425464 return ! tryCast ( isExternalModuleReference ( specifier ) ? specifier . expression : specifier , isStringLiteralLike ) ?. text ;
54435465}
54445466
5445- function getVariableDeclaration ( property : Node ) : VariableDeclaration | undefined {
5446- const variableDeclaration = findAncestor ( property , node =>
5467+ function getVariableOrParameterDeclaration ( contextToken : Node | undefined ) {
5468+ if ( ! contextToken ) return ;
5469+
5470+ const declaration = findAncestor ( contextToken , node =>
54475471 isFunctionBlock ( node ) || isArrowFunctionBody ( node ) || isBindingPattern ( node )
54485472 ? "quit"
5449- : isVariableDeclaration ( node ) ) ;
5450-
5451- return variableDeclaration as VariableDeclaration | undefined ;
5473+ : isVariableDeclaration ( node ) || ( ( isParameter ( node ) || isTypeParameterDeclaration ( node ) ) && ! isIndexSignatureDeclaration ( node . parent ) ) ) ;
5474+ return declaration as ParameterDeclaration | TypeParameterDeclaration | VariableDeclaration | undefined ;
54525475}
54535476
54545477function isArrowFunctionBody ( node : Node ) {
5455- return node . parent && isArrowFunction ( node . parent ) && node . parent . body === node ;
5478+ return node . parent && isArrowFunction ( node . parent ) &&
5479+ ( node . parent . body === node ||
5480+ // const a = () => /**/;
5481+ node . kind === SyntaxKind . EqualsGreaterThanToken
5482+ ) ;
54565483}
54575484
54585485/** True if symbol is a type or a module containing at least one type. */
0 commit comments