remove textEdit of completionItem

This commit is contained in:
chemzqm 2018-12-04 11:51:49 +08:00
parent 5d0c6830fc
commit ec6e406594
2 changed files with 5 additions and 71 deletions

View file

@ -10,7 +10,7 @@ import * as PConst from '../protocol.const'
import { ITypeScriptServiceClient } from '../typescriptService'
import API from '../utils/api'
import { applyCodeAction } from '../utils/codeAction'
import { convertCompletionEntry, resolveItem } from '../utils/completionItem'
import { convertCompletionEntry } from '../utils/completionItem'
import * as Previewer from '../utils/previewer'
import * as typeConverters from '../utils/typeConverters'
import TypingsStatus from '../utils/typingsStatus'
@ -185,7 +185,6 @@ export default class TypeScriptCompletionItemProvider implements CompletionItemP
if (!filepath) return undefined
let document = workspace.getDocument(uri)
if (!document) return undefined
resolveItem(item, document)
const args: Proto.CompletionDetailsRequestArgs = {
...typeConverters.Position.toFileLocationRequestArgs(
filepath,
@ -345,18 +344,7 @@ export default class TypeScriptCompletionItemProvider implements CompletionItemP
const methodName = detail.displayParts.find(
part => part.kind === 'methodName'
)
let { textEdit, data } = item
let { position, uri } = data
if (textEdit) {
snippet += item.insertText || textEdit.newText // tslint:disable-line
} else {
let document = workspace.getDocument(uri)
if (!document) return
let range = document.getWordRangeAtPosition(position)
textEdit = { range, newText: '' }
snippet += item.insertText || (methodName && methodName.text) || item.label // tslint:disable-line
}
snippet += item.insertText || (methodName && methodName.text) || item.label // tslint:disable-line
snippet += '('
let holderIndex = 1
let parenCount = 0
@ -395,8 +383,8 @@ export default class TypeScriptCompletionItemProvider implements CompletionItemP
}
snippet += ')'
snippet += '$0'
textEdit.newText = snippet
item.textEdit = textEdit
// tslint:disable-next-line:deprecation
item.insertText = snippet
}
private async isValidFunctionCompletionContext(

View file

@ -2,8 +2,8 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { workspace } from 'coc.nvim'
import { CompletionItem, CompletionItemKind, InsertTextFormat, Position, TextEdit } from 'vscode-languageserver-protocol'
import { Document, workspace } from 'coc.nvim'
import * as Proto from '../protocol'
import * as PConst from '../protocol.const'
@ -13,51 +13,6 @@ interface CommitCharactersSettings {
readonly useCodeSnippetsOnMethodSuggest: boolean
}
export function resolveItem(
item: CompletionItem,
document: Document,
): void {
let { textEdit, label } = item // tslint:disable-line
let { position } = item.data
if (textEdit) return
// try replace more characters after cursor
const wordRange = document.getWordRangeAtPosition(position)
let text = document.textDocument.getText({
start: {
line: position.line,
character: Math.max(0, position.character - label.length),
},
end: {
line: position.line,
character: position.character
}
})
text = text.toLowerCase()
const entryName = label.toLowerCase()
for (let i = entryName.length; i >= 0; --i) {
if (text.endsWith(entryName.substr(0, i)) &&
(!wordRange ||
wordRange.start.character > position.character - i)) {
item.textEdit = {
newText: label,
range: {
start: {
line: position.line,
character: Math.max(0, position.character - i)
},
end: {
line: position.line,
character: position.character
}
}
}
break
}
}
}
export function convertCompletionEntry(
tsEntry: Proto.CompletionEntry,
uri: string,
@ -85,16 +40,8 @@ export function convertCompletionEntry(
kind === CompletionItemKind.Method)
) ? InsertTextFormat.Snippet : InsertTextFormat.PlainText
let textEdit: TextEdit = null
let insertText = tsEntry.insertText
let document = workspace.getDocument(uri)
if (insertText) {
textEdit = {
range: document.getWordRangeAtPosition(position),
newText: insertText
}
insertText = null
}
let preText = document.getline(position.line).slice(0, position.character)
const isInValidCommitCharacterContext = preText.match(/(^|[a-z_$\(\)\[\]\{\}]|[^.]\.)\s*$/ig) !== null
@ -104,7 +51,6 @@ export function convertCompletionEntry(
label,
insertText,
kind,
textEdit,
insertTextFormat,
sortText,
commitCharacters,