comparison dot_config/nvim/init.lua @ 446:9c575d146453

Add mapping to open definition in split
author Zeger Van de Vannet <zegervdv@me.com>
date Wed, 01 Sep 2021 11:14:31 +0200
parents 34fb1bd9986f
children aa15d8b06f04
comparison
equal deleted inserted replaced
445:34fb1bd9986f 446:9c575d146453
567 local on_attach = function(client) 567 local on_attach = function(client)
568 local nnoremap = vim.keymap.nnoremap 568 local nnoremap = vim.keymap.nnoremap
569 local inoremap = vim.keymap.inoremap 569 local inoremap = vim.keymap.inoremap
570 nnoremap { 'gd', vim.lsp.buf.declaration, silent = true } 570 nnoremap { 'gd', vim.lsp.buf.declaration, silent = true }
571 nnoremap { '<c-]>', vim.lsp.buf.definition, silent = true } 571 nnoremap { '<c-]>', vim.lsp.buf.definition, silent = true }
572 nnoremap {
573 'g<c-]>',
574 function ()
575 local params = vim.lsp.util.make_position_params()
576 opts = {}
577 local results_lsp = vim.lsp.buf_request_sync(0, "textDocument/definition", params, opts.timeout or 10000)
578 if not results_lsp or vim.tbl_isempty(results_lsp) then
579 print("No results from textDocument/definition")
580 return
581 end
582 for _, lsp_data in pairs(results_lsp) do
583 if lsp_data ~= nil and lsp_data.result ~= nil and not vim.tbl_isempty(lsp_data.result) then
584 for _, value in pairs(lsp_data.result) do
585 local range = value.range or value.targetRange
586 if range ~= nil then
587 local file = value.uri or value.targetUri
588 if file ~=nil then
589 vim.api.nvim_command [[split]]
590 vim.lsp.util.jump_to_location(value)
591 return
592 end
593 end
594 end
595 end
596 end
597 -- try to call default lsp function
598 vim.lsp.buf.definition()
599 end,
600 silent = true
601 }
572 nnoremap { 'K', vim.lsp.buf.hover, silent = true } 602 nnoremap { 'K', vim.lsp.buf.hover, silent = true }
573 nnoremap { 'gD', vim.lsp.buf.implementation, silent = true } 603 nnoremap { 'gD', vim.lsp.buf.implementation, silent = true }
574 nnoremap { '1gD', vim.lsp.buf.type_definition, silent = true } 604 nnoremap { '1gD', vim.lsp.buf.type_definition, silent = true }
575 nnoremap { 'gr', vim.lsp.buf.references, silent = true } 605 nnoremap { 'gr', vim.lsp.buf.references, silent = true }
576 nnoremap { 'g0', vim.lsp.buf.document_symbol, silent = true } 606 nnoremap { 'g0', vim.lsp.buf.document_symbol, silent = true }