Fix duplicate "this" completion (#25900)

This commit is contained in:
Andy 2018-07-25 12:29:28 -07:00 committed by GitHub
parent d60f4988a6
commit bd600cfd50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 23 deletions

View File

@ -4670,7 +4670,7 @@ namespace ts {
}
}
// Use contextual parameter type if one is available
const type = declaration.symbol.escapedName === "this" ? getContextualThisParameterType(func) : getContextuallyTypedParameterType(declaration);
const type = declaration.symbol.escapedName === InternalSymbolName.This ? getContextualThisParameterType(func) : getContextuallyTypedParameterType(declaration);
if (type) {
return addOptionality(type, isOptional);
}
@ -7488,7 +7488,7 @@ namespace ts {
const resolvedSymbol = resolveName(param, paramSymbol.escapedName, SymbolFlags.Value, undefined, undefined, /*isUse*/ false);
paramSymbol = resolvedSymbol!;
}
if (i === 0 && paramSymbol.escapedName === "this") {
if (i === 0 && paramSymbol.escapedName === InternalSymbolName.This) {
hasThisParameter = true;
thisParameter = param.symbol;
}
@ -15373,7 +15373,7 @@ namespace ts {
const jsDocFunctionType = <JSDocFunctionType>jsdocType;
if (jsDocFunctionType.parameters.length > 0 &&
jsDocFunctionType.parameters[0].name &&
(jsDocFunctionType.parameters[0].name as Identifier).escapedText === "this") {
(jsDocFunctionType.parameters[0].name as Identifier).escapedText === InternalSymbolName.This) {
return getTypeFromTypeNode(jsDocFunctionType.parameters[0].type!);
}
}
@ -26797,6 +26797,7 @@ namespace ts {
populateSymbols();
symbols.delete(InternalSymbolName.This); // Not a symbol, a keyword
return symbolsToArray(symbols);
function populateSymbols() {

View File

@ -3559,6 +3559,7 @@ namespace ts {
Resolving = "__resolving__", // Indicator symbol used to mark partially resolved type aliases
ExportEquals = "export=", // Export assignment symbol
Default = "default", // Default export symbol (technically not wholly internal, but included here for usability)
This = "this",
}
/**

View File

@ -2106,7 +2106,8 @@ declare namespace ts {
Computed = "__computed",
Resolving = "__resolving__",
ExportEquals = "export=",
Default = "default"
Default = "default",
This = "this"
}
/**
* This represents a string whose leading underscore have been escaped by adding extra leading underscores.

View File

@ -2106,7 +2106,8 @@ declare namespace ts {
Computed = "__computed",
Resolving = "__resolving__",
ExportEquals = "export=",
Default = "default"
Default = "default",
This = "this"
}
/**
* This represents a string whose leading underscore have been escaped by adding extra leading underscores.

View File

@ -9,21 +9,20 @@
////
////function f(this: { x: number }) { /*f*/ }
goTo.marker("");
verify.completionListContains("xyz", "(method) C.xyz(): any", "", "method", undefined, undefined, {
includeInsertTextCompletions: true,
insertText: "this.xyz",
});
verify.completionListContains("foo bar", '(property) C["foo bar"]: number', "", "property", undefined, undefined, {
includeInsertTextCompletions: true,
insertText: 'this["foo bar"]',
});
goTo.marker("f");
verify.completionListContains("x", "(property) x: number", "", "property", undefined, undefined, {
includeInsertTextCompletions: true,
insertText: "this.x",
});
const preferences: FourSlashInterface.UserPreferences = { includeInsertTextCompletions: true };
verify.completions(
{
marker: "",
includes: [
{ name: "xyz", text: "(method) C.xyz(): any", kind: "method", insertText: "this.xyz" },
{ name: "foo bar", text: '(property) C["foo bar"]: number', kind: "property", insertText: 'this["foo bar"]' },
],
isNewIdentifierLocation: true,
preferences,
},
{
marker: "f",
includes: { name: "x", text: "(property) x: number", kind: "property", insertText: "this.x" },
preferences,
},
);