nvim: lsp-utils: Update Deno configuration

This commit is contained in:
Sanchayan Maity 2024-11-26 21:14:17 +05:30
parent 218eff222e
commit 3f42d117b6
Signed by: sanchayanmaity
GPG key ID: 6F6A0609C12038F3

View file

@ -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.',