From 22e5ff16d457e4c5c9c5704e2469ce4ed3efe502 Mon Sep 17 00:00:00 2001 From: yoyo930021 Date: Thu, 26 Mar 2020 18:58:12 +0800 Subject: [PATCH] Fix object property completion when have hyphen --- server/src/modes/script/javascript.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/server/src/modes/script/javascript.ts b/server/src/modes/script/javascript.ts index 61403ab1b6..3d446d29c6 100644 --- a/server/src/modes/script/javascript.ts +++ b/server/src/modes/script/javascript.ts @@ -25,7 +25,8 @@ import { MarkupContent, CodeAction, CodeActionKind, - WorkspaceEdit + WorkspaceEdit, + InsertTextFormat } from 'vscode-languageserver-types'; import { LanguageMode } from '../../embeddedSupport/languageModes'; import { VueDocumentRegions, LanguageRange } from '../../embeddedSupport/embeddedSupport'; @@ -157,17 +158,29 @@ export async function getJavascriptMode( const entries = completions.entries.filter(entry => entry.name !== '__vueEditorBridge'); return { isIncomplete: false, - items: entries.map((entry, index) => { + items: entries.map(entry => { const range = entry.replacementSpan && convertRange(scriptDoc, entry.replacementSpan); + const filterText = entry.insertText && range && entry.insertText[0] === '[' ? '.' + entry.name : undefined; const { label, detail } = calculateLabelAndDetailTextForPathImport(entry); + const kind = toCompletionItemKind(entry.kind); + const insertTextFormat = + kind === CompletionItemKind.Function || kind === CompletionItemKind.Method + ? InsertTextFormat.Snippet + : undefined; + const insertText = entry.insertText || entry.name; + return { uri: doc.uri, position, + preselect: entry.isRecommended ? true : undefined, label, detail, - sortText: entry.sortText + index, + filterText, + insertTextFormat, + sortText: entry.sortText, kind: toCompletionItemKind(entry.kind), - textEdit: range && TextEdit.replace(range, entry.name), + textEdit: range && TextEdit.replace(range, insertText), + insertText: range ? undefined : insertText, data: { // data used for resolving item details (see 'doResolve') languageId: scriptDoc.languageId,