From e13d618a98d0ea5afb559f2b18e150b4d5b0755f Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 23 Jan 2025 23:18:49 +0100 Subject: [PATCH] feat!: Remove mason Mason is really awesome and it just works. However, I want my "real" package manager give back more control (and of course reduce my plugin count for no reason) --- lua/vnext/plugins/lsp.lua | 305 ++++++++++++++++---------------------- 1 file changed, 127 insertions(+), 178 deletions(-) diff --git a/lua/vnext/plugins/lsp.lua b/lua/vnext/plugins/lsp.lua index 25d598b3..b8fbfda4 100644 --- a/lua/vnext/plugins/lsp.lua +++ b/lua/vnext/plugins/lsp.lua @@ -1,161 +1,131 @@ -local servers = { - bashls = {}, - dockerls = {}, - gopls = { - settings = { - gofumpt = true, - codelenses = { - gc_details = false, - generate = true, - regenerate_cgo = true, - run_govulncheck = true, - test = true, - tidy = true, - upgrade_dependency = true, - vendor = true, - }, - hints = { - assignVariableTypes = true, - compositeLiteralFields = true, - compositeLiteralTypes = true, - constantValues = true, - functionTypeParameters = true, - parameterNames = true, - rangeVariableTypes = true, - }, - analyses = { - fieldalignment = true, - nilness = true, - unusedparams = true, - unusedwrite = true, - useany = true, - }, - usePlaceholders = true, - completeUnimported = true, - staticcheck = true, - directoryFilters = { "-.git", "-.vscode", "-.idea", "-.vscode-test", "-node_modules" }, - semanticTokens = true, - }, - }, - lua_ls = { - -- cmd = { ... }, - -- filetypes = { ... }, - -- capabilities = {}, - settings = { - format = { - enable = false, -- let conform handle the formatting - }, - diagnostics = { globals = { "vim" } }, - telemetry = { enable = false }, - hint = { enable = true }, - Lua = { - workspace = { - checkThirdParty = false, - }, - codeLens = { - enable = true, - }, - doc = { - privateName = { "^_" }, - }, - hint = { - enable = true, - setType = false, - paramType = true, - paramName = "Disable", - semicolon = "Disable", - arrayIndex = "Disable", - }, - completion = { - callSnippet = "Replace", - }, - -- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings - -- diagnostics = { disable = { 'missing-fields' } }, - }, - }, - }, - marksman = {}, - pyright = {}, - terraformls = {}, - tinymist = {}, - yamlls = { - capabilities = { - textDocument = { - foldingRange = { - dynamicRegistration = false, - lineFoldingOnly = true, +return { + { + "neovim/nvim-lspconfig", + event = { "BufReadPre", "BufNewFile" }, + opts = { + servers = { + bashls = {}, + dockerls = {}, + gopls = { + settings = { + gofumpt = true, + codelenses = { + gc_details = false, + generate = true, + regenerate_cgo = true, + run_govulncheck = true, + test = true, + tidy = true, + upgrade_dependency = true, + vendor = true, + }, + hints = { + assignVariableTypes = true, + compositeLiteralFields = true, + compositeLiteralTypes = true, + constantValues = true, + functionTypeParameters = true, + parameterNames = true, + rangeVariableTypes = true, + }, + analyses = { + fieldalignment = true, + nilness = true, + unusedparams = true, + unusedwrite = true, + useany = true, + }, + usePlaceholders = true, + completeUnimported = true, + staticcheck = true, + directoryFilters = { "-.git", "-.vscode", "-.idea", "-.vscode-test", "-node_modules" }, + semanticTokens = true, + }, }, - }, - }, - settings = { - redhat = { telemetry = { enabled = false } }, - yaml = { - schemaStore = { - enable = true, - url = "https://www.schemastore.org/api/json/catalog.json", + lua_ls = { + -- cmd = { ... }, + -- filetypes = { ... }, + -- capabilities = {}, + settings = { + format = { + enable = false, -- let conform handle the formatting + }, + diagnostics = { globals = { "vim" } }, + telemetry = { enable = false }, + hint = { enable = true }, + Lua = { + workspace = { + checkThirdParty = false, + }, + codeLens = { + enable = true, + }, + doc = { + privateName = { "^_" }, + }, + hint = { + enable = true, + setType = false, + paramType = true, + paramName = "Disable", + semicolon = "Disable", + arrayIndex = "Disable", + }, + completion = { + callSnippet = "Replace", + }, + -- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings + -- diagnostics = { disable = { 'missing-fields' } }, + }, + }, }, - format = { enabled = false }, - -- enabling this conflicts between Kubernetes resources, kustomization.yaml, and Helmreleases - validate = false, - schemas = { - kubernetes = "*.yaml", - ["http://json.schemastore.org/github-workflow"] = ".github/workflows/*", - ["http://json.schemastore.org/github-action"] = ".github/action.{yml,yaml}", - ["https://raw.githubusercontent.com/microsoft/azure-pipelines-vscode/master/service-schema.json"] = "azure-pipelines*.{yml,yaml}", - ["https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/ansible.json#/$defs/tasks"] = "roles/tasks/*.{yml,yaml}", - ["https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/ansible.json#/$defs/playbook"] = "*play*.{yml,yaml}", - ["http://json.schemastore.org/prettierrc"] = ".prettierrc.{yml,yaml}", - ["http://json.schemastore.org/kustomization"] = "kustomization.{yml,yaml}", - ["http://json.schemastore.org/chart"] = "Chart.{yml,yaml}", - ["https://json.schemastore.org/dependabot-v2"] = ".github/dependabot.{yml,yaml}", - ["https://gitlab.com/gitlab-org/gitlab/-/raw/master/app/assets/javascripts/editor/schema/ci.json"] = "*gitlab-ci*.{yml,yaml}", - ["https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/schemas/v3.1/schema.json"] = "*api*.{yml,yaml}", - ["https://raw.githubusercontent.com/compose-spec/compose-spec/master/schema/compose-spec.json"] = "*docker-compose*.{yml,yaml}", - ["https://raw.githubusercontent.com/argoproj/argo-workflows/master/api/jsonschema/schema.json"] = "*flow*.{yml,yaml}", + marksman = {}, + pyright = {}, + terraformls = {}, + tinymist = {}, + yamlls = { + capabilities = { + textDocument = { + foldingRange = { + dynamicRegistration = false, + lineFoldingOnly = true, + }, + }, + }, + settings = { + redhat = { telemetry = { enabled = false } }, + yaml = { + schemaStore = { + enable = true, + url = "https://www.schemastore.org/api/json/catalog.json", + }, + format = { enabled = false }, + -- enabling this conflicts between Kubernetes resources, kustomization.yaml, and Helmreleases + validate = false, + schemas = { + kubernetes = "*.yaml", + ["http://json.schemastore.org/github-workflow"] = ".github/workflows/*", + ["http://json.schemastore.org/github-action"] = ".github/action.{yml,yaml}", + ["https://raw.githubusercontent.com/microsoft/azure-pipelines-vscode/master/service-schema.json"] = "azure-pipelines*.{yml,yaml}", + ["https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/ansible.json#/$defs/tasks"] = "roles/tasks/*.{yml,yaml}", + ["https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/ansible.json#/$defs/playbook"] = "*play*.{yml,yaml}", + ["http://json.schemastore.org/prettierrc"] = ".prettierrc.{yml,yaml}", + ["http://json.schemastore.org/kustomization"] = "kustomization.{yml,yaml}", + ["http://json.schemastore.org/chart"] = "Chart.{yml,yaml}", + ["https://json.schemastore.org/dependabot-v2"] = ".github/dependabot.{yml,yaml}", + ["https://gitlab.com/gitlab-org/gitlab/-/raw/master/app/assets/javascripts/editor/schema/ci.json"] = "*gitlab-ci*.{yml,yaml}", + ["https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/schemas/v3.1/schema.json"] = "*api*.{yml,yaml}", + ["https://raw.githubusercontent.com/compose-spec/compose-spec/master/schema/compose-spec.json"] = "*docker-compose*.{yml,yaml}", + ["https://raw.githubusercontent.com/argoproj/argo-workflows/master/api/jsonschema/schema.json"] = "*flow*.{yml,yaml}", + }, + }, + }, }, }, }, - }, -} -local tools = { - "debugpy", - "delve", - "gofumpt", - "goimports", - "golangci-lint", - "gomodifytags", - "gotests", - "hadolint", - "iferr", - "impl", - "isort", - "markdownlint-cli2", - "prettier", - "ruff", - "selene", - "shellcheck", - "shfmt", - "stylua", - "taplo", - "tflint", - "typstfmt", - "yamllint", -} - --- TODO: Maybe replace Mason with "pure" nvim-lspconfig -return { - - { "williamboman/mason.nvim", config = true, lazy = true }, -- NOTE: Must be loaded before dependants - { "williamboman/mason-lspconfig.nvim", lazy = true }, - { "WhoIsSethDaniel/mason-tool-installer.nvim", lazy = true }, - - { - "neovim/nvim-lspconfig", - event = { "BufReadPre", "BufNewFile" }, -- BUG: Prevents new tools from being installed! - config = function() - -- function will be executed to configure the current buffer + config = function(_, opts) vim.api.nvim_create_autocmd("LspAttach", { - group = vim.api.nvim_create_augroup("kickstart-lsp-attach", { clear = true }), + group = vim.api.nvim_create_augroup("lsp-attach", { clear = true }), callback = function(event) local map = function(keys, func, desc, mode) mode = mode or "n" @@ -198,34 +168,13 @@ return { end, }) - local signs = { ERROR = "", WARN = "", INFO = "", HINT = "" } - local diagnostic_signs = {} - for type, icon in pairs(signs) do - diagnostic_signs[vim.diagnostic.severity[type]] = icon - end - vim.diagnostic.config({ signs = { text = diagnostic_signs } }) - + local lspconfig = require("lspconfig") local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities = vim.tbl_deep_extend("force", capabilities, require("blink.cmp").get_lsp_capabilities()) - - require("mason").setup() - - local ensure_installed = vim.tbl_keys(servers) - vim.list_extend(ensure_installed, tools) - require("mason-tool-installer").setup({ ensure_installed = ensure_installed }) - - require("mason-lspconfig").setup({ - handlers = { - function(server_name) - local server = servers[server_name] or {} - -- This handles overriding only values explicitly passed - -- by the server configuration above. Useful when disabling - -- certain features of an LSP (for example, turning off formatting for ts_ls) - server.capabilities = vim.tbl_deep_extend("force", {}, capabilities, server.capabilities or {}) - require("lspconfig")[server_name].setup(server) - end, - }, - }) + for server, server_opts in pairs(opts.servers) do + server_opts.capabilities = vim.tbl_deep_extend("force", {}, capabilities, server_opts.capabilities or {}) + lspconfig[server].setup(server_opts) + end end, }, }