Skip to content

Commit

Permalink
feat(completion): add suggest.invalidInsertCharacters (#1195)
Browse files Browse the repository at this point in the history
  • Loading branch information
diartyz authored and chemzqm committed Sep 23, 2019
1 parent d6346fb commit 582aa07
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
8 changes: 8 additions & 0 deletions data/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 5 additions & 3 deletions src/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ interface CompleteConfig {
waitTime: number
detailMaxLength: number
detailField: string
invalidInsertCharacters: string[]
}

function fixDocumentation(str: string): string {
Expand Down Expand Up @@ -170,7 +171,8 @@ class Languages {
echodocSupport: getConfig<boolean>('echodocSupport', false),
waitTime: getConfig<number>('triggerCompletionWait', 60),
detailField: getConfig<string>('detailField', 'abbr'),
detailMaxLength: getConfig<number>('detailMaxLength', 50)
detailMaxLength: getConfig<number>('detailMaxLength', 50),
invalidInsertCharacters: getConfig<string[]>('invalidInsertCharacters', [' ', '(', '<', '{', '[', '\r', '\n']),
}
}

Expand Down Expand Up @@ -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()
Expand All @@ -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),
Expand Down
3 changes: 1 addition & 2 deletions src/util/complete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 582aa07

Please sign in to comment.