@@ -168,6 +168,8 @@ import {
168
168
isImportKeyword ,
169
169
isImportSpecifier ,
170
170
isInComment ,
171
+ isIndexSignatureDeclaration ,
172
+ isInferTypeNode ,
171
173
isInitializedProperty ,
172
174
isInJSFile ,
173
175
isInRightSideOfInternalImportEqualsDeclaration ,
@@ -235,6 +237,7 @@ import {
235
237
isTypeOfExpression ,
236
238
isTypeOnlyImportDeclaration ,
237
239
isTypeOnlyImportOrExportDeclaration ,
240
+ isTypeParameterDeclaration ,
238
241
isTypeReferenceType ,
239
242
isValidTypeOnlyAliasUseSite ,
240
243
isVariableDeclaration ,
@@ -292,6 +295,7 @@ import {
292
295
ObjectType ,
293
296
ObjectTypeDeclaration ,
294
297
or ,
298
+ ParameterDeclaration ,
295
299
ParenthesizedTypeNode ,
296
300
positionBelongsToNode ,
297
301
positionIsASICandidate ,
@@ -360,6 +364,7 @@ import {
360
364
TypeLiteralNode ,
361
365
TypeNode ,
362
366
TypeOnlyImportDeclaration ,
367
+ TypeParameterDeclaration ,
363
368
TypeQueryNode ,
364
369
TypeReferenceNode ,
365
370
unescapeLeadingUnderscores ,
@@ -2389,7 +2394,7 @@ export function getCompletionEntriesFromSymbols(
2389
2394
includeSymbol = false
2390
2395
) : UniqueNameSet {
2391
2396
const start = timestamp ( ) ;
2392
- const variableDeclaration = getVariableDeclaration ( location ) ;
2397
+ const variableOrParameterDeclaration = getVariableOrParameterDeclaration ( contextToken ) ;
2393
2398
const useSemicolons = probablyUsesSemicolons ( sourceFile ) ;
2394
2399
const typeChecker = program . getTypeChecker ( ) ;
2395
2400
// Tracks unique names.
@@ -2463,10 +2468,27 @@ export function getCompletionEntriesFromSymbols(
2463
2468
}
2464
2469
// Filter out variables from their own initializers
2465
2470
// `const a = /* no 'a' here */`
2466
- if ( variableDeclaration && symbol . valueDeclaration === variableDeclaration ) {
2471
+ if ( tryCast ( variableOrParameterDeclaration , isVariableDeclaration ) && symbol . valueDeclaration === variableOrParameterDeclaration ) {
2467
2472
return false ;
2468
2473
}
2469
2474
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
+
2470
2492
// External modules can have global export declarations that will be
2471
2493
// available as global keywords in all scopes. But if the external module
2472
2494
// already has an explicit export and user only wants to user explicit
@@ -5442,17 +5464,22 @@ function isModuleSpecifierMissingOrEmpty(specifier: ModuleReference | Expression
5442
5464
return ! tryCast ( isExternalModuleReference ( specifier ) ? specifier . expression : specifier , isStringLiteralLike ) ?. text ;
5443
5465
}
5444
5466
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 =>
5447
5471
isFunctionBlock ( node ) || isArrowFunctionBody ( node ) || isBindingPattern ( node )
5448
5472
? "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 ;
5452
5475
}
5453
5476
5454
5477
function 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
+ ) ;
5456
5483
}
5457
5484
5458
5485
/** True if symbol is a type or a module containing at least one type. */
0 commit comments