From ec6e40659444ad0d13fff03cc04e1e855221a63f Mon Sep 17 00:00:00 2001 From: chemzqm Date: Tue, 4 Dec 2018 11:51:49 +0800 Subject: [PATCH] remove textEdit of completionItem --- src/server/features/completionItemProvider.ts | 20 ++----- src/server/utils/completionItem.ts | 56 +------------------ 2 files changed, 5 insertions(+), 71 deletions(-) diff --git a/src/server/features/completionItemProvider.ts b/src/server/features/completionItemProvider.ts index ef43bb7..bc1c2ce 100644 --- a/src/server/features/completionItemProvider.ts +++ b/src/server/features/completionItemProvider.ts @@ -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( diff --git a/src/server/utils/completionItem.ts b/src/server/utils/completionItem.ts index 6c1cfde..70f3d64 100644 --- a/src/server/utils/completionItem.ts +++ b/src/server/utils/completionItem.ts @@ -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,