Skip to content

Commit

Permalink
Fix #25 does not insert snippet directly
Browse files Browse the repository at this point in the history
  • Loading branch information
Shougo committed Oct 15, 2021
1 parent 75b5382 commit a5f9c16
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
34 changes: 17 additions & 17 deletions denops/@ddc-sources/nvim-lsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,28 +91,28 @@ export class Source extends BaseSource<Params> {
completePosition: number,
): Candidate[] {
const candidates = results.map((v) => {
let word = "";

// Remove heading spaces.
const label = v.label.replace(/^\s+/, "");

if (v.textEdit) {
const textEdit = v.textEdit;
if (
"range" in textEdit && equal(textEdit.range.start, textEdit.range.end)
) {
word = `${input.slice(completePosition)}${textEdit.newText}`;
} else {
word = textEdit.newText;
}
} else if (v.insertText) {
if (v.insertTextFormat != InsertTextFormat.PlainText) {
word = label;
} else {
let word = label;

// Note: Does not insert snippet directly
if (
!v.insertTextFormat || v.insertTextFormat == InsertTextFormat.PlainText
) {
if (v.textEdit) {
const textEdit = v.textEdit;
if (
"range" in textEdit &&
equal(textEdit.range.start, textEdit.range.end)
) {
word = `${input.slice(completePosition)}${textEdit.newText}`;
} else {
word = textEdit.newText;
}
} else if (v.insertText) {
word = v.insertText;
}
} else {
word = label;
}

// Remove parentheses from word.
Expand Down
2 changes: 1 addition & 1 deletion lua/ddc_nvim_lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ end

local request_candidates = function(arguments, id)
local map = vim.lsp.buf_request(0, 'textDocument/completion', arguments, function(_, arg1, arg2) get_candidates(id, _, arg1, arg2) end)
if #map == 0 then
if not map or #map == 0 then
api.nvim_call_function('ddc#callback', {id, {
result = {},
success = false,
Expand Down

0 comments on commit a5f9c16

Please sign in to comment.