From c102b696d9135edeadb02aca76177bff76f1abfc Mon Sep 17 00:00:00 2001 From: Thomas Vigouroux Date: Tue, 16 Aug 2022 13:51:48 +0200 Subject: [PATCH] fix(lsp): CompleteDone coding mistake --- lua/complementree/init.lua | 2 ++ lua/complementree/sources.lua | 11 +++++++---- teal/complementree/init.tl | 2 ++ teal/complementree/sources.tl | 11 +++++++---- types/types.d.tl | 3 +++ 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/lua/complementree/init.lua b/lua/complementree/init.lua index 1e6b167..2843cb9 100644 --- a/lua/complementree/init.lua +++ b/lua/complementree/init.lua @@ -141,8 +141,10 @@ function M._CompleteDone() if not completed_item or not completed_item.user_data or not completed_item.user_data.source then return end + vim.notify("CompleteDone") local func = sources.complete_done_cbs[completed_item.user_data.source] if func then + vim.notify("CompleteDone found") diff --git a/lua/complementree/sources.lua b/lua/complementree/sources.lua index 90fc6e4..762caaf 100644 --- a/lua/complementree/sources.lua +++ b/lua/complementree/sources.lua @@ -428,20 +428,23 @@ local function lsp_completedone(completed_item) local cursor = api.nvim_win_get_cursor(0) local col = cursor[2] local lnum = cursor[1] - 1 - local item = completed_item.user_data local bufnr = api.nvim_get_current_buf() - local expand_snippet = item.insertTextFormat == 2 - local client = lsp.get_client_by_id() + local extra = completed_item.user_data.extra + local item = extra.item + + local client = lsp.get_client_by_id(extra.client_id) if not client then - return + error(string.format("Could not find client %d", extra.client_id)) end + local expand_snippet = item.insertTextFormat == 2 local resolveEdits = (client.server_capabilities.completionProvider or {}).resolveProvider local offset_encoding = client and client.offset_encoding or 'utf-16' local tidy = function() end local suffix = nil + if expand_snippet then local line = api.nvim_buf_get_lines(bufnr, lnum, lnum + 1, true)[1] tidy = function() diff --git a/teal/complementree/init.tl b/teal/complementree/init.tl index eda3035..c40410a 100644 --- a/teal/complementree/init.tl +++ b/teal/complementree/init.tl @@ -141,8 +141,10 @@ function M._CompleteDone() if not completed_item or not completed_item.user_data or not completed_item.user_data.source then return end + vim.notify "CompleteDone" local func = sources.complete_done_cbs[completed_item.user_data.source] if func then + vim.notify "CompleteDone found" -- We will force the ignore of InsertLeave events for a certain time, in order to avoid strange -- behavior and flickering of the UI. So we _synchronously_ set 'eventignore' to ignore -- InsertLeave, and schedule the reset in the loop. diff --git a/teal/complementree/sources.tl b/teal/complementree/sources.tl index 67dbe5b..7259522 100644 --- a/teal/complementree/sources.tl +++ b/teal/complementree/sources.tl @@ -428,20 +428,23 @@ local function lsp_completedone(completed_item: CompleteItem) local cursor = api.nvim_win_get_cursor(0) local col = cursor[2] local lnum = cursor[1] - 1 - local item = completed_item.user_data as lsp.LspCompletionItem local bufnr = api.nvim_get_current_buf() - local expand_snippet = item.insertTextFormat == 2 - local client = lsp.get_client_by_id() + local extra = completed_item.user_data.extra as LspExtraInfo + local item = extra.item + + local client = lsp.get_client_by_id(extra.client_id) if not client then - return + error(string.format("Could not find client %d", extra.client_id)) end + local expand_snippet = item.insertTextFormat == 2 local resolveEdits = (client.server_capabilities.completionProvider or {}).resolveProvider local offset_encoding = client and client.offset_encoding or 'utf-16' local tidy = function() end local suffix: string = nil + if expand_snippet then local line = api.nvim_buf_get_lines(bufnr, lnum, lnum + 1, true)[1] tidy = function() diff --git a/types/types.d.tl b/types/types.d.tl index 3ac7d97..bb640d3 100644 --- a/types/types.d.tl +++ b/types/types.d.tl @@ -150,6 +150,9 @@ global record vim tbl_map: function(function(T), {T}) list_extend: function({T}, {T}, integer|nil, integer|nil): {T} + + notify: function(string) + pretty_print: function(...: any) inspect: function(...: any): string end -- 2.45.2