Configuration for my NixOS based systems and Home Manager
at othinus 176 lines 5.1 kB view raw
1local nvim_lsp = require("lspconfig") 2--######################## 3--#### Set up LSPs #### 4--######################## 5-- 6-- TypeScript 7nvim_lsp.tsserver.setup { 8 flags = { 9 debounce_text_changes = 150 10 } 11} 12 13local util = require("lspconfig.util") 14 15-- Rust 16-- Python LSP 17nvim_lsp.pylsp.setup( 18 { 19 cmd = {"/home/noah/.envs/nvim/bin/pylsp"}, 20 root_dir = function(fname) 21 local root_files = { 22 "pants.toml", 23 "pyproject.toml", 24 "setup.py", 25 "setup.cfg", 26 "Pipfile" 27 } 28 return util.find_git_ancestor(fname) or util.root_pattern(unpack(root_files))(fname) 29 end 30 } 31) 32--nvim_lsp.scheme_langserver.setup{} 33 34-- Golang 35-- Lots of things 36--nvim_lsp.diagnosticls.setup( 37-- { 38-- flags = { 39-- debounce_text_changes = 150 40-- } 41-- } 42--) 43nvim_lsp.lua_ls.setup{ 44 settings = { 45 Lua = { 46 runtime = { 47 -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) 48 version = "LuaJIT" 49 }, 50 diagnostics = { 51 -- Get the language server to recognize the `vim` global 52 globals = {"vim"} 53 }, 54 workspace = { 55 -- Make the server aware of Neovim runtime files 56 library = vim.api.nvim_get_runtime_file("", true) 57 }, 58 -- Do not send telemetry data containing a randomized but unique identifier 59 telemetry = { 60 enable = false 61 } 62 } 63 } 64} 65 66-- LSPs that just use default config 67local simple_lsps = { 68 "fennel_ls", 69 "nil_ls", 70 "htmx", 71 "bzl", 72 "bufls", 73 "crystalline", 74 "dockerls", 75 "erlangls", 76 "elixirls", 77 "fortls", 78 "gleam", 79 "gopls", 80 "hls", 81 "jsonls", 82 "vimls", 83 "asm_lsp", 84 "ccls", 85 "pyright", 86 -- ruff", idk if this is wrong? 87 "ruff_lsp", 88 "clojure_lsp", 89 "guile_ls", 90 -- Of course the Java-based ones are verbose af 91 "kotlin_language_server", 92 "java_language_server", 93 "jsonls", 94 "pest_ls", 95 "ocamllsp", 96 "reason_ls", 97 "racket_langserver", 98 "rust_analyzer", 99 "scheme_langserver", 100 "sqls", 101 "thriftls", 102 "typst_lsp", 103 "vhdl_ls", 104 "yamlls", 105 "zls", 106 "tsserver", 107 "eslint", 108} 109-- #simple_lsps is the length of the table when treated as a list... funky! 110for _,v in pairs(simple_lsps) do 111 nvim_lsp[v].setup{} 112end 113 114-- Whenever an LSP is attached to a buffer 115local on_attach = function(ev) 116 --Enable completion triggered by <c-x><x-o> 117 vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc' 118 119 local opts = {noremap = true, silent = true, buffer = ev.buf} 120 local protocol = require("vim.lsp.protocol") 121 -- Mappings. 122 -- See `:help vim.lsp.*` for documentation on any of the below functions 123 vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts) 124 vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) 125 vim.keymap.set("n", "K", vim.lsp.buf.hover, opts) 126 vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts) 127 vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, opts) 128 vim.keymap.set("n", "<space>wa", vim.lsp.buf.add_workspace_folder, opts) 129 vim.keymap.set("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, opts) 130 vim.keymap.set("n", "<space>wl", function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end, opts) 131 vim.keymap.set("n", "<space>D", vim.lsp.buf.type_definition, opts) 132 vim.keymap.set("n", "<space>rn", vim.lsp.buf.rename, opts) 133 vim.keymap.set("n", "<space>ca", vim.lsp.buf.code_action, opts) 134 vim.keymap.set("n", "gr", vim.lsp.buf.references, opts) 135 vim.keymap.set("n", "<space>e", vim.diagnostic.open_float, opts) 136 vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts) 137 vim.keymap.set("n", "]d", vim.diagnostic.goto_next, opts) 138 vim.keymap.set("n", "<space>q", vim.diagnostic.setloclist, opts) 139 vim.keymap.set("n", "<space>f", function() 140 vim.lsp.buf.format{ async = true } 141 end, opts) 142 vim.keymap.set("n", "<space>s", vim.lsp.buf.workspace_symbol, opts) 143 144 -- require'completion'.on_attach(client, bufnr) 145 protocol.CompletionItemKind = { 146 "", -- Text 147 "", -- Method 148 "𝑓", -- Function 149 "", -- Constructor 150 "", -- Field 151 "", -- Variable 152 "", -- Class 153 "", -- Interface 154 "", -- Module 155 "", -- Property 156 "", -- Unit 157 "", -- Value 158 "", -- Enum 159 "", -- Keyword 160 "", -- Snippet 161 "", -- Color 162 "", -- File 163 "", -- Reference 164 "", -- Folder 165 "", -- EnumMember 166 "", -- Constant 167 "", -- Struct 168 "", -- Event 169 "", -- Operator 170 "" -- TypeParameter 171 } 172end 173vim.api.nvim_create_autocmd('LspAttach', { 174 group = vim.api.nvim_create_augroup('UserLspConfig', {}), 175 callback = on_attach 176})