local nvim_lsp = require("lspconfig") --######################## --#### Set up LSPs #### --######################## -- -- TypeScript nvim_lsp.tsserver.setup { flags = { debounce_text_changes = 150 } } local util = require("lspconfig.util") -- Rust -- Python LSP nvim_lsp.pylsp.setup( { cmd = {"/home/noah/.envs/nvim/bin/pylsp"}, root_dir = function(fname) local root_files = { "pants.toml", "pyproject.toml", "setup.py", "setup.cfg", "Pipfile" } return util.find_git_ancestor(fname) or util.root_pattern(unpack(root_files))(fname) end } ) --nvim_lsp.scheme_langserver.setup{} -- Golang -- Lots of things --nvim_lsp.diagnosticls.setup( -- { -- flags = { -- debounce_text_changes = 150 -- } -- } --) nvim_lsp.lua_ls.setup{ settings = { Lua = { runtime = { -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) version = "LuaJIT" }, diagnostics = { -- Get the language server to recognize the `vim` global globals = {"vim"} }, workspace = { -- Make the server aware of Neovim runtime files library = vim.api.nvim_get_runtime_file("", true) }, -- Do not send telemetry data containing a randomized but unique identifier telemetry = { enable = false } } } } -- LSPs that just use default config local simple_lsps = { "fennel_ls", "nil_ls", "htmx", "bzl", "bufls", "crystalline", "dockerls", "erlangls", "elixirls", "fortls", "gleam", "gopls", "hls", "jsonls", "vimls", "asm_lsp", "ccls", "pyright", -- ruff", idk if this is wrong? "ruff_lsp", "clojure_lsp", "guile_ls", -- Of course the Java-based ones are verbose af "kotlin_language_server", "java_language_server", "jsonls", "pest_ls", "ocamllsp", "reason_ls", "racket_langserver", "rust_analyzer", "scheme_langserver", "sqls", "thriftls", "typst_lsp", "vhdl_ls", "yamlls", "zls", "tsserver", "eslint", } -- #simple_lsps is the length of the table when treated as a list... funky! for _,v in pairs(simple_lsps) do nvim_lsp[v].setup{} end -- Whenever an LSP is attached to a buffer local on_attach = function(ev) --Enable completion triggered by vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc' local opts = {noremap = true, silent = true, buffer = ev.buf} local protocol = require("vim.lsp.protocol") -- Mappings. -- See `:help vim.lsp.*` for documentation on any of the below functions vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts) vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) vim.keymap.set("n", "K", vim.lsp.buf.hover, opts) vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts) vim.keymap.set("n", "", vim.lsp.buf.signature_help, opts) vim.keymap.set("n", "wa", vim.lsp.buf.add_workspace_folder, opts) vim.keymap.set("n", "wr", vim.lsp.buf.remove_workspace_folder, opts) vim.keymap.set("n", "wl", function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end, opts) vim.keymap.set("n", "D", vim.lsp.buf.type_definition, opts) vim.keymap.set("n", "rn", vim.lsp.buf.rename, opts) vim.keymap.set("n", "ca", vim.lsp.buf.code_action, opts) vim.keymap.set("n", "gr", vim.lsp.buf.references, opts) vim.keymap.set("n", "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", "q", vim.diagnostic.setloclist, opts) vim.keymap.set("n", "f", function() vim.lsp.buf.format{ async = true } end, opts) vim.keymap.set("n", "s", vim.lsp.buf.workspace_symbol, opts) -- require'completion'.on_attach(client, bufnr) protocol.CompletionItemKind = { "", -- Text "⋙", -- Method "𝑓", -- Function "", -- Constructor "", -- Field "", -- Variable "", -- Class "ﰮ", -- Interface "", -- Module "", -- Property "", -- Unit "", -- Value "", -- Enum "", -- Keyword "﬌", -- Snippet "", -- Color "", -- File "", -- Reference "", -- Folder "", -- EnumMember "", -- Constant "", -- Struct "", -- Event "ﬦ", -- Operator "" -- TypeParameter } end vim.api.nvim_create_autocmd('LspAttach', { group = vim.api.nvim_create_augroup('UserLspConfig', {}), callback = on_attach })