diff options
| author | Martin Fischer <martin@push-f.com> | 2026-10-02 17:18:58 +0200 |
|---|---|---|
| committer | Martin Fischer <martin@push-f.com> | 2026-10-20 17:05:52 +0200 |
| commit | 997ffd41e78417726f269fe739e9a33217449758 (patch) | |
| tree | 7fd7f3afee564af7561d9eb2271187656a7fad08 | |
| parent | efc48406acbd04968c5cee1ea8382b4a1eb9cd6b (diff) | |
feat(workstation): set up LSP with nvim
| -rw-r--r-- | nixos/profiles/workstation/graphical.nix | 4 | ||||
| -rw-r--r-- | nixos/profiles/workstation/pkgs/nvim.nix | 4 | ||||
| -rw-r--r-- | user/nvim/init.lua | 52 |
3 files changed, 60 insertions, 0 deletions
diff --git a/nixos/profiles/workstation/graphical.nix b/nixos/profiles/workstation/graphical.nix index 8027200..d7076df 100644 --- a/nixos/profiles/workstation/graphical.nix +++ b/nixos/profiles/workstation/graphical.nix @@ -49,6 +49,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 0961b4d..7f0ea83 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 fcf3bc9..6caaffa 100644 --- a/user/nvim/init.lua +++ b/user/nvim/init.lua @@ -25,6 +25,51 @@ 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' }) +-- 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' } }, +} + +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', '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. @@ -34,6 +79,13 @@ vim.keymap.set('n', '<C-p>', function() pick.builtin.files() 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 |
