From 3f42d117b61e341f92ef889d1fa355d60168ea1f Mon Sep 17 00:00:00 2001 From: Sanchayan Maity Date: Tue, 26 Nov 2024 21:14:17 +0530 Subject: [PATCH] nvim: lsp-utils: Update Deno configuration --- nvim/.config/nvim/lua/lsp-utils.lua | 41 +++++++++++++---------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/nvim/.config/nvim/lua/lsp-utils.lua b/nvim/.config/nvim/lua/lsp-utils.lua index 69e53c1..988c04b 100644 --- a/nvim/.config/nvim/lua/lsp-utils.lua +++ b/nvim/.config/nvim/lua/lsp-utils.lua @@ -4,10 +4,17 @@ local M = {} -- -- Deno specific functions local buf_cache = function(bufnr, client) - local params = {} - params['referrer'] = { uri = vim.uri_from_bufnr(bufnr) } - params['uris'] = {} - client.request_sync('deno/cache', params) + local params = { + command = 'deno.cache', + arguments = { {}, vim.uri_from_bufnr(bufnr) }, + } + client.request('workspace/executeCommand', params, function(err, _result, ctx) + if err then + local uri = ctx.params.arguments[2] + vim.api.nvim_err_writeln('Cache command failed for ' .. vim.uri_to_fname(uri)) + end + end, bufnr) + end local virtual_text_document_handler = function(uri, res, client) @@ -25,9 +32,9 @@ local virtual_text_document_handler = function(uri, res, client) vim.api.nvim_buf_set_lines(bufnr, 0, -1, nil, lines) - vim.api.nvim_buf_set_option(bufnr, 'readonly' , true) - vim.api.nvim_buf_set_option(bufnr, 'modified' , false) - vim.api.nvim_buf_set_option(bufnr, 'modifiable', false) + vim.api.nvim_set_option_value('readonly' , true, { buf = bufnr }) + vim.api.nvim_set_option_value('modified' , false, { buf = bufnr }) + vim.api.nvim_set_option_value('modifiable', false, { buf = bufnr }) vim.lsp.buf_attach_client(bufnr, client.id) end @@ -126,9 +133,7 @@ function M.deno_config() suggest = { imports = { hosts = { - ['https://deno.land'] = true, - ['https://crux.land'] = true, - ['https://x.nest.land'] = true, + ['https://deno.land'] = true, }, }, }, @@ -138,23 +143,13 @@ function M.deno_config() ['textDocument/definition'] = denols_handler, ['textDocument/typeDefinition'] = denols_handler, ['textDocument/references'] = denols_handler, - ['workspace/executeCommand'] = function(err, result, context) - if context.params.command == 'deno.cache' then - buf_cache(context.bufnr, vim.lsp.get_client_by_id(context.client_id)) - else - vim.lsp.handlers[context.method](err, result, context) - end - end, }, commands = { DenolsCache = { function() - local clients = vim.lsp.get_active_clients() - for _, client in ipairs(clients) do - if client.name == 'denols' then - buf_cache(0, client) - break - end + local clients = vim.lsp.get_clients({ bufnr = 0, name = 'denols' }) + if #clients > 0 then + buf_cache(0, clients[#clients]) end end, description = 'Cache a module and all of its dependencies.',