diff options
author | Lewis Russell <lewis6991@gmail.com> | 2022-05-18 20:03:24 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-18 21:03:24 +0200 |
commit | 3eea66d65a75c83cbd6bd7ec2aa0886781c807c9 (patch) | |
tree | ecaef2738b6550e485cd83b633d79dfd5458527c /runtime/lua/vim/lsp/buf.lua | |
parent | 03a8269e3a904e7660eb95b9c17ccfc0938f1e30 (diff) | |
download | rneovim-3eea66d65a75c83cbd6bd7ec2aa0886781c807c9.tar.gz rneovim-3eea66d65a75c83cbd6bd7ec2aa0886781c807c9.tar.bz2 rneovim-3eea66d65a75c83cbd6bd7ec2aa0886781c807c9.zip |
feat(lsp): option to reuse_win for jump actions (#18577)
Diffstat (limited to 'runtime/lua/vim/lsp/buf.lua')
-rw-r--r-- | runtime/lua/vim/lsp/buf.lua | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua index b0bf2c6e5b..80350bcb71 100644 --- a/runtime/lua/vim/lsp/buf.lua +++ b/runtime/lua/vim/lsp/buf.lua @@ -63,26 +63,45 @@ function M.hover() request('textDocument/hover', params) end +---@private +local function request_with_options(name, params, options) + local req_handler + if options then + req_handler = function(err, result, ctx, config) + local client = vim.lsp.get_client_by_id(ctx.client_id) + local handler = client.handlers[name] or vim.lsp.handlers[name] + handler(err, result, ctx, vim.tbl_extend('force', config or {}, options)) + end + end + request(name, params, req_handler) +end + --- Jumps to the declaration of the symbol under the cursor. ---@note Many servers do not implement this method. Generally, see |vim.lsp.buf.definition()| instead. --- -function M.declaration() +---@param options table|nil additional options +--- - reuse_win: (boolean) Jump to existing window if buffer is already open. +function M.declaration(options) local params = util.make_position_params() - request('textDocument/declaration', params) + request_with_options('textDocument/declaration', params, options) end --- Jumps to the definition of the symbol under the cursor. --- -function M.definition() +---@param options table|nil additional options +--- - reuse_win: (boolean) Jump to existing window if buffer is already open. +function M.definition(options) local params = util.make_position_params() - request('textDocument/definition', params) + request_with_options('textDocument/definition', params, options) end --- Jumps to the definition of the type of the symbol under the cursor. --- -function M.type_definition() +---@param options table|nil additional options +--- - reuse_win: (boolean) Jump to existing window if buffer is already open. +function M.type_definition(options) local params = util.make_position_params() - request('textDocument/typeDefinition', params) + request_with_options('textDocument/typeDefinition', params, options) end --- Lists all the implementations for the symbol under the cursor in the |