From 23442b59f347b2838397a5eaff7a404f11e50588 Mon Sep 17 00:00:00 2001 From: Einherjar Date: Wed, 20 Sep 2023 11:59:22 -0300 Subject: [PATCH] feat(lsp): inlay hints Depends on neovim 0.10. Ideas taken from https://youtu.be/DYaTzkw3zqQ and https://github.com/LazyVim/LazyVim/commit/01c7eeebd0641bd952e3c518dd28b178aed8e148. Closes #1. --- lua/plugins/lsp.lua | 53 +++++++++++--- lua/plugins/rust.lua | 161 +++++++++++++++++-------------------------- 2 files changed, 109 insertions(+), 105 deletions(-) diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua index e35090f..cfad5b3 100644 --- a/lua/plugins/lsp.lua +++ b/lua/plugins/lsp.lua @@ -102,6 +102,14 @@ return { vim.keymap.set("n", "cwl", function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end, { desc = "[L]ist Folders" }) + -- Enable inlay hints (depends on neovim 0.10) + if vim.lsp.inlay_hint then + vim.lsp.buf.inlay_hint(0, true) -- toggle on by default + -- set the keymap to toggle on/off + vim.keymap.set("n", "ch", function() + vim.lsp.inlay_hint(0, nil) + end, { desc = "Toggle Inlay [H]ints" }) + end end, }) -- nvim-cmp supports additional completion capabilities, so broadcast that to servers @@ -218,19 +226,46 @@ return { }, }) -- Enable some language servers with the additional completion capabilities offered by nvim-cmp - lsp.pyright.setup({ capabilities = capabilities }) -- requires pyright to be installed - lsp.tsserver.setup({ capabilities = capabilities }) -- requires typescript-language-server to be installed - lsp.bashls.setup({ capabilities = capabilities }) -- requires bash-language-server to be installed - lsp.html.setup({ capabilities = capabilities }) -- requires vscode-langservers-extracted to be installed - lsp.cssls.setup({ capabilities = capabilities }) -- requires vscode-langservers-extracted to be installed - lsp.jsonls.setup({ capabilities = capabilities }) -- requires vscode-langservers-extracted to be installed - lsp.eslint.setup({ capabilities = capabilities }) -- requires vscode-langservers-extracted to be installed - lsp.rnix.setup({ capabilities = capabilities }) -- requires rnix-lsp to be installed - lsp.lua_ls.setup({ -- requires lua-language-server to be installed + lsp.pyright.setup({ capabilities = capabilities }) -- requires pyright to be installed + lsp.tsserver.setup({ -- requires typescript-language-server to be installed + capabilities = capabilities, + -- taken from https://github.com/typescript-language-server/typescript-language-server#workspacedidchangeconfiguration + javascript = { + inlayHints = { + includeInlayEnumMemberValueHints = true, + includeInlayFunctionLikeReturnTypeHints = true, + includeInlayFunctionParameterTypeHints = true, + includeInlayParameterNameHints = "all", + includeInlayParameterNameHintsWhenArgumentMatchesName = true, + includeInlayPropertyDeclarationTypeHints = true, + includeInlayVariableTypeHints = true, + }, + }, + typescript = { + inlayHints = { + includeInlayEnumMemberValueHints = true, + includeInlayFunctionLikeReturnTypeHints = true, + includeInlayFunctionParameterTypeHints = true, + includeInlayParameterNameHints = "all", + includeInlayParameterNameHintsWhenArgumentMatchesName = true, + includeInlayPropertyDeclarationTypeHints = true, + includeInlayVariableTypeHints = true, + }, + }, + }) + lsp.bashls.setup({ capabilities = capabilities }) -- requires bash-language-server to be installed + lsp.html.setup({ capabilities = capabilities }) -- requires vscode-langservers-extracted to be installed + lsp.cssls.setup({ capabilities = capabilities }) -- requires vscode-langservers-extracted to be installed + lsp.jsonls.setup({ capabilities = capabilities }) -- requires vscode-langservers-extracted to be installed + lsp.eslint.setup({ capabilities = capabilities }) -- requires vscode-langservers-extracted to be installed + lsp.rnix.setup({ capabilities = capabilities }) -- requires rnix-lsp to be installed + lsp.lua_ls.setup({ -- requires lua-language-server to be installed capabilities = capabilities, settings = { Lua = { + workspace = { checkThirdParty = false }, telemetry = { enable = false }, + hint = { enable = true }, }, }, }) diff --git a/lua/plugins/rust.lua b/lua/plugins/rust.lua index 61289f4..64e05e6 100644 --- a/lua/plugins/rust.lua +++ b/lua/plugins/rust.lua @@ -1,104 +1,73 @@ return { - { - "simrat39/rust-tools.nvim", - event = { "BufReadPre", "BufNewFile" }, - lazy = true, - opts = { - on_initialized = function() - vim.cmd([[ - augroup RustLSP - autocmd CursorHold *.rs silent! lua vim.lsp.buf.document_highlight() - autocmd CursorMoved,InsertEnter *.rs silent! lua vim.lsp.buf.clear_references() - autocmd BufEnter,CursorHold,InsertLeave *.rs silent! lua vim.lsp.codelens.refresh() - augroup END - ]]) - end, + "nvim-neotest/neotest", + dependencies = { + { + "rouge8/neotest-rust", + dependencies = { + "nvim-lua/plenary.nvim", + "nvim-treesitter/nvim-treesitter", + "antoinemadec/FixCursorHold.nvim", + }, }, - config = function() - local rt = require("rust-tools") - rt.setup({ - server = { - on_attach = function(_, bufnr) - -- Hover actions - vim.keymap.set("n", "K", "RustHoverActions", { buffer = bufnr, desc = "Hover Documentation" }) - -- Code action groups - vim.keymap.set("n", "ca", "RustCodeAction", { buffer = bufnr, desc = "Code [A]ction" }) - end, - }, - }) - end, }, - { - "nvim-neotest/neotest", - dependencies = { - { - "rouge8/neotest-rust", - dependencies = { - "nvim-lua/plenary.nvim", - "nvim-treesitter/nvim-treesitter", - "antoinemadec/FixCursorHold.nvim", - }, + config = function() + require("neotest").setup({ + status = { virtual_text = true }, + output = { open_on_run = true }, + adapters = { + require("neotest-rust"), }, + }) + end, + keys = { + { + "tt", + function() + require("neotest").run.run(vim.fn.expand("%")) + end, + desc = "Run File", }, - config = function() - require("neotest").setup({ - status = { virtual_text = true }, - output = { open_on_run = true }, - adapters = { - require("neotest-rust"), - }, - }) - end, - keys = { - { - "tt", - function() - require("neotest").run.run(vim.fn.expand("%")) - end, - desc = "Run File", - }, - { - "tT", - function() - require("neotest").run.run(vim.loop.cwd()) - end, - desc = "Run All Test Files", - }, - { - "tr", - function() - require("neotest").run.run() - end, - desc = "Run Nearest", - }, - { - "ts", - function() - require("neotest").summary.toggle() - end, - desc = "Toggle Summary", - }, - { - "to", - function() - require("neotest").output.open({ enter = true, auto_close = true }) - end, - desc = "Show Output", - }, - { - "tO", - function() - require("neotest").output_panel.toggle() - end, - desc = "Toggle Output Panel", - }, - { - "tS", - function() - require("neotest").run.stop() - end, - desc = "Stop", - }, + { + "tT", + function() + require("neotest").run.run(vim.loop.cwd()) + end, + desc = "Run All Test Files", + }, + { + "tr", + function() + require("neotest").run.run() + end, + desc = "Run Nearest", + }, + { + "ts", + function() + require("neotest").summary.toggle() + end, + desc = "Toggle Summary", + }, + { + "to", + function() + require("neotest").output.open({ enter = true, auto_close = true }) + end, + desc = "Show Output", + }, + { + "tO", + function() + require("neotest").output_panel.toggle() + end, + desc = "Toggle Output Panel", + }, + { + "tS", + function() + require("neotest").run.stop() + end, + desc = "Stop", }, }, }