From 31c9213c0a3580e02e601fb80cd9a43210cc72b9 Mon Sep 17 00:00:00 2001 From: Sanchayan Maity Date: Tue, 20 Jun 2023 16:45:21 +0530 Subject: [PATCH] nvim: lsp: Add support for inlay hints Make sure to disable inlay hints by default. It seems to be quite bug ridden at the moment. However, we add a key mapping to toggle inlay hints. --- nvim/.config/nvim/lua/lsp.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/nvim/.config/nvim/lua/lsp.lua b/nvim/.config/nvim/lua/lsp.lua index 2990099..159f94c 100644 --- a/nvim/.config/nvim/lua/lsp.lua +++ b/nvim/.config/nvim/lua/lsp.lua @@ -50,15 +50,16 @@ local lsp_augroup_id = vim.api.nvim_create_augroup("LSP", { clear = true }) local lsp_key_mappings = { { "definitionProvider" , 'n', 'pd' , 'lua PeekDefinition()' }, { "definitionProvider" , 'n', 'gd' , 'lua vim.lsp.buf.definition()' }, - { "declarationProvider" , 'n', 'gD' , 'lua vim.lsp.buf.declaration()' }, +--{ "declarationProvider" , 'n', 'gD' , 'lua vim.lsp.buf.declaration()' }, { "typeDefinitionProvider" , 'n', '' , 'lua vim.lsp.buf.type_definition()' }, { "referencesProvider" , 'n', 'gr' , 'lua vim.lsp.buf.references()' }, - { "implementationProvider" , 'n', 'gi' , 'lua vim.lsp.buf.implementation()' }, + { "implementationProvider" , 'n', 'gD' , 'lua vim.lsp.buf.implementation()' }, { "documentSymbolProvider" , 'n', '1gd' , 'lua vim.lsp.buf.document_symbol()' }, { "workspaceSymbolProvider", 'n', '1gD' , 'lua vim.lsp.buf.workspace_symbol()' }, { "hoverProvider" , 'n', 'k', 'lua vim.lsp.buf.hover()' }, { "signatureHelpProvider" , 'n', 'S', 'lua vim.lsp.buf.signature_help()' }, { "renameProvider" , 'n', 'gR' , 'lua vim.lsp.buf.rename()' }, + { "inlayHintProvider" , 'n', 'gi' , 'lua vim.lsp.buf.inlay_hint(0, nil)' }, { "documentRangeFormattingProvider", 'x', 'gq', 'lua vim.lsp.buf.format({async=true})' }, { "documentFormattingProvider" , 'n', 'gq', 'lua vim.lsp.buf.format({async=true})' }, @@ -192,6 +193,10 @@ local on_attach = function(client, bufnr) callback = vim.lsp.buf.clear_references, }) end + + if client.server_capabilities.inlayHintProvider then + vim.lsp.buf.inlay_hint(bufnr, false) + end end vim.api.nvim_create_autocmd("LspAttach", {