Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class MyCompletionItem extends vscode.CompletionItem {
private readonly completionContext: CompletionContext,
public readonly metadata: any | undefined,
client: ITypeScriptServiceClient,
defaultCommitCharacters: readonly string[] | undefined,
) {
const label = tsEntry.name || (tsEntry.insertText ?? '');
super(label, MyCompletionItem.convertKind(tsEntry.kind));
Expand Down Expand Up @@ -93,7 +94,7 @@ class MyCompletionItem extends vscode.CompletionItem {
this.useCodeSnippet = completionContext.completeFunctionCalls && (this.kind === vscode.CompletionItemKind.Function || this.kind === vscode.CompletionItemKind.Method);

this.range = this.getRangeFromReplacementSpan(tsEntry, completionContext);
this.commitCharacters = MyCompletionItem.getCommitCharacters(completionContext, tsEntry);
this.commitCharacters = MyCompletionItem.getCommitCharacters(completionContext, tsEntry, defaultCommitCharacters);
this.insertText = isSnippet && tsEntry.insertText ? new vscode.SnippetString(tsEntry.insertText) : tsEntry.insertText;
this.filterText = tsEntry.filterText || this.getFilterText(completionContext.line, tsEntry.insertText);

Expand Down Expand Up @@ -500,7 +501,22 @@ class MyCompletionItem extends vscode.CompletionItem {
}
}

private static getCommitCharacters(context: CompletionContext, entry: Proto.CompletionEntry): string[] | undefined {
private static getCommitCharacters(
context: CompletionContext,
entry: Proto.CompletionEntry,
defaultCommitCharacters: readonly string[] | undefined): string[] | undefined {
// @ts-expect-error until TS 5.6
let commitCharacters = entry.commitCharacters ?? defaultCommitCharacters;
if (commitCharacters) {
if (context.enableCallCompletions
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this logic be moved to the TS side?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future, yes. I didn't include that on TS Server for now because I'm still working out what our approach for commit characters will be exactly. It could be that this setting becomes irrelevant and we start offering ( as a commit character on TSServer by default, or we could want more settings. But one way or the other, we'll eventually get rid of this logic on the vscode side.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok that sounds good. I'll go ahead and merge this initial version then

&& !context.isNewIdentifierLocation
&& entry.kind !== PConst.Kind.warning
&& entry.kind !== PConst.Kind.string) {
commitCharacters.push('(');
}
return commitCharacters;
}

if (entry.kind === PConst.Kind.warning || entry.kind === PConst.Kind.string) { // Ambient JS word based suggestion, strings
return undefined;
}
Expand All @@ -509,7 +525,7 @@ class MyCompletionItem extends vscode.CompletionItem {
return undefined;
}

const commitCharacters: string[] = ['.', ',', ';'];
commitCharacters = ['.', ',', ';'];
if (context.enableCallCompletions) {
commitCharacters.push('(');
}
Expand Down Expand Up @@ -744,6 +760,7 @@ class TypeScriptCompletionItemProvider implements vscode.CompletionItemProvider<
let response: ServerResponse.Response<Proto.CompletionInfoResponse> | undefined;
let duration: number | undefined;
let optionalReplacementRange: vscode.Range | undefined;
let defaultCommitCharacters: string[] | undefined;
if (this.client.apiVersion.gte(API.v300)) {
const startTime = Date.now();
try {
Expand All @@ -769,6 +786,8 @@ class TypeScriptCompletionItemProvider implements vscode.CompletionItemProvider<
isIncomplete = !!response.body.isIncomplete || (response.metadata as any)?.isIncomplete;
entries = response.body.entries;
metadata = response.metadata;
// @ts-expect-error until TS 5.6
defaultCommitCharacters = response.body.defaultCommitCharacters;

if (response.body.optionalReplacementSpan) {
optionalReplacementRange = typeConverters.Range.fromTextSpan(response.body.optionalReplacementSpan);
Expand Down Expand Up @@ -799,7 +818,14 @@ class TypeScriptCompletionItemProvider implements vscode.CompletionItemProvider<
const items: MyCompletionItem[] = [];
for (const entry of entries) {
if (!shouldExcludeCompletionEntry(entry, completionConfiguration)) {
const item = new MyCompletionItem(position, document, entry, completionContext, metadata, this.client);
const item = new MyCompletionItem(
position,
document,
entry,
completionContext,
metadata,
this.client,
defaultCommitCharacters);
item.command = {
command: ApplyCompletionCommand.ID,
title: '',
Expand Down