diff options
Diffstat (limited to 'lua/lsp/null-ls')
-rw-r--r-- | lua/lsp/null-ls/formatters.lua | 66 | ||||
-rw-r--r-- | lua/lsp/null-ls/init.lua | 32 | ||||
-rw-r--r-- | lua/lsp/null-ls/linters.lua | 66 | ||||
-rw-r--r-- | lua/lsp/null-ls/services.lua | 63 |
4 files changed, 0 insertions, 227 deletions
diff --git a/lua/lsp/null-ls/formatters.lua b/lua/lsp/null-ls/formatters.lua deleted file mode 100644 index 4728b908..00000000 --- a/lua/lsp/null-ls/formatters.lua +++ /dev/null @@ -1,66 +0,0 @@ -local M = {} - -local null_ls = require "null-ls" -local services = require "lsp.null-ls.services" -local Log = require "core.log" - -function M.list_supported_names(filetype) - local null_ls_methods = require "null-ls.methods" - local formatter_method = null_ls_methods.internal["FORMATTING"] - local registered_providers = services.list_registered_providers_names(filetype) - return registered_providers[formatter_method] or {} -end - -function M.list_available(filetype) - local formatters = {} - local tbl = require "utils.table" - for _, provider in pairs(null_ls.builtins.formatting) do - if tbl.contains(provider.filetypes or {}, function(ft) - return ft == "*" or ft == filetype - end) then - table.insert(formatters, provider.name) - end - end - - return formatters -end - -function M.list_configured(formatter_configs) - local formatters, errors = {}, {} - - for _, fmt_config in ipairs(formatter_configs) do - local formatter_name = fmt_config.exe:gsub("-", "_") - local formatter = null_ls.builtins.formatting[formatter_name] - - if not formatter then - Log:error("Not a valid formatter: " .. fmt_config.exe) - errors[fmt_config.exe] = {} -- Add data here when necessary - else - local formatter_cmd = services.find_command(formatter._opts.command) - if not formatter_cmd then - Log:warn("Not found: " .. formatter._opts.command) - errors[fmt_config.exe] = {} -- Add data here when necessary - else - Log:debug("Using formatter: " .. formatter_cmd) - formatters[fmt_config.exe] = formatter.with { - command = formatter_cmd, - extra_args = fmt_config.args, - filetypes = fmt_config.filetypes, - } - end - end - end - - return { supported = formatters, unsupported = errors } -end - -function M.setup(formatter_configs) - if vim.tbl_isempty(formatter_configs) then - return - end - - local formatters_by_ft = M.list_configured(formatter_configs) - null_ls.register { sources = formatters_by_ft.supported } -end - -return M diff --git a/lua/lsp/null-ls/init.lua b/lua/lsp/null-ls/init.lua deleted file mode 100644 index 0d030c22..00000000 --- a/lua/lsp/null-ls/init.lua +++ /dev/null @@ -1,32 +0,0 @@ -local M = {} - -local Log = require "core.log" -local formatters = require "lsp.null-ls.formatters" -local linters = require "lsp.null-ls.linters" - -function M:setup() - local status_ok, null_ls = pcall(require, "null-ls") - if not status_ok then - Log:error "Missing null-ls dependency" - return - end - - null_ls.config() - require("lspconfig")["null-ls"].setup(lvim.lsp.null_ls.setup) - for filetype, config in pairs(lvim.lang) do - if not vim.tbl_isempty(config.formatters) then - vim.tbl_map(function(c) - c.filetypes = { filetype } - end, config.formatters) - formatters.setup(config.formatters) - end - if not vim.tbl_isempty(config.linters) then - vim.tbl_map(function(c) - c.filetypes = { filetype } - end, config.formatters) - linters.setup(config.linters) - end - end -end - -return M diff --git a/lua/lsp/null-ls/linters.lua b/lua/lsp/null-ls/linters.lua deleted file mode 100644 index 549c6cdd..00000000 --- a/lua/lsp/null-ls/linters.lua +++ /dev/null @@ -1,66 +0,0 @@ -local M = {} - -local null_ls = require "null-ls" -local services = require "lsp.null-ls.services" -local Log = require "core.log" - -function M.list_supported_names(filetype) - local null_ls_methods = require "null-ls.methods" - local linter_method = null_ls_methods.internal["DIAGNOSTICS"] - local registered_providers = services.list_registered_providers_names(filetype) - return registered_providers[linter_method] or {} -end - -function M.list_available(filetype) - local linters = {} - local tbl = require "utils.table" - for _, provider in pairs(null_ls.builtins.diagnostics) do - if tbl.contains(provider.filetypes or {}, function(ft) - return ft == "*" or ft == filetype - end) then - table.insert(linters, provider.name) - end - end - - return linters -end - -function M.list_configured(linter_configs) - local linters, errors = {}, {} - - for _, lnt_config in pairs(linter_configs) do - local linter_name = lnt_config.exe:gsub("-", "_") - local linter = null_ls.builtins.diagnostics[linter_name] - - if not linter then - Log:error("Not a valid linter: " .. lnt_config.exe) - errors[lnt_config.exe] = {} -- Add data here when necessary - else - local linter_cmd = services.find_command(linter._opts.command) - if not linter_cmd then - Log:warn("Not found: " .. linter._opts.command) - errors[lnt_config.exe] = {} -- Add data here when necessary - else - Log:debug("Using linter: " .. linter_cmd) - linters[lnt_config.exe] = linter.with { - command = linter_cmd, - extra_args = lnt_config.args, - filetypes = lnt_config.filetypes, - } - end - end - end - - return { supported = linters, unsupported = errors } -end - -function M.setup(linter_configs) - if vim.tbl_isempty(linter_configs) then - return - end - - local linters = M.list_configured(linter_configs) - null_ls.register { sources = linters.supported } -end - -return M diff --git a/lua/lsp/null-ls/services.lua b/lua/lsp/null-ls/services.lua deleted file mode 100644 index ef9e7d22..00000000 --- a/lua/lsp/null-ls/services.lua +++ /dev/null @@ -1,63 +0,0 @@ -local M = {} - -local function find_root_dir() - local util = require "lspconfig/util" - local lsp_utils = require "lsp.utils" - - local ts_client = lsp_utils.is_client_active "typescript" - if ts_client then - return ts_client.config.root_dir - end - local dirname = vim.fn.expand "%:p:h" - return util.root_pattern "package.json"(dirname) -end - -local function from_node_modules(command) - local root_dir = find_root_dir() - - if not root_dir then - return nil - end - - return root_dir .. "/node_modules/.bin/" .. command -end - -local local_providers = { - prettier = { find = from_node_modules }, - prettierd = { find = from_node_modules }, - prettier_d_slim = { find = from_node_modules }, - eslint_d = { find = from_node_modules }, - eslint = { find = from_node_modules }, - stylelint = { find = from_node_modules }, -} - -function M.find_command(command) - if local_providers[command] then - local local_command = local_providers[command].find(command) - if local_command and vim.fn.executable(local_command) == 1 then - return local_command - end - end - - if vim.fn.executable(command) == 1 then - return command - end - return nil -end - -function M.list_registered_providers_names(filetype) - local u = require "null-ls.utils" - local c = require "null-ls.config" - local registered = {} - for method, source in pairs(c.get()._methods) do - for name, filetypes in pairs(source) do - if u.filetype_matches(filetypes, filetype) then - registered[method] = registered[method] or {} - table.insert(registered[method], name) - end - end - end - return registered -end - -return M |