diff options
author | Christian Chiarulli <[email protected]> | 2021-07-24 21:17:11 -0400 |
---|---|---|
committer | GitHub <[email protected]> | 2021-07-24 21:17:11 -0400 |
commit | 98f8a77819670ce6012216e01885c135a6d3a289 (patch) | |
tree | b655da889c33e0eb89251878783700a8cd014a27 /lua/lsp/null-ls.lua | |
parent | 0884dcd84670bc097c34253e983d2cde9c209dfa (diff) |
New contract (#1080)
Changes to the global config object
O is now lvim
user_plugins is now plugins
user_autocommands is now autocommands
No more lang specific plugins
Null-ls has replaced both formatter.nvim and nvim-lint
Diffstat (limited to 'lua/lsp/null-ls.lua')
-rw-r--r-- | lua/lsp/null-ls.lua | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/lua/lsp/null-ls.lua b/lua/lsp/null-ls.lua new file mode 100644 index 00000000..43d4400a --- /dev/null +++ b/lua/lsp/null-ls.lua @@ -0,0 +1,70 @@ +local M = {} + +local null_ls = require "null-ls" +local sources = {} + +local local_executables = { "prettier", "prettierd", "prettier_d_slim", "eslint_d", "eslint" } + +local function is_table(t) + return type(t) == "table" +end + +local function is_string(t) + return type(t) == "string" +end + +local function has_value(tab, val) + for index, value in ipairs(tab) do + if value == val then + return true + end + end + + return false +end + +local find_local_exe = function(exe) + vim.cmd "let root_dir = FindRootDirectory()" + local root_dir = vim.api.nvim_get_var "root_dir" + local local_exe = root_dir .. "/node_modules/.bin/" .. exe + return local_exe +end + +local function setup_ls(exe, type) + if has_value(local_executables, exe) then + local smart_executable = null_ls.builtins[type][exe] + local local_executable = find_local_exe(exe) + if vim.fn.executable(local_executable) then + smart_executable._opts.command = local_executable + end + table.insert(sources, smart_executable) + else + table.insert(sources, null_ls.builtins[type][exe]) + end + null_ls.register { sources = sources } +end + +local function setup(filetype, type) + if type == "diagnostics" then + executables = lvim.lang[filetype].linters + end + if type == "formatting" then + executables = lvim.lang[filetype].formatter.exe + end + + if is_table(executables) then + for _, exe in pairs(executables) do + setup_ls(exe, type) + end + end + if is_string(executables) then + setup_ls(executables, type) + end +end + +function M.setup(filetype) + setup(filetype, "formatting") + setup(filetype, "diagnostics") +end + +return M |