dotfiles

My current dotfiles, managed with stow!
Log | Files | Refs | README

lsp.lua (3378B)


      1 -- Uncomment this for a broken implementation of format on save! :(
      2 --local format = vim.api.nvim_create_augroup("LSPFormat", { clear = true })
      3 --vim.api.nvim_create_autocmd("BufWritePre", {
      4 --command = ":lua vim.lsp.buf.format()",
      5 --group = format,
      6 --buffer = 0,
      7 --})
      8 
      9 -- Mappings
     10 local opts = { noremap = true, silent = true }
     11 
     12 -- Open detail about a diagnostic
     13 vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, opts)
     14 -- Go to the previous or next diagnostic
     15 vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
     16 vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
     17 -- Create a list of diagnostics for the current buffer
     18 -- This is pretty cool! It makes a new buffer which contains the list, and you
     19 -- can goto each diagnostic by pressing enter on it!
     20 vim.keymap.set('n', '<leader><leader>e', vim.diagnostic.setloclist, opts)
     21 
     22 -- Only do this stuff once a language server has been attached
     23 local on_attach = function(_, bufnr)
     24     -- Enable insert mode autocompletion with <C-x><C-o> (:h 'omnifunc')
     25     vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
     26 
     27     local bufopts = { noremap = true, silent = true, buffer = bufnr }
     28 
     29     -- Format the current file using the formatter provided with the language
     30     -- server
     31     vim.keymap.set('n', '<leader><leader>f', vim.lsp.buf.format, bufopts)
     32     -- Show information about the symbol under the cursor in a floating windor.
     33     -- Call twice to move into the floating window.
     34     vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts)
     35     -- Jump to definitions
     36     vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
     37     vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
     38     vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
     39     vim.keymap.set('n', '<leader>d', vim.lsp.buf.type_definition, bufopts)
     40     -- List all references of the symbol under the cursor
     41     vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
     42     -- Rename something
     43     vim.keymap.set('n', '<leader><leader>r', vim.lsp.buf.rename, bufopts)
     44     -- Run a code action (very cool) with telescope i think somehow
     45     vim.keymap.set('n', '<leader><leader>c', vim.lsp.buf.code_action, bufopts)
     46 end
     47 
     48 -- Servers
     49 require 'lspconfig'.ccls.setup {
     50     on_attach = on_attach,
     51 }
     52 require 'lspconfig'.hls.setup {
     53     on_attach = on_attach,
     54 }
     55 require 'lspconfig'.texlab.setup {
     56     on_attach = on_attach,
     57 }
     58 require 'lspconfig'.typst_lsp.setup {
     59     on_attach = on_attach,
     60     settings = {
     61         --exportPdf = "onType"
     62     }
     63 }
     64 require 'lspconfig'.lua_ls.setup {
     65     on_attach = on_attach,
     66     settings = {
     67         Lua = {
     68             runtime = {
     69                 version = "LuaJIT",
     70             },
     71             diagnostics = {
     72                 globals = { 'vim' },
     73             },
     74             workspace = {
     75                 library = vim.api.nvim_get_runtime_file("", true),
     76             },
     77             telemetry = {
     78                 enabled = false,
     79             },
     80         }
     81     }
     82 }
     83 require 'rust-tools'.setup({
     84     server = {
     85         on_attach = on_attach,
     86         settings = {
     87             ["rust-analyzer"] = {
     88                 checkOnSave = {
     89                     allTargets = false,
     90                 },
     91                 inlayHints = { locationLinks = false },
     92             }
     93         }
     94     }
     95 })
     96 require 'zk'.setup({
     97     lsp = {
     98         config = {
     99             on_attach = on_attach,
    100         }
    101     }
    102 })