From 528209b91c32e016af013a2af47f1c0d26668b77 Mon Sep 17 00:00:00 2001 From: Qiming Zhao Date: Mon, 12 Sep 2022 12:09:05 +0800 Subject: [PATCH] fix snippet not work with optional property --- src/server/features/completionItemProvider.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/server/features/completionItemProvider.ts b/src/server/features/completionItemProvider.ts index 8280ee2..7d81387 100644 --- a/src/server/features/completionItemProvider.ts +++ b/src/server/features/completionItemProvider.ts @@ -225,8 +225,6 @@ export default class TypeScriptCompletionItemProvider implements CompletionItemP let { uri, position, source, name, data } = item.data const filepath = this.client.toPath(uri) if (!filepath) return undefined - let document = workspace.getDocument(uri) - if (!document) return undefined const args: Proto.CompletionDetailsRequestArgs = { ...typeConverters.Position.toFileLocationRequestArgs( filepath, @@ -259,11 +257,10 @@ export default class TypeScriptCompletionItemProvider implements CompletionItemP item.additionalTextEdits = additionalTextEdits if (detail && item.insertTextFormat == InsertTextFormat.Snippet) { const shouldCompleteFunction = await this.isValidFunctionCompletionContext(filepath, position, token) - if (shouldCompleteFunction && !item.insertText) { + if (shouldCompleteFunction) { this.createSnippetOfFunctionCall(item, detail) } } - return item } @@ -380,7 +377,7 @@ export default class TypeScriptCompletionItemProvider implements CompletionItemP let { displayParts } = detail const parameterListParts = getParameterListParts(displayParts) const snippet = new SnippetString() - snippet.appendText(`${item.insertText || item.label}(`) + snippet.appendText(`${item.insertText ?? item.label}(`) appendJoinedPlaceholders(snippet, parameterListParts.parts, ', ') if (parameterListParts.hasOptionalParameters) { snippet.appendTabstop()