Add # to completion trigger character, (#36462)

Handle private identifiers little better by creating token for private identifier when its just #
Report same error as invalid character but from language service we can now provide completions for this.#

Fixes #36367, #36250
This commit is contained in:
Sheetal Nandi
2020-01-27 14:25:20 -08:00
committed by GitHub
parent 3ece65a94c
commit a87512d21b
7 changed files with 28 additions and 9 deletions
+5 -4
View File
@@ -1907,11 +1907,12 @@ namespace ts {
if (ch === CharacterCodes.backslash) {
tokenValue += scanIdentifierParts();
}
return token = SyntaxKind.PrivateIdentifier;
}
error(Diagnostics.Invalid_character);
// no `pos++` because already advanced past the '#'
return token = SyntaxKind.Unknown;
else {
tokenValue = "#";
error(Diagnostics.Invalid_character);
}
return token = SyntaxKind.PrivateIdentifier;
default:
if (isIdentifierStart(ch, languageVersion)) {
pos += charSize(ch);
+1 -1
View File
@@ -1972,7 +1972,7 @@ namespace ts.server.protocol {
arguments: FormatOnKeyRequestArgs;
}
export type CompletionsTriggerCharacter = "." | '"' | "'" | "`" | "/" | "@" | "<";
export type CompletionsTriggerCharacter = "." | '"' | "'" | "`" | "/" | "@" | "<" | "#";
/**
* Arguments for completions messages.
+2
View File
@@ -2654,6 +2654,8 @@ namespace ts.Completions {
case "`":
// Only automatically bring up completions if this is an opening quote.
return !!contextToken && isStringLiteralOrTemplate(contextToken) && position === contextToken.getStart(sourceFile) + 1;
case "#":
return !!contextToken && isPrivateIdentifier(contextToken) && !!getContainingClass(contextToken);
case "<":
// Opening JSX tag
return !!contextToken && contextToken.kind === SyntaxKind.LessThanToken && (!isBinaryExpression(contextToken.parent) || binaryExpressionMayBeOpenTag(contextToken.parent));
+1 -1
View File
@@ -418,7 +418,7 @@ namespace ts {
export type OrganizeImportsScope = CombinedCodeFixScope;
export type CompletionsTriggerCharacter = "." | '"' | "'" | "`" | "/" | "@" | "<";
export type CompletionsTriggerCharacter = "." | '"' | "'" | "`" | "/" | "@" | "<" | "#";
export interface GetCompletionsAtPositionOptions extends UserPreferences {
/**
+2 -2
View File
@@ -5198,7 +5198,7 @@ declare namespace ts {
fileName: string;
}
type OrganizeImportsScope = CombinedCodeFixScope;
type CompletionsTriggerCharacter = "." | '"' | "'" | "`" | "/" | "@" | "<";
type CompletionsTriggerCharacter = "." | '"' | "'" | "`" | "/" | "@" | "<" | "#";
interface GetCompletionsAtPositionOptions extends UserPreferences {
/**
* If the editor is asking for completions because a certain character was typed
@@ -7541,7 +7541,7 @@ declare namespace ts.server.protocol {
command: CommandTypes.Formatonkey;
arguments: FormatOnKeyRequestArgs;
}
type CompletionsTriggerCharacter = "." | '"' | "'" | "`" | "/" | "@" | "<";
type CompletionsTriggerCharacter = "." | '"' | "'" | "`" | "/" | "@" | "<" | "#";
/**
* Arguments for completions messages.
*/
+1 -1
View File
@@ -5198,7 +5198,7 @@ declare namespace ts {
fileName: string;
}
type OrganizeImportsScope = CombinedCodeFixScope;
type CompletionsTriggerCharacter = "." | '"' | "'" | "`" | "/" | "@" | "<";
type CompletionsTriggerCharacter = "." | '"' | "'" | "`" | "/" | "@" | "<" | "#";
interface GetCompletionsAtPositionOptions extends UserPreferences {
/**
* If the editor is asking for completions because a certain character was typed
@@ -0,0 +1,16 @@
/// <reference path="fourslash.ts" />
// @target: esnext
////class K {
//// #value: number;
////
//// foo() {
//// this.#/**/
//// }
////}
verify.completions(
{ marker: "", exact: ["#value", "foo"] },
{ marker: "", exact: ["#value", "foo"], triggerCharacter: "#" },
);