mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
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:
@@ -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);
|
||||
|
||||
@@ -1972,7 +1972,7 @@ namespace ts.server.protocol {
|
||||
arguments: FormatOnKeyRequestArgs;
|
||||
}
|
||||
|
||||
export type CompletionsTriggerCharacter = "." | '"' | "'" | "`" | "/" | "@" | "<";
|
||||
export type CompletionsTriggerCharacter = "." | '"' | "'" | "`" | "/" | "@" | "<" | "#";
|
||||
|
||||
/**
|
||||
* Arguments for completions messages.
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -418,7 +418,7 @@ namespace ts {
|
||||
|
||||
export type OrganizeImportsScope = CombinedCodeFixScope;
|
||||
|
||||
export type CompletionsTriggerCharacter = "." | '"' | "'" | "`" | "/" | "@" | "<";
|
||||
export type CompletionsTriggerCharacter = "." | '"' | "'" | "`" | "/" | "@" | "<" | "#";
|
||||
|
||||
export interface GetCompletionsAtPositionOptions extends UserPreferences {
|
||||
/**
|
||||
|
||||
+2
-2
@@ -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
@@ -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: "#" },
|
||||
);
|
||||
Reference in New Issue
Block a user