Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lsp): inlay hints #3

Merged
merged 4 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ vscode-langservers-extracted pyright lua-language-server`

## Tmux

Additinally you can use my tmux config to have a nice status bar.
Additionally you can use my tmux config to have a nice status bar.
They are located in `tmux.conf`.
55 changes: 46 additions & 9 deletions lua/plugins/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ 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
local client = vim.lsp.get_client_by_id(ev.data.client_id)
if client.supports_method("textDocument/inlayHint") then
vim.g.inlay_hints_visible = true
vim.lsp.inlay_hint(ev.buf, true)
-- set the keymap to toggle on/off
vim.keymap.set("n", "<leader>ch", function()
vim.lsp.inlay_hint(ev.buf, nil)
end, { desc = "Toggle Inlay [H]ints" })
end
end,
})
-- nvim-cmp supports additional completion capabilities, so broadcast that to servers
Expand Down Expand Up @@ -213,19 +223,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 },
workspace = {
checkThirdParty = false,
},
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",
},
},
}