From 582aa072c55b334ea8596a1cb52f18663175a907 Mon Sep 17 00:00:00 2001 From: diartyz Date: Mon, 23 Sep 2019 09:25:14 +0800 Subject: [PATCH] feat(completion): add suggest.invalidInsertCharacters (#1195) --- data/schema.json | 8 ++++++++ src/languages.ts | 8 +++++--- src/util/complete.ts | 3 +-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/data/schema.json b/data/schema.json index ef62a276e54..419e9f800f0 100644 --- a/data/schema.json +++ b/data/schema.json @@ -450,6 +450,14 @@ }, "additionalProperties": false }, + "suggest.invalidInsertCharacters": { + "type": "array", + "items": { + "type": "string" + }, + "description": "Invalid character for strip valid word when inserting text of complete item.", + "default": [" ", "(", "<", "{", "[", "\r", "\n"] + }, "diagnostic.enable": { "type": "boolean", "description": "Set to false to disable diagnostic display", diff --git a/src/languages.ts b/src/languages.ts index 461ae4a1d80..b0015a671f1 100644 --- a/src/languages.ts +++ b/src/languages.ts @@ -46,6 +46,7 @@ interface CompleteConfig { waitTime: number detailMaxLength: number detailField: string + invalidInsertCharacters: string[] } function fixDocumentation(str: string): string { @@ -170,7 +171,8 @@ class Languages { echodocSupport: getConfig('echodocSupport', false), waitTime: getConfig('triggerCompletionWait', 60), detailField: getConfig('detailField', 'abbr'), - detailMaxLength: getConfig('detailMaxLength', 50) + detailMaxLength: getConfig('detailMaxLength', 50), + invalidInsertCharacters: getConfig('invalidInsertCharacters', [' ', '(', '<', '{', '[', '\r', '\n']), } } @@ -716,7 +718,7 @@ class Languages { } private convertVimCompleteItem(item: CompletionItem, shortcut: string, opt: CompleteOption): VimCompleteItem { - let { echodocSupport, detailField, detailMaxLength } = this.completeConfig + let { echodocSupport, detailField, detailMaxLength, invalidInsertCharacters } = this.completeConfig let hasAdditionalEdit = item.additionalTextEdits && item.additionalTextEdits.length > 0 let isSnippet = item.insertTextFormat === InsertTextFormat.Snippet || hasAdditionalEdit let label = item.label.trim() @@ -727,7 +729,7 @@ class Languages { item.insertTextFormat = InsertTextFormat.PlainText } let obj: VimCompleteItem = { - word: complete.getWord(item, opt), + word: complete.getWord(item, opt, invalidInsertCharacters), abbr: label, menu: `[${shortcut}]`, kind: complete.completionKindString(item.kind, this.completionItemKindMap, this.completeConfig.defaultKindText), diff --git a/src/util/complete.ts b/src/util/complete.ts index 8019e83ee85..fe052245cc4 100644 --- a/src/util/complete.ts +++ b/src/util/complete.ts @@ -3,7 +3,6 @@ import { SnippetParser } from '../snippets/parser' import { CompleteOption } from '../types' import { byteSlice, characterIndex } from './string' const logger = require('./logger')('util-complete') -const invalidInsertCharacters = [' ', '(', '<', '{', '[', '\r', '\n'] export function getPosition(opt: CompleteOption): Position { let { line, linenr, colnr } = opt @@ -14,7 +13,7 @@ export function getPosition(opt: CompleteOption): Position { } } -export function getWord(item: CompletionItem, opt: CompleteOption): string { +export function getWord(item: CompletionItem, opt: CompleteOption, invalidInsertCharacters: string[]): string { // tslint:disable-next-line: deprecation let { label, data, insertTextFormat, insertText, textEdit } = item let word: string