aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2026-10-02 17:18:58 +0200
committerMartin Fischer <martin@push-f.com>2026-10-30 18:02:24 +0100
commitf48322283217ef93515c76fe184b02b91d5f9c14 (patch)
tree60e4eaeaf2d8864e14eb5528b97c5394209ff0fa
parentd31b120ac5b97db1a0f91b0ba5cfc64e7d0b96fd (diff)
feat(workstation): set up LSP with nvim
-rw-r--r--nixos/profiles/workstation/dev.nix1
-rw-r--r--nixos/profiles/workstation/graphical.nix4
-rw-r--r--nixos/profiles/workstation/pkgs/nvim.nix4
-rw-r--r--user/nvim/init.lua64
4 files changed, 73 insertions, 0 deletions
diff --git a/nixos/profiles/workstation/dev.nix b/nixos/profiles/workstation/dev.nix
index 5ccca6f..7b47fe0 100644
--- a/nixos/profiles/workstation/dev.nix
+++ b/nixos/profiles/workstation/dev.nix
@@ -29,6 +29,7 @@
# language servers
rust-analyzer
nixd
+ taplo
# documentation
man-pages # Linux development manual pages
diff --git a/nixos/profiles/workstation/graphical.nix b/nixos/profiles/workstation/graphical.nix
index 5c82d49..c633456 100644
--- a/nixos/profiles/workstation/graphical.nix
+++ b/nixos/profiles/workstation/graphical.nix
@@ -52,6 +52,10 @@
[[ "$(tty)" == /dev/tty1 ]] && exec niri-session -l
'';
+ fonts.packages = with pkgs; [
+ nerd-fonts.symbols-only
+ ];
+
environment.systemPackages = with pkgs; [
wmenu
i3bar-river
diff --git a/nixos/profiles/workstation/pkgs/nvim.nix b/nixos/profiles/workstation/pkgs/nvim.nix
index 46a678c..aaedda6 100644
--- a/nixos/profiles/workstation/pkgs/nvim.nix
+++ b/nixos/profiles/workstation/pkgs/nvim.nix
@@ -19,5 +19,9 @@ pkgs.wrapNeovimUnstable pkgs.neovim-unwrapped {
svelte
typescript
]))
+
+ # For LSP. Language servers are installed in ../dev.nix.
+ nvim-lspconfig
+ blink-cmp
];
}
diff --git a/user/nvim/init.lua b/user/nvim/init.lua
index 108f84a..3ef8c88 100644
--- a/user/nvim/init.lua
+++ b/user/nvim/init.lua
@@ -25,6 +25,63 @@ pick.setup({ source = { show = pick.default_show } })
-- Reuse Neovim's popup-menu selection color for mini.pick's selected item.
vim.api.nvim_set_hl(0, 'MiniPickMatchCurrent', { link = 'PmenuSel' })
+-- Show diagnostics inline at the end of the affected line.
+vim.diagnostic.config({ virtual_text = true })
+
+-- Enable language servers when they are available (for example, from a nix shell).
+local language_servers = {
+ { name = 'rust_analyzer', cmd = { 'rust-analyzer' } },
+ { name = 'pyright', cmd = { 'pyright-langserver', '--stdio' } },
+ { name = 'ts_ls', cmd = { 'typescript-language-server', '--stdio' } },
+ -- nvim-lspconfig's gopls root detection also invokes `go env`.
+ { name = 'gopls', cmd = { 'gopls' }, required_commands = { 'go' } },
+ { name = 'nixd', cmd = { 'nixd' } },
+ { name = 'svelte', cmd = { 'svelteserver', '--stdio' } },
+ { name = 'taplo', cmd = { 'taplo', 'lsp', 'stdio' } },
+}
+
+for _, server in ipairs(language_servers) do
+ local command = vim.fn.exepath(server.cmd[1])
+ local available = command ~= ''
+
+ for _, required_command in ipairs(server.required_commands or {}) do
+ if vim.fn.exepath(required_command) == '' then
+ available = false
+ break
+ end
+ end
+
+ if available then
+ server.cmd[1] = command
+ vim.lsp.config(server.name, { cmd = server.cmd })
+ vim.lsp.enable(server.name)
+ end
+end
+
+require('blink.cmp').setup({
+ keymap = {
+ preset = 'default',
+ ['<CR>'] = {
+ 'accept',
+ function()
+ if vim.fn.pumvisible() == 1 then
+ return vim.keycode('<C-y>')
+ end
+ end,
+ 'fallback',
+ },
+ },
+ sources = {
+ -- Only show completion items provided by an attached LSP. This disables
+ -- blink.cmp's default buffer/path/snippet sources, which otherwise trigger
+ -- completions in plain text and Markdown files.
+ default = { 'lsp' },
+ },
+ completion = {
+ documentation = { auto_show = true },
+ },
+})
+
-- Keyboard shortcuts
-- Clear search highlighting with Escape.
@@ -35,6 +92,13 @@ vim.keymap.set('n', '<C-p>', function()
pick.builtin.files({ tool = tool })
end, { desc = 'Pick files' })
+vim.keymap.set('n', 'gd', vim.lsp.buf.definition, {
+ desc = 'LSP: Go to definition',
+})
+vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, {
+ desc = 'LSP: Go to declaration',
+})
+
-- Disable netrw's directory browser; directory buffers are handled below with MiniPick.
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1