From eebffce98e4c9a53db1f9c99781793b48adce507 Mon Sep 17 00:00:00 2001 From: Sanchayan Maity Date: Sat, 25 Sep 2021 15:20:44 +0530 Subject: [PATCH] nvim: lsp: Add back custom preview function Follow up to 469e367. --- nvim/.config/nvim/lua/lsp.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/nvim/.config/nvim/lua/lsp.lua b/nvim/.config/nvim/lua/lsp.lua index 09236f2..6e0fe11 100644 --- a/nvim/.config/nvim/lua/lsp.lua +++ b/nvim/.config/nvim/lua/lsp.lua @@ -5,6 +5,19 @@ local ts_utils = require("nvim-lsp-ts-utils") local null_ls = require("null-ls") local util = require("lspconfig/util") +-- https://github.com/neovim/nvim-lspconfig/wiki/User-contributed-tips +local function preview_location_callback(_, result) + if result == nil or vim.tbl_isempty(result) then + return nil + end + vim.lsp.util.preview_location(result[1]) +end + +function PeekDefinition() + local params = vim.lsp.util.make_position_params() + return vim.lsp.buf_request(0, 'textDocument/definition', params, preview_location_callback) +end + local on_attach = function(client, bufnr) signature.on_attach({ bind = true, @@ -33,6 +46,7 @@ local on_attach = function(client, bufnr) vim.api.nvim_buf_set_keymap(bufnr, 'n', '1gd' , 'lua vim.lsp.buf.document_symbol()' , opts) vim.api.nvim_buf_set_keymap(bufnr, 'n', '1gD' , 'lua vim.lsp.buf.workspace_symbol()', opts) vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gR' , 'lua vim.lsp.buf.rename()' , opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'pd' , 'lua PeekDefinition()' , opts) vim.api.nvim_buf_set_keymap(bufnr, 'n', '[d', 'lua vim.lsp.diagnostic.goto_prev { wrap = false }', opts) vim.api.nvim_buf_set_keymap(bufnr, 'n', ']d', 'lua vim.lsp.diagnostic.goto_next { wrap = false }', opts)