# HG changeset patch # User Zeger Van de Vannet # Date 1630487671 -7200 # Node ID 9c575d1464535eae1b179173eda0422bcbfa1d27 # Parent 34fb1bd9986f95a2fc3f06ec6cb05c2e03480a1d Add mapping to open definition in split diff -r 34fb1bd9986f -r 9c575d146453 dot_config/nvim/init.lua --- a/dot_config/nvim/init.lua Wed Sep 01 11:13:53 2021 +0200 +++ b/dot_config/nvim/init.lua Wed Sep 01 11:14:31 2021 +0200 @@ -569,6 +569,36 @@ local inoremap = vim.keymap.inoremap nnoremap { 'gd', vim.lsp.buf.declaration, silent = true } nnoremap { '', vim.lsp.buf.definition, silent = true } + nnoremap { + 'g', + function () + local params = vim.lsp.util.make_position_params() + opts = {} + local results_lsp = vim.lsp.buf_request_sync(0, "textDocument/definition", params, opts.timeout or 10000) + if not results_lsp or vim.tbl_isempty(results_lsp) then + print("No results from textDocument/definition") + return + end + for _, lsp_data in pairs(results_lsp) do + if lsp_data ~= nil and lsp_data.result ~= nil and not vim.tbl_isempty(lsp_data.result) then + for _, value in pairs(lsp_data.result) do + local range = value.range or value.targetRange + if range ~= nil then + local file = value.uri or value.targetUri + if file ~=nil then + vim.api.nvim_command [[split]] + vim.lsp.util.jump_to_location(value) + return + end + end + end + end + end + -- try to call default lsp function + vim.lsp.buf.definition() + end, + silent = true + } nnoremap { 'K', vim.lsp.buf.hover, silent = true } nnoremap { 'gD', vim.lsp.buf.implementation, silent = true } nnoremap { '1gD', vim.lsp.buf.type_definition, silent = true }