diff options
author | lvimuser <109605931+lvimuser@users.noreply.github.com> | 2022-10-08 05:22:25 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-08 10:22:25 +0200 |
commit | 0773a9ee3a21db54cd6b2376dd2e087bc09d5ea1 (patch) | |
tree | bd41979a0da6a0b0f5043620633d514111510557 /runtime/lua/vim/lsp/handlers.lua | |
parent | cfdb4cbada8c65aa57e69776bcc0f7b8b298317a (diff) | |
download | rneovim-0773a9ee3a21db54cd6b2376dd2e087bc09d5ea1.tar.gz rneovim-0773a9ee3a21db54cd6b2376dd2e087bc09d5ea1.tar.bz2 rneovim-0773a9ee3a21db54cd6b2376dd2e087bc09d5ea1.zip |
feat(lsp): support window/showDocument (#19977)
Diffstat (limited to 'runtime/lua/vim/lsp/handlers.lua')
-rw-r--r-- | runtime/lua/vim/lsp/handlers.lua | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/runtime/lua/vim/lsp/handlers.lua b/runtime/lua/vim/lsp/handlers.lua index a32c59dd17..d7d9ca7ce9 100644 --- a/runtime/lua/vim/lsp/handlers.lua +++ b/runtime/lua/vim/lsp/handlers.lua @@ -512,6 +512,52 @@ M['window/showMessage'] = function(_, result, ctx, _) return result end +--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#window_showDocument +M['window/showDocument'] = function(_, result, ctx, _) + local uri = result.uri + + if result.external then + -- TODO(lvimuser): ask the user for confirmation + local cmd + if vim.fn.has('win32') == 1 then + cmd = { 'cmd.exe', '/c', 'start', '""', vim.fn.shellescape(uri) } + elseif vim.fn.has('macunix') == 1 then + cmd = { 'open', vim.fn.shellescape(uri) } + else + cmd = { 'xdg-open', vim.fn.shellescape(uri) } + end + + local ret = vim.fn.system(cmd) + if vim.v.shellerror ~= 0 then + return { + success = false, + error = { + code = protocol.ErrorCodes.UnknownErrorCode, + message = ret, + }, + } + end + + return { success = true } + end + + local client_id = ctx.client_id + local client = vim.lsp.get_client_by_id(client_id) + local client_name = client and client.name or string.format('id=%d', client_id) + if not client then + err_message({ 'LSP[', client_name, '] client has shut down after sending ', ctx.method }) + return vim.NIL + end + + local location = { + uri = uri, + range = result.selection, + } + + local success = util.show_document(location, client.offset_encoding, true, result.takeFocus) + return { success = success or false } +end + -- Add boilerplate error validation and logging for all of these. for k, fn in pairs(M) do M[k] = function(err, result, ctx, config) |