diff options
| author | Alec Goncharow <algo@cloudflare.com> | 2023-02-24 23:20:34 -0600 |
|---|---|---|
| committer | Alec Goncharow <algo@cloudflare.com> | 2023-02-24 23:20:34 -0600 |
| commit | 0c446121ba1f1653a0d984068209429e8cc453fb (patch) | |
| tree | bc04e8bb2a985e5cb4f7b15c1e4d8962b2c4b000 /.config/nvim/lua/lsp.lua | |
| parent | d3aeb8f7d8d9b4352e7b827a361d1da11cb6cf04 (diff) | |
out of the frying pan
into the fire
Diffstat (limited to '.config/nvim/lua/lsp.lua')
| -rw-r--r-- | .config/nvim/lua/lsp.lua | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/.config/nvim/lua/lsp.lua b/.config/nvim/lua/lsp.lua new file mode 100644 index 0000000..65eaedc --- /dev/null +++ b/.config/nvim/lua/lsp.lua @@ -0,0 +1,47 @@ +-- See `:help vim.diagnostic.*` for documentation on any of the below functions +local opts = { noremap=true, silent=true } +vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts) +vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts) +vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts) +vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts) + +-- Use an on_attach function to only map the following keys +-- after the language server attaches to the current buffer +local on_attach = function(client, bufnr) + -- Enable completion triggered by <c-x><c-o> + vim.api.nvim_buf_set_option(bufnr, "formatexpr", "v:lua.vim.lsp.formatexpr()") + vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc") + vim.api.nvim_buf_set_option(bufnr, "tagfunc", "v:lua.vim.lsp.tagfunc") + + -- Mappings. + -- See `:help vim.lsp.*` for documentation on any of the below functions + local bufopts = { noremap=true, silent=true, buffer=bufnr } + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts) + vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts) + vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, bufopts) + vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, bufopts) + vim.keymap.set('n', '<space>wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, bufopts) + vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts) + vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts) + vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) + vim.keymap.set('n', '<space>f', function() vim.lsp.buf.format { async = true } end, bufopts) +end +-- Setup buffer-local keymaps / options for LSP buffers +local capabilities = require("cmp_nvim_lsp").default_capabilities() +-- Setup rust_analyzer via rust-tools.nvim +require("rust-tools").setup({ + server = { + capabilities = capabilities, + on_attach = on_attach, + } +}) + + +-- local autocmd = vim.api.nvim_create_autocmd +-- autocmd({ "BufLeave" }, { pattern = { "*" }, command = "if &buftype == 'quickfix'|q|endif" }) |
