my neovim config, who would've thought

migrate to nvim 0.11 lsp (#3)

* refactor: remove lspconfig, use lsp.config

* feat(lsp): setup servers

* refactor(null-ls): remove what stuff that dont get used

* fix: remove lspconfig from deps

* refactor(lsp): use universal root_markers and extend from them when needed

* refactor(lsp): change the place where LspAttach is set

* resort

* fixup! refactor(lsp): use universal root_markers and extend from them when needed

* feat(lsp): add util for capabilities extensions

* fixup! feat(lsp): add util for capabilities extensions

* feat(git): load diffview on its command

* feat: add config for ledger files

* refactor: fix utils

authored by olexsmir.xyz and committed by GitHub 511b2851 83e9ecd0

+3
after/ftplugin/ledger.lua
··· 1 + vim.opt_local.foldmethod = "marker" 2 + vim.opt_local.ts = 2 3 + vim.opt_local.sw = 2
+1
init.lua
··· 2 2 require "core.lazy" 3 3 require "core.keymaps" 4 4 require "core.autocmd" 5 + require "core.lsp" 5 6 require "hidden"
+21
lsp/golangci_lint_ls.lua
··· 1 + local u = require("core.utils").lsp 2 + 3 + ---@return vim.lsp.Config 4 + return { 5 + cmd = { "golangci-lint-langserver" }, 6 + filetypes = { "go", "gomod" }, 7 + init_options = { 8 + command = { 9 + "golangci-lint", 10 + "run", 11 + "--output.json.path=stdout", 12 + "--show-stats=false", 13 + }, 14 + }, 15 + root_markers = u.root_marker { 16 + ".golangci.yml", 17 + ".golangci.yaml", 18 + ".golangci.toml", 19 + ".golangci.json", 20 + }, 21 + }
+43
lsp/gopls.lua
··· 1 + local u = require("core.utils").lsp 2 + 3 + ---@return vim.lsp.Config 4 + return { 5 + cmd = { "gopls" }, 6 + filetypes = { "go", "gomod", "gowork", "gotmpl" }, 7 + root_markers = u.root_marker { 8 + "go.mod", 9 + "go.work", 10 + }, 11 + settings = { 12 + gopls = { 13 + linksInHover = false, 14 + staticcheck = true, 15 + gofumpt = true, 16 + analyses = { 17 + unusedparams = true, 18 + unreachable = true, 19 + unusedwrite = true, 20 + useany = true, 21 + shadow = true, 22 + nilness = true, 23 + }, 24 + hints = { 25 + assignVariableTypes = true, 26 + compositeLiteralFields = true, 27 + compositeLiteralTypes = true, 28 + constantValues = true, 29 + functionTypeParameters = false, 30 + parameterNames = true, 31 + rangeVariableTypes = true, 32 + }, 33 + codelenses = { 34 + generate = true, 35 + gc_details = false, 36 + test = true, 37 + tidy = true, 38 + run_govulncheck = true, 39 + upgrade_dependency = true, 40 + }, 41 + }, 42 + }, 43 + }
+14
lsp/jsonls.lua
··· 1 + ---@return vim.lsp.Config 2 + return { 3 + cmd = { "vscode-json-language-server", "--stdio" }, 4 + filetypes = { "json", "jsonc" }, 5 + init_options = { 6 + provideFormatter = true, 7 + }, 8 + settings = { 9 + json = { 10 + schemas = require("schemastore").json.schemas(), 11 + validate = { enable = true }, 12 + }, 13 + }, 14 + }
+31
lsp/lua_ls.lua
··· 1 + ---@return vim.lsp.Config 2 + return { 3 + cmd = { "lua-language-server" }, 4 + filetypes = { "lua" }, 5 + root_markers = { 6 + ".luarc.json", 7 + ".luarc.jsonc", 8 + ".luacheckrc", 9 + ".stylua.toml", 10 + "stylua.toml", 11 + "selene.toml", 12 + "selene.yml", 13 + ".git", 14 + }, 15 + settings = { 16 + Lua = { 17 + format = { enable = false }, 18 + completion = { callSnippet = "Replace" }, 19 + telemetry = { enable = false }, 20 + hint = { 21 + enable = true, 22 + arrayIndex = "Disable", 23 + await = true, 24 + paramName = "Disable", 25 + paramType = false, 26 + semicolon = "Disable", 27 + setType = true, 28 + }, 29 + }, 30 + }, 31 + }
+15
lsp/markdown_oxide.lua
··· 1 + local u = require("core.utils").lsp 2 + 3 + ---@return vim.lsp.Config 4 + return { 5 + cmd = { "markdown-oxide" }, 6 + filetypes = { "markdown" }, 7 + root_markers = { ".git", ".obsidian", ".moxide.toml" }, 8 + capabilities = u.capabilities { 9 + workspace = { 10 + didChangeWatchedFiles = { 11 + dynamicRegistration = true, 12 + }, 13 + }, 14 + }, 15 + }
+12
lsp/yamlls.lua
··· 1 + ---@return vim.lsp.Config 2 + return { 3 + cmd = { "yaml-language-server", "--stdio" }, 4 + filetypes = { "yaml", "yaml.docker-compose", "yaml.gitlab" }, 5 + settings = { 6 + redhat = { telemetry = { enabled = false } }, 7 + yaml = { 8 + schemaStore = { enable = false, url = "" }, 9 + schemas = require("schemastore").yaml.schemas(), 10 + }, 11 + }, 12 + }
+31
lua/core/utils.lua
··· 1 + local lsp_root_markers = { ".git" } 2 + 1 3 return { 2 4 ---@param mode string|table 3 5 ---@param from string ··· 12 14 end, 13 15 14 16 aucmd = vim.api.nvim_create_autocmd, 17 + 18 + ---@param name string 19 + ---@return integer 15 20 augroup = function(name) 16 21 return vim.api.nvim_create_augroup("olexsmir_" .. name, { clear = true }) 17 22 end, 23 + 24 + lsp = { 25 + default_markers = lsp_root_markers, 26 + 27 + ---@param extend? string[] 28 + root_marker = function(extend) 29 + if extend == nil then 30 + return lsp_root_markers 31 + end 32 + 33 + local r = vim.deepcopy(lsp_root_markers) 34 + for _, v in ipairs(extend) do 35 + table.insert(r, v) 36 + end 37 + return r 38 + end, 39 + 40 + ---@param extend? table 41 + capabilities = function(extend) 42 + return vim.tbl_extend( 43 + "force", 44 + vim.lsp.protocol.make_client_capabilities(), 45 + extend or {} 46 + ) 47 + end, 48 + }, 18 49 }
+3 -1
lua/plugins/git.lua
··· 47 47 keys = { { "<leader>gg", vim.cmd.Neogit } }, 48 48 ---@module "neogit" 49 49 ---@type NeogitConfig 50 - dependencies = { "sindrets/diffview.nvim" }, 50 + dependencies = { 51 + { "sindrets/diffview.nvim", cmd = "DiffviewOpen" }, 52 + }, 51 53 opts = { 52 54 kind = "vsplit", 53 55 console_timeout = 8000,
+14
lua/plugins/lsp/attach.lua lua/core/lsp.lua
··· 1 1 local u = require "core.utils" 2 2 3 + vim.lsp.config("*", { 4 + root_markers = u.lsp.default_markers, 5 + flags = { debounce_text_changes = 150 }, 6 + }) 7 + 8 + vim.lsp.enable { 9 + "golangci_lint_ls", 10 + "gopls", 11 + "jsonls", 12 + "lua_ls", 13 + "markdown_oxide", 14 + "yamlls", 15 + } 16 + 3 17 u.aucmd("LspAttach", { 4 18 group = u.augroup "lsp", 5 19 callback = function(args)
+47 -50
lua/plugins/lsp/init.lua
··· 1 1 ---@type LazySpec 2 2 return { 3 - "neovim/nvim-lspconfig", 4 - event = "BufRead", 5 - dependencies = { 6 - "b0o/schemastore.nvim", 7 - { import = "plugins.lsp.lazydev" }, 8 - { import = "plugins.lsp.null-ls" }, 9 - { 10 - "j-hui/fidget.nvim", 11 - dependencies = { "nvim-lspconfig" }, 12 - opts = { 13 - progress = { 14 - display = { 15 - render_limit = 2, 16 - done_ttl = 2, 17 - }, 3 + "b0o/schemastore.nvim", 4 + { import = "plugins.lsp.lazydev" }, 5 + { import = "plugins.lsp.null-ls" }, 6 + 7 + { 8 + "j-hui/fidget.nvim", 9 + event = { "BufReadPre", "BufNewFile" }, 10 + opts = { 11 + progress = { 12 + display = { 13 + render_limit = 2, 14 + done_ttl = 2, 18 15 }, 19 16 }, 20 17 }, 21 - { 22 - "nvim-cmp", 23 - dependencies = { "hrsh7th/cmp-nvim-lsp" }, 24 - ---@module "cmp" 25 - ---@param opts cmp.ConfigSchema 26 - opts = function(_, opts) 27 - table.insert(opts.sources, 1, { 28 - name = "nvim_lsp", 29 - group_index = 0, 30 - max_item_count = 12, 31 - }) 32 - end, 18 + }, 19 + 20 + { 21 + "RRethy/vim-illuminate", 22 + event = { "BufReadPre", "BufNewFile" }, 23 + opts = { 24 + providers = { "lsp", "treesitter" }, 25 + filetypes_denylist = { 26 + "NeogitStatus", 27 + "TelescopePrompt", 28 + }, 33 29 }, 34 - { 35 - "RRethy/vim-illuminate", 36 - dependencies = { "nvim-lspconfig" }, 37 - opts = { 38 - providers = { "lsp", "treesitter" }, 39 - filetypes_denylist = { 40 - "NvimTree", 41 - "packer", 42 - "NeogitStatus", 43 - "TelescopePrompt", 44 - }, 30 + config = function(_, opts) 31 + require("illuminate").configure(opts) 32 + end, 33 + }, 34 + 35 + { 36 + "nvim-cmp", 37 + dependencies = { 38 + { 39 + "hrsh7th/cmp-nvim-lsp", 40 + config = function() 41 + vim.lsp.config("*", { 42 + capabilities = require("cmp_nvim_lsp").default_capabilities(), 43 + }) 44 + end, 45 45 }, 46 - config = function(_, opts) 47 - require("illuminate").configure(opts) 48 - end, 49 46 }, 47 + ---@module "cmp" 48 + ---@param opts cmp.ConfigSchema 49 + opts = function(_, opts) 50 + table.insert(opts.sources, 1, { 51 + name = "nvim_lsp", 52 + group_index = 0, 53 + max_item_count = 12, 54 + }) 55 + end, 50 56 }, 51 - config = function() 52 - for name, conf in pairs(require "plugins.lsp.servers") do 53 - require "plugins.lsp.attach" 54 - require("lspconfig")[name].setup(vim.tbl_extend("force", { 55 - flags = { debounce_text_changes = 150 }, 56 - capabilities = require("cmp_nvim_lsp").default_capabilities(), 57 - }, conf)) 58 - end 59 - end, 60 57 }
-1
lua/plugins/lsp/lazydev.lua
··· 4 4 ft = "lua", 5 5 cmd = "LazyDev", 6 6 dependencies = { 7 - "nvim-lspconfig", 8 7 { 9 8 "nvim-cmp", 10 9 ---@module "cmp"
+2 -8
lua/plugins/lsp/null-ls.lua
··· 1 1 ---@type LazySpec 2 2 return { 3 3 "nvimtools/none-ls.nvim", 4 - dependencies = { "nvim-lspconfig" }, 4 + event = { "BufReadPre", "BufNewFile" }, 5 5 config = function() 6 6 local null_ls = require "null-ls" 7 7 local formatting = null_ls.builtins.formatting ··· 9 9 10 10 null_ls.setup { 11 11 sources = { 12 + formatting.pg_format, 12 13 diagnostic.codespell.with { 13 14 args = { 14 15 "--ignore-words", ··· 26 27 27 28 formatting.goimports, 28 29 formatting.golines, 29 - 30 - formatting.clang_format, 31 - formatting.pg_format, 32 - formatting.prettierd.with { 33 - -- stylua: ignore 34 - filetypes = { "javascript", "javascriptreact", "typescript", "typescriptreact", "vue", "html", "json", "jsonc", "svelte", "astro" }, 35 - }, 36 30 }, 37 31 } 38 32 end,
-96
lua/plugins/lsp/servers.lua
··· 1 - return { 2 - clangd = {}, 3 - eslint = {}, 4 - html = {}, 5 - gleam = {}, 6 - templ = {}, 7 - bashls = {}, 8 - gopls = { 9 - settings = { 10 - gopls = { 11 - linksInHover = false, 12 - staticcheck = true, 13 - gofumpt = true, 14 - analyses = { 15 - unusedparams = true, 16 - unreachable = true, 17 - unusedwrite = true, 18 - useany = true, 19 - shadow = true, 20 - nilness = true, 21 - }, 22 - hints = { 23 - assignVariableTypes = true, 24 - compositeLiteralFields = true, 25 - compositeLiteralTypes = true, 26 - constantValues = true, 27 - functionTypeParameters = false, 28 - parameterNames = true, 29 - rangeVariableTypes = true, 30 - }, 31 - codelenses = { 32 - generate = true, 33 - gc_details = false, 34 - test = true, 35 - tidy = true, 36 - run_govulncheck = true, 37 - upgrade_dependency = true, 38 - }, 39 - }, 40 - }, 41 - }, 42 - golangci_lint_ls = { 43 - init_options = { 44 - command = { 45 - "golangci-lint", 46 - "run", 47 - "--output.json.path=stdout", 48 - "--show-stats=false", 49 - "--issues-exit-code=1", 50 - }, 51 - }, 52 - }, 53 - lua_ls = { 54 - settings = { 55 - Lua = { 56 - format = { enable = false }, 57 - completion = { callSnippet = "Replace" }, 58 - telemetry = { enable = false }, 59 - hint = { 60 - enable = true, 61 - arrayIndex = "Disable", 62 - await = true, 63 - paramName = "Disable", 64 - paramType = false, 65 - semicolon = "Disable", 66 - setType = true, 67 - }, 68 - }, 69 - }, 70 - }, 71 - markdown_oxide = { 72 - capabilities = { 73 - workspace = { 74 - didChangeWatchedFiles = { 75 - dynamicRegistration = true, 76 - }, 77 - }, 78 - }, 79 - }, 80 - yamlls = { 81 - settings = { 82 - yaml = { 83 - schemaStore = { enable = false, url = "" }, 84 - schemas = require("schemastore").yaml.schemas(), 85 - }, 86 - }, 87 - }, 88 - jsonls = { 89 - settings = { 90 - json = { 91 - schemas = require("schemastore").json.schemas(), 92 - validate = { enable = true }, 93 - }, 94 - }, 95 - }, 96 - }