-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: wait for all LSPs to respond before showing
Closes #691
- Loading branch information
Showing
4 changed files
with
202 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
local async = require('blink.cmp.lib.async') | ||
local known_defaults = { | ||
'commitCharacters', | ||
'insertTextFormat', | ||
'insertTextMode', | ||
'data', | ||
} | ||
local CompletionTriggerKind = vim.lsp.protocol.CompletionTriggerKind | ||
|
||
local completion = {} | ||
|
||
function completion.get_completion_for_client(client, context) | ||
return async.task.new(function(resolve) | ||
local params = vim.lsp.util.make_position_params(0, client.offset_encoding) | ||
params.context = { | ||
triggerKind = context.trigger.kind == 'trigger_character' and CompletionTriggerKind.TriggerCharacter | ||
or CompletionTriggerKind.Invoked, | ||
} | ||
if context.trigger.kind == 'trigger_character' then params.context.triggerCharacter = context.trigger.character end | ||
|
||
local _, request_id = client.request('textDocument/completion', params, function(err, result) | ||
if err or result == nil then | ||
resolve({ is_incomplete_forward = false, is_incomplete_backward = false, items = {} }) | ||
return | ||
end | ||
|
||
local items = result.items or result | ||
local default_edit_range = result.itemDefaults and result.itemDefaults.editRange | ||
for _, item in ipairs(items) do | ||
item.client_id = client.id | ||
|
||
-- score offset for deprecated items | ||
-- todo: make configurable | ||
if item.deprecated or (item.tags and vim.tbl_contains(item.tags, 1)) then item.score_offset = -2 end | ||
|
||
-- set defaults | ||
for key, value in pairs(result.itemDefaults or {}) do | ||
if vim.tbl_contains(known_defaults, key) then item[key] = item[key] or value end | ||
end | ||
if default_edit_range and item.textEdit == nil then | ||
local new_text = item.textEditText or item.insertText or item.label | ||
if default_edit_range.replace ~= nil then | ||
item.textEdit = { | ||
replace = default_edit_range.replace, | ||
insert = default_edit_range.insert, | ||
newText = new_text, | ||
} | ||
else | ||
item.textEdit = { | ||
range = result.itemDefaults.editRange, | ||
newText = new_text, | ||
} | ||
end | ||
end | ||
end | ||
|
||
resolve({ | ||
is_incomplete_forward = result.isIncomplete or false, | ||
is_incomplete_backward = true, | ||
items = items, | ||
}) | ||
end) | ||
|
||
-- cancellation function | ||
return function() | ||
if request_id ~= nil then client.cancel_request(request_id) end | ||
end | ||
end) | ||
end | ||
|
||
return completion |
Oops, something went wrong.