From e6d153527210a293e2dc805cfd5af6bb73f7755e Mon Sep 17 00:00:00 2001 From: eleith Date: Sun, 6 Aug 2023 15:44:46 +0000 Subject: [PATCH] [nvim] replace null-ls with efm-langserver --- config/fish/functions/fish_title.fish | 14 +- config/nvim/lua/plugins/cmp.lua | 4 +- config/nvim/lua/plugins/lsp.lua | 289 ++++++++++++------- config/nvim/lua/plugins/null-ls.lua | 397 -------------------------- 4 files changed, 188 insertions(+), 516 deletions(-) delete mode 100644 config/nvim/lua/plugins/null-ls.lua diff --git a/config/fish/functions/fish_title.fish b/config/fish/functions/fish_title.fish index 0225d42..690c8ae 100644 --- a/config/fish/functions/fish_title.fish +++ b/config/fish/functions/fish_title.fish @@ -12,14 +12,14 @@ function fish_title --argument-names last_cmd if [ fish != $_ ] switch $_ case vi vim nvim - set last_path (string split ' ' $last_cmd)[2..] + set last_path (string split ' ' $last_cmd)[2..] - if test -n "$last_path" - and test -f "$last_path" - echo "$prefix$_ $(path basename $last_path)" - else - echo "$prefix$last_cmd" - end + if test -n "$last_path" + and test -f "$last_path" + echo "$prefix$_ $(path basename $last_path)" + else + echo "$prefix$last_cmd" + end case '*' echo "$prefix$last_cmd" end diff --git a/config/nvim/lua/plugins/cmp.lua b/config/nvim/lua/plugins/cmp.lua index 3f8da36..df2ab47 100644 --- a/config/nvim/lua/plugins/cmp.lua +++ b/config/nvim/lua/plugins/cmp.lua @@ -41,7 +41,7 @@ return { [""] = cmp.mapping.abort(), [""] = cmp.mapping.confirm({ select = true }), }), - sources = { + sources = cmp.config.sources({ { name = "nvim_lsp" }, { name = "nvim_diagnostic" }, { name = "buffer" }, @@ -50,7 +50,7 @@ return { { name = "nvim_lua" }, { name = "nvim_lsp_signature_help" }, { name = "emoji" }, - }, + }), formatting = { format = lspkind.cmp_format({ mode = "symbol_text", diff --git a/config/nvim/lua/plugins/lsp.lua b/config/nvim/lua/plugins/lsp.lua index 9e84798..93058eb 100644 --- a/config/nvim/lua/plugins/lsp.lua +++ b/config/nvim/lua/plugins/lsp.lua @@ -1,126 +1,195 @@ return { - "neovim/nvim-lspconfig", - dependencies = { - "hrsh7th/nvim-cmp", - }, - config = function() - local lspconfig = require("lspconfig") - local capabilities = vim.lsp.protocol.make_client_capabilities() - local lspwindow = require("lspconfig.ui.windows") + "neovim/nvim-lspconfig", + dependencies = { + "hrsh7th/nvim-cmp", + "creativenull/efmls-configs-nvim", + }, + config = function() + local lspconfig = require("lspconfig") + local capabilities = vim.lsp.protocol.make_client_capabilities() + local lspwindow = require("lspconfig.ui.windows") - capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities) - capabilities.textDocument.completion.completionItem.snippetSupport = true + capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities) + capabilities.textDocument.completion.completionItem.snippetSupport = true - -- disable showing diagnostics in virtual text - vim.diagnostic.config({ virtual_text = false }) + -- disable showing diagnostics in virtual text + vim.diagnostic.config({ virtual_text = false }) - -- close quickfix menu after selecting choice - vim.api.nvim_create_autocmd("FileType", { - pattern = { "qf" }, - command = [[nnoremap :cclose]], - }) + -- close quickfix menu after selecting choice + vim.api.nvim_create_autocmd("FileType", { + pattern = { "qf" }, + command = [[nnoremap :cclose]], + }) - -- override all window borders - local orig_util_open_floating_preview = vim.lsp.util.open_floating_preview - local border = "rounded" + -- override all window borders + local orig_util_open_floating_preview = vim.lsp.util.open_floating_preview + local border = "rounded" - function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...) - opts = opts or {} - opts.border = border - return orig_util_open_floating_preview(contents, syntax, opts, ...) - end + function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...) + opts = opts or {} + opts.border = border + return orig_util_open_floating_preview(contents, syntax, opts, ...) + end - -- lspinfo needs a separate override - lspwindow.default_options = { - border = border, - } + -- lspinfo needs a separate override + lspwindow.default_options = { + border = border, + } - -- LSP settings (for overriding per client) - local handlers = {} - local opts = { noremap = true, silent = true } + -- LSP settings (for overriding per client) + local handlers = {} - local on_attach = function(_, bufnr) - -- Mappings. - local bufopts = { noremap = true, silent = true, buffer = bufnr } + local on_attach = function(_, bufnr) + -- Mappings. + local bufopts = { noremap = true, silent = true, buffer = bufnr } - -- See `:help vim.lsp.*` for more methods - vim.keymap.set("n", "bf", function() - vim.lsp.buf.format({ timeout = 2000, async = true }) - end, bufopts) - end + -- See `:help vim.lsp.*` for more methods + vim.keymap.set("n", "bf", function() + vim.lsp.buf.format({ timeout = 2000, async = true }) + end, bufopts) + end - local function organize_imports() - local params = { - command = "_typescript.organizeImports", - arguments = { vim.api.nvim_buf_get_name(0) }, - title = "", - } - vim.lsp.buf.execute_command(params) - end + local function organize_imports() + local params = { + command = "_typescript.organizeImports", + arguments = { vim.api.nvim_buf_get_name(0) }, + title = "", + } + vim.lsp.buf.execute_command(params) + end - local servers = { - { - "tsserver", - commands = { - LspOrganizeImports = { - organize_imports, - description = "Organize Imports", - }, - }, - }, - { "tailwindcss" }, - { "flow" }, - { "graphql" }, - { "html" }, - { "intelephense" }, - { "jsonls" }, - { "pyright" }, - { "vimls" }, - { "prismals" }, - { "solargraph" }, - { "bashls" }, - { "dockerls" }, - { "gopls", { - root_dir = function() - return vim.loop.cwd() - end, - } }, - { - "yamlls", - { - settings = { - yaml = { - schemas = { - ["https://json.schemastore.org/github-workflow.json"] = "/.github/workflows/*", - ["https://raw.githubusercontent.com/woodpecker-ci/woodpecker/master/pipeline/schema/schema.json"] = "/.woodpecker", - }, - }, - }, - }, - }, - { "cssls" }, - { "lua_ls" }, - } + local servers = { + { + "tsserver", + commands = { + LspOrganizeImports = { + organize_imports, + description = "Organize Imports", + }, + }, + }, + { "tailwindcss" }, + { "graphql" }, + { "html" }, + { "intelephense" }, + { "jsonls" }, + { "pyright" }, + { "vimls" }, + { "bashls" }, + { "dockerls" }, + { "solargraph" }, + -- { "rubocop" }, -- needs rubocop >= 1.54 + -- { "ruby_ls" }, -- wait for nvim 0.10 + { "gopls", { + root_dir = function() + return vim.loop.cwd() + end, + } }, + { "eslint" }, + { + "yamlls", + settings = { + yaml = { + schemas = { + ["https://json.schemastore.org/github-workflow.json"] = "/.github/workflows/*", + ["https://raw.githubusercontent.com/woodpecker-ci/woodpecker/master/pipeline/schema/schema.json"] = "/.woodpecker", + }, + }, + }, + }, + { "stylelint_lsp" }, + { "cssls" }, + { + "efm", + filetypes = { + "lua", + "fish", + "ruby", + "javascript", + "typescript", + "javascriptreact", + "typescriptreact", + "javascript.tsx", + "typescript.tsx" + }, + init_options = { + documentFormatting = true, + hover = true, + documentSymbol = true, + codeAction = true, + completion = true, + }, + settings = { + rootMarkers = { ".git/" }, + languages = { + lua = { + require("efmls-configs.linters.luacheck"), + }, + fish = { + require("efmls-configs.linters.fish"), + require("efmls-configs.formatters.fish_indent"), + }, + ruby = { + require("efmls-configs.linters.rubocop"), + }, + javascript = { + require("efmls-configs.formatters.prettier"), + }, + typescript = { + require("efmls-configs.formatters.prettier"), + }, + javascriptreact = { + require("efmls-configs.formatters.prettier"), + }, + typescriptreact = { + require("efmls-configs.formatters.prettier"), + }, + ["javascript.tsx"] = { + require("efmls-configs.formatters.prettier"), + }, + ["typescript.tsx"] = { + require("efmls-configs.formatters.prettier"), + }, + }, + }, + }, + { + "lua_ls", + settings = { + Lua = { + runtime = { + version = 'LuaJIT', + }, + diagnostics = { + globals = { 'vim' }, + }, + workspace = { + library = vim.api.nvim_get_runtime_file("", true), + }, + telemetry = { + enable = false, + }, + }, + }, + }, + } - for _, server in pairs(servers) do - local config = lspconfig[server[1]] - -- Only setup a language server if we have the binary available! - if vim.fn.executable(config.document_config.default_config.cmd[1]) == 1 then - local opts = { - on_attach = on_attach, - handlers = handlers, - capabilities = capabilities, - } + for _, server in pairs(servers) do + local config = lspconfig[server[1]] + local setup_config = { + on_attach = on_attach, + handlers = handlers, + capabilities = capabilities, + } - -- Add custom config if available - for k, v in pairs(server) do - if type(k) ~= "number" then - opts[k] = v - end - end + -- Add custom config if available + for k, v in pairs(server) do + if type(k) ~= "number" then + setup_config[k] = v + end + end - config.setup(opts) - end - end - end, + config.setup(setup_config) + end + end, } diff --git a/config/nvim/lua/plugins/null-ls.lua b/config/nvim/lua/plugins/null-ls.lua deleted file mode 100644 index 4e63eb3..0000000 --- a/config/nvim/lua/plugins/null-ls.lua +++ /dev/null @@ -1,397 +0,0 @@ -return { - "jose-elias-alvarez/null-ls.nvim", - dependencies = { - "nvim-lua/plenary.nvim", - "lewis6991/gitsigns.nvim", - }, - config = function() - local null_ls = require("null-ls") - local utils = require("null-ls.utils") - local cmd_resolver = require("null-ls.helpers.command_resolver") - - local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) - local async_formatting = function(bufnr) - bufnr = bufnr or vim.api.nvim_get_current_buf() - - vim.lsp.buf_request( - bufnr, - "textDocument/formatting", - vim.lsp.util.make_formatting_params({}), - function(err, res, ctx) - if err then - local err_msg = type(err) == "string" and err or err.message - -- you can modify the log message / level (or ignore it completely) - vim.notify("formatting: " .. err_msg, vim.log.levels.WARN) - return - end - - -- don't apply results if buffer is unloaded or has been modified - if not vim.api.nvim_buf_is_loaded(bufnr) or vim.api.nvim_buf_get_option(bufnr, "modified") then - return - end - - if res then - local client = vim.lsp.get_client_by_id(ctx.client_id) - - if client.name == "null-ls" then - vim.lsp.util.apply_text_edits(res, bufnr, client and client.offset_encoding or "utf-16") - vim.api.nvim_buf_call(bufnr, function() - vim.cmd("silent noautocmd update") - end) - end - end - end - ) - end - - null_ls.setup({ - on_attach = function(client, bufnr) - if client.supports_method("textDocument/formatting") then - vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) - vim.api.nvim_create_autocmd("BufWritePre", { - group = augroup, - buffer = bufnr, - callback = function() - async_formatting(bufnr) - end, - }) - end - end, - border = "single", - sources = { - -- nvim plugins - null_ls.builtins.completion.spell, - null_ls.builtins.code_actions.gitsigns, - - null_ls.builtins.diagnostics.stylelint.with({ - condition = function(u) - local cmd = cmd_resolver.from_node_modules()({ - command = "stylelint", - bufnr = vim.api.nvim_get_current_buf(), - bufname = vim.api.nvim_buf_get_name(vim.api.nvim_get_current_buf()), - }) - return utils.is_executable(cmd) and u.root_has_file(".stylelintrc.json") - end, - filetypes = { - "css", - "scss", - "less", - "vue", - "html", - "javascript", - "javascriptreact", - "typescript", - "typescriptreact", - }, - }), - - null_ls.builtins.formatting.stylelint.with({ - condition = function(u) - local cmd = cmd_resolver.from_node_modules()({ - command = "stylelint", - bufnr = vim.api.nvim_get_current_buf(), - bufname = vim.api.nvim_buf_get_name(vim.api.nvim_get_current_buf()), - }) - return utils.is_executable(cmd) and u.root_has_file(".stylelintrc.json") - end, - filetypes = { - "css", - "scss", - "less", - "vue", - "html", - "javascript", - "javascriptreact", - "typescript", - "typescriptreact", - }, - }), - - -- project local commands - null_ls.builtins.formatting.eslint.with({ - condition = function() - local cmd = cmd_resolver.from_node_modules()({ - command = "eslint", - bufnr = vim.api.nvim_get_current_buf(), - bufname = vim.api.nvim_buf_get_name(vim.api.nvim_get_current_buf()), - }) - return utils.is_executable(cmd) - end, - }), - null_ls.builtins.diagnostics.eslint.with({ - condition = function() - local cmd = cmd_resolver.from_node_modules()({ - command = "eslint", - bufnr = vim.api.nvim_get_current_buf(), - bufname = vim.api.nvim_buf_get_name(vim.api.nvim_get_current_buf()), - }) - return utils.is_executable(cmd) - end, - }), - - null_ls.builtins.formatting.prettier.with({ - condition = function() - local cmd = cmd_resolver.from_node_modules()({ - command = "prettier", - bufnr = vim.api.nvim_get_current_buf(), - bufname = vim.api.nvim_buf_get_name(vim.api.nvim_get_current_buf()), - }) - return utils.is_executable(cmd) - end, - filetypes = { - "javascript", - "javascriptreact", - "typescript", - "typescriptreact", - "vue", - "css", - "scss", - "less", - "html", - "yaml", - "json", - "graphql", - }, - }), - - -- global commands - null_ls.builtins.diagnostics.erb_lint.with({ - condition = function() - return utils.is_executable("erblint") - end, - }), - null_ls.builtins.formatting.erb_lint.with({ - condition = function() - return utils.is_executable("erblint") - end, - }), - - null_ls.builtins.code_actions.shellcheck.with({ - condition = function() - return utils.is_executable("shellcheck") - end, - }), - null_ls.builtins.diagnostics.shellcheck.with({ - condition = function() - return utils.is_executable("shellcheck") - end, - }), - - null_ls.builtins.diagnostics.buf.with({ - condition = function() - return utils.is_executable("buf") - end, - }), - - null_ls.builtins.diagnostics.checkmake.with({ - condition = function() - return utils.is_executable("checkmake") - end, - }), - - null_ls.builtins.diagnostics.codespell.with({ - condition = function() - return utils.is_executable("codespell") - end, - }), - - null_ls.builtins.diagnostics.fish.with({ - condition = function() - return utils.is_executable("fish") - end, - }), - null_ls.builtins.formatting.fish_indent.with({ - condition = function() - return utils.is_executable("fish_indent") - end, - }), - - null_ls.builtins.diagnostics.flake8.with({ - condition = function() - return utils.is_executable("flake8") - end, - }), - - null_ls.builtins.diagnostics.golangci_lint.with({ - condition = function() - return utils.is_executable("golangci-lint") - end, - }), - - null_ls.builtins.diagnostics.luacheck.with({ - condition = function() - return utils.is_executable("luacheck") - end, - }), - null_ls.builtins.formatting.stylua.with({ - condition = function() - return utils.is_executable("stylua") - end, - }), - - null_ls.builtins.diagnostics.markdownlint.with({ - condition = function() - return utils.is_executable("markdownlint") - end, - }), - null_ls.builtins.formatting.markdownlint.with({ - condition = function() - return utils.is_executable("markdownlint") - end, - }), - - null_ls.builtins.diagnostics.mypy.with({ - condition = function() - return utils.is_executable("mypy") - end, - }), - - null_ls.builtins.diagnostics.php.with({ - condition = function() - return utils.is_executable("php") - end, - }), - - null_ls.builtins.diagnostics.pylint.with({ - condition = function() - return utils.is_executable("pylint") - end, - }), - - null_ls.builtins.diagnostics.rubocop.with({ - condition = function() - return utils.is_executable("rubocop") - end, - }), - null_ls.builtins.formatting.rubocop.with({ - condition = function() - return utils.is_executable("rubocop") - end, - }), - - null_ls.builtins.diagnostics.tidy.with({ - condition = function() - return utils.is_executable("tidy") - end, - }), - null_ls.builtins.formatting.tidy.with({ - condition = function() - return utils.is_executable("tidy") - end, - }), - - null_ls.builtins.formatting.autopep8.with({ - condition = function() - return utils.is_executable("autopep8") - end, - }), - - null_ls.builtins.formatting.beautysh.with({ - condition = function() - return utils.is_executable("beautysh") - end, - }), - - null_ls.builtins.formatting.black.with({ - condition = function() - return utils.is_executable("black") - end, - }), - - null_ls.builtins.formatting.gofmt.with({ - condition = function() - return utils.is_executable("gofmt") - end, - }), - - null_ls.builtins.formatting.gofumpt.with({ - condition = function() - return utils.is_executable("gofumpt") - end, - }), - - null_ls.builtins.formatting.goimports.with({ - condition = function() - return utils.is_executable("goimports") - end, - }), - - null_ls.builtins.formatting.isort.with({ - condition = function() - return utils.is_executable("isort") - end, - }), - - null_ls.builtins.formatting.nginx_beautifier.with({ - condition = function() - return utils.is_executable("nginxbeautifier") - end, - }), - - null_ls.builtins.formatting.pg_format.with({ - condition = function() - return utils.is_executable("pg_format") - end, - }), - - null_ls.builtins.formatting.prismaFmt.with({ - condition = function() - return utils.is_executable("prisma-fmt") - end, - }), - - null_ls.builtins.formatting.rustywind.with({ - condition = function() - return utils.is_executable("rustywind") - end, - filetypes = { - "eruby", - "javascript", - "javascriptreact", - "typescript", - "typescriptreact", - "vue", - "svelte", - "html", - }, - }), - - null_ls.builtins.formatting.shfmt.with({ - condition = function() - return utils.is_executable("shfmt") - end, - }), - - null_ls.builtins.diagnostics.terraform_validate.with({ - condition = function() - return utils.is_executable("terraform") - end, - }), - null_ls.builtins.formatting.terraform_fmt.with({ - condition = function() - return utils.is_executable("terraform") - end, - }), - - null_ls.builtins.diagnostics.actionlint.with({ - condition = function() - return utils.is_executable("actionlint") - end, - }), - - null_ls.builtins.formatting.xmllint.with({ - condition = function() - return utils.is_executable("xmllint") - end, - }), - - null_ls.builtins.formatting.deno_fmt.with({ - condition = function() - return utils.is_executable("deno") - end, - filetypes = { "markdown" }, - }), - }, - }) - end, -}