diff --git a/src/services/completions.ts b/src/services/completions.ts index 30e9ad40bf3f1..dd623aadeb156 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -2745,8 +2745,14 @@ export function getCompletionEntriesFromSymbols( } // Filter out variables from their own initializers // `const a = /* no 'a' here */` - if (tryCast(closestSymbolDeclaration, isVariableDeclaration) && symbol.valueDeclaration === closestSymbolDeclaration) { - return false; + if (closestSymbolDeclaration && tryCast(closestSymbolDeclaration, isVariableDeclaration)) { + if (symbol.valueDeclaration === closestSymbolDeclaration) { + return false; + } + // const { a } = /* no 'a' here */; + if (isBindingPattern(closestSymbolDeclaration.name) && closestSymbolDeclaration.name.elements.some(e => e === symbol.valueDeclaration)) { + return false; + } } // Filter out current and latter parameters from defaults diff --git a/tests/cases/fourslash/completionListWithoutVariableinitializer.ts b/tests/cases/fourslash/completionListWithoutVariableinitializer.ts index 5d2a95b743cca..cba6743f3f6c0 100644 --- a/tests/cases/fourslash/completionListWithoutVariableinitializer.ts +++ b/tests/cases/fourslash/completionListWithoutVariableinitializer.ts @@ -9,6 +9,10 @@ //// const fn = (p = /*7*/) => {} //// const { g, h = /*8*/ } = { ... } //// const [ g1, h1 = /*9*/ ] = [ ... ] +//// const { a1 } = a/*10*/; +//// const { a2 } = fn({a: a/*11*/}); +//// const [ a3 ] = a/*12*/; +//// const [ a4 ] = fn([a/*13*/]); verify.completions({ marker: ["1"], @@ -58,3 +62,26 @@ verify.completions({ marker: ["9"], includes: ["a", "b", "c", "d", "e", "fn"], }); + +verify.completions({ + marker: ["10"], + excludes: ["a1"], + isNewIdentifierLocation: true, +}); + +verify.completions({ + marker: ["11"], + excludes: ["a2"], +}); + +verify.completions({ + marker: ["12"], + excludes: ["a3"], + isNewIdentifierLocation: true, +}); + +verify.completions({ + marker: ["13"], + excludes: ["a4"], + isNewIdentifierLocation: true, +});