Skip to content

Handle this.# completions and add # to completion trigger character, #36462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/compiler/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/server/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1972,7 +1972,7 @@ namespace ts.server.protocol {
arguments: FormatOnKeyRequestArgs;
}

export type CompletionsTriggerCharacter = "." | '"' | "'" | "`" | "/" | "@" | "<";
export type CompletionsTriggerCharacter = "." | '"' | "'" | "`" | "/" | "@" | "<" | "#";

/**
* Arguments for completions messages.
Expand Down
2 changes: 2 additions & 0 deletions src/services/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2651,6 +2651,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));
Expand Down
2 changes: 1 addition & 1 deletion src/services/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ namespace ts {

export type OrganizeImportsScope = CombinedCodeFixScope;

export type CompletionsTriggerCharacter = "." | '"' | "'" | "`" | "/" | "@" | "<";
export type CompletionsTriggerCharacter = "." | '"' | "'" | "`" | "/" | "@" | "<" | "#";

export interface GetCompletionsAtPositionOptions extends UserPreferences {
/**
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -7541,7 +7541,7 @@ declare namespace ts.server.protocol {
command: CommandTypes.Formatonkey;
arguments: FormatOnKeyRequestArgs;
}
type CompletionsTriggerCharacter = "." | '"' | "'" | "`" | "/" | "@" | "<";
type CompletionsTriggerCharacter = "." | '"' | "'" | "`" | "/" | "@" | "<" | "#";
/**
* Arguments for completions messages.
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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: "#" },
);