Skip to content

Commit

Permalink
feat(lsp): inlay hints
Browse files Browse the repository at this point in the history
Depends on neovim 0.10.
Ideas taken from https://youtu.be/DYaTzkw3zqQ and LazyVim/LazyVim@01c7eee.
Closes #1.
  • Loading branch information
realeinherjar committed Sep 20, 2023
1 parent a8b2c09 commit 23442b5
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 105 deletions.
53 changes: 44 additions & 9 deletions lua/plugins/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ return {
vim.keymap.set("n", "<leader>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", "<leader>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
Expand Down Expand Up @@ -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 },
},
},
})
Expand Down
161 changes: 65 additions & 96 deletions lua/plugins/rust.lua
Original file line number Diff line number Diff line change
@@ -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", "<CMD>RustHoverActions<CR>", { buffer = bufnr, desc = "Hover Documentation" })
-- Code action groups
vim.keymap.set("n", "<leader>ca", "<CMD>RustCodeAction<CR>", { 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 = {
{
"<leader>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 = {
{
"<leader>tt",
function()
require("neotest").run.run(vim.fn.expand("%"))
end,
desc = "Run File",
},
{
"<leader>tT",
function()
require("neotest").run.run(vim.loop.cwd())
end,
desc = "Run All Test Files",
},
{
"<leader>tr",
function()
require("neotest").run.run()
end,
desc = "Run Nearest",
},
{
"<leader>ts",
function()
require("neotest").summary.toggle()
end,
desc = "Toggle Summary",
},
{
"<leader>to",
function()
require("neotest").output.open({ enter = true, auto_close = true })
end,
desc = "Show Output",
},
{
"<leader>tO",
function()
require("neotest").output_panel.toggle()
end,
desc = "Toggle Output Panel",
},
{
"<leader>tS",
function()
require("neotest").run.stop()
end,
desc = "Stop",
},
{
"<leader>tT",
function()
require("neotest").run.run(vim.loop.cwd())
end,
desc = "Run All Test Files",
},
{
"<leader>tr",
function()
require("neotest").run.run()
end,
desc = "Run Nearest",
},
{
"<leader>ts",
function()
require("neotest").summary.toggle()
end,
desc = "Toggle Summary",
},
{
"<leader>to",
function()
require("neotest").output.open({ enter = true, auto_close = true })
end,
desc = "Show Output",
},
{
"<leader>tO",
function()
require("neotest").output_panel.toggle()
end,
desc = "Toggle Output Panel",
},
{
"<leader>tS",
function()
require("neotest").run.stop()
end,
desc = "Stop",
},
},
}

0 comments on commit 23442b5

Please sign in to comment.