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