# This file provides a configured neovim for debugging the LSP. # Run `nvim` inside the shell to test. # Env vars: # - `NIL_PATH`: The path to "nil" LSP binary. Default: `target/debug/nil` # - `NIL_LOG_PATH`: Where to redirect LSP's stderr. Default: `/tmp/nil.log` { pkgs ? import { } }: let neovim = pkgs.neovim.override { withPython = false; withRuby = false; configure = { customRC = '' lua <'] = cmp.mapping.select_prev_item(), [''] = cmp.mapping.select_next_item(), [''] = cmp.mapping.complete(), [''] = cmp.mapping.close(), [''] = cmp.mapping.confirm { select = true }, }, sources = cmp.config.sources({ { name = 'nvim_lsp' }, { name = 'luasnip' }, }), } local lsp_mappings = { { 'gD', 'vim.lsp.buf.declaration()' }, { 'gd', 'vim.lsp.buf.definition()' }, { 'gi', 'vim.lsp.buf.implementation()' }, { 'gr', 'vim.lsp.buf.references()' }, { '[d', 'vim.diagnostic.goto_prev()' }, { ']d', 'vim.diagnostic.goto_next()' }, { '', 'vim.lsp.buf.hover()' }, { 's', 'vim.lsp.buf.signature_help()' }, { 'r', 'vim.lsp.buf.rename()' }, { 'a', 'vim.lsp.buf.code_action()' }, { 'd', 'vim.diagnostic.open_float()' }, { 'q', 'vim.diagnostic.setloclist()' }, } for i, lr in pairs(lsp_mappings) do vim.api.nvim_set_keymap('n', lr[1], 'lua ' .. lr[2] .. '', { noremap = true, silent = true }) end -- https://github.com/neovim/nvim-lspconfig/wiki/Autocompletion local caps = vim.lsp.protocol.make_client_capabilities() caps = require('cmp_nvim_lsp').update_capabilities(caps) local lsp_path = vim.env.NIL_PATH or 'target/debug/nil' local log_path = vim.env.NIL_LOG_PATH or '/tmp/nil.log' require('lspconfig').rnix.setup { autostart = true, capabilities = caps, cmd = { '${pkgs.bash}/bin/bash', '-c', vim.fn.shellescape(lsp_path) .. ' 2>>' .. vim.fn.shellescape(log_path), }, } ''; in pkgs.mkShell { packages = [ neovim ]; }