From 3eaf6d461c896ba9fadaf63af0ecbe3769653fa2 Mon Sep 17 00:00:00 2001 From: Pasi Bergman Date: Thu, 29 Jul 2021 16:03:03 +0300 Subject: fix: Use null-ls eslint diagnostics config with eslint_d exe (#1159) --- lua/lsp/null-ls.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'lua/lsp/null-ls.lua') diff --git a/lua/lsp/null-ls.lua b/lua/lsp/null-ls.lua index a231698a..6a31de26 100644 --- a/lua/lsp/null-ls.lua +++ b/lua/lsp/null-ls.lua @@ -13,15 +13,25 @@ local find_local_exe = function(exe) return local_exe end +-- https://github.com/jose-elias-alvarez/null-ls.nvim/blob/9b8458bd1648e84169a7e8638091ba15c2f20fc0/doc/BUILTINS.md#eslint +local get_normalized_exe = function(exe, type) + if type == "diagnostics" and exe == "eslint_d" then + return "eslint" + end + return exe +end + local function setup_ls(exe, type) if utils.has_value(local_executables, exe) then - local smart_executable = null_ls.builtins[type][exe] + local normalized_exe = get_normalized_exe(exe, type) + local smart_executable = null_ls.builtins[type][normalized_exe] local local_executable = find_local_exe(exe) if vim.fn.executable(local_executable) == 1 then smart_executable._opts.command = local_executable table.insert(sources, smart_executable) else if vim.fn.executable(exe) == 1 then + smart_executable._opts.command = exe table.insert(sources, smart_executable) end end -- cgit v1.2.3 From 9d89929d9bb47d1f78c2d3945b761da2f24a5643 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Sat, 31 Jul 2021 06:06:08 +0200 Subject: Enable querying lang-server formatting capabilities (#1078) --- lua/lsp/null-ls.lua | 113 +++++++++++++++++++++++++++------------------------- 1 file changed, 58 insertions(+), 55 deletions(-) (limited to 'lua/lsp/null-ls.lua') diff --git a/lua/lsp/null-ls.lua b/lua/lsp/null-ls.lua index 6a31de26..d2222602 100644 --- a/lua/lsp/null-ls.lua +++ b/lua/lsp/null-ls.lua @@ -1,76 +1,79 @@ local M = {} +local u = require "utils" +local null_ls = require "null-ls" -local _, null_ls = pcall(require, "null-ls") -local utils = require "utils" -local sources = {} +local nodejs_local_providers = { "prettier", "prettierd", "prettier_d_slim", "eslint_d", "eslint" } -local local_executables = { "prettier", "prettierd", "prettier_d_slim", "eslint_d", "eslint" } +M.requested_providers = {} -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 +local function is_nodejs_provider(provider) + for _, local_provider in ipairs(nodejs_local_providers) do + if local_provider == provider.exe then + return true + end + end + return false end --- https://github.com/jose-elias-alvarez/null-ls.nvim/blob/9b8458bd1648e84169a7e8638091ba15c2f20fc0/doc/BUILTINS.md#eslint -local get_normalized_exe = function(exe, type) - if type == "diagnostics" and exe == "eslint_d" then - return "eslint" +local function is_provider_found(provider) + -- special case: fallback to "eslint" + -- https://github.com/jose-elias-alvarez/null-ls.nvim/blob/9b8458bd1648e84169a7e8638091ba15c2f20fc0/doc/BUILTINS.md#eslint + provider._opts.command = provider._opts.command == "eslint_d" and "eslint" or provider._opts.command + + local retval = { is_local = false, path = nil } + if vim.fn.executable(provider._opts.command) == 1 then + return false, provider._opts.command end - return exe + if is_nodejs_provider(provider) then + vim.cmd "let root_dir = FindRootDirectory()" + local root_dir = vim.api.nvim_get_var "root_dir" + local local_provider_command = root_dir .. "/node_modules/.bin/" .. provider._opts.command + if vim.fn.executable(local_provider_command) == 1 then + retval.is_local = true + retval.path = local_provider_command + end + end + return retval.is_local, retval.path end -local function setup_ls(exe, type) - if utils.has_value(local_executables, exe) then - local normalized_exe = get_normalized_exe(exe, type) - local smart_executable = null_ls.builtins[type][normalized_exe] - local local_executable = find_local_exe(exe) - if vim.fn.executable(local_executable) == 1 then - smart_executable._opts.command = local_executable - table.insert(sources, smart_executable) - else - if vim.fn.executable(exe) == 1 then - smart_executable._opts.command = exe - table.insert(sources, smart_executable) - end - end - else - if null_ls.builtins[type][exe] and vim.fn.executable(null_ls.builtins[type][exe]._opts.command) then - table.insert(sources, null_ls.builtins[type][exe]) - end +local function validate_provider(provider) + local is_local, provider_path = is_provider_found(provider) + if not provider_path then + u.lvim_log(string.format("Unable to find the path for: [%s]", provider)) + return false end - null_ls.register { sources = sources } + if is_local then + provider._opts.command = provider_path + end + return true end -- TODO: for linters and formatters with spaces and '-' replace with '_' -local function setup(filetype, type) - local executables = nil - if type == "diagnostics" then - executables = lvim.lang[filetype].linters +function M.setup(filetype) + for _, formatter in pairs(lvim.lang[filetype].formatters) do + local builtin_formatter = null_ls.builtins.formatting[formatter.exe] + -- FIXME: why doesn't this work? + -- builtin_formatter._opts.args = formatter.args or builtin_formatter._opts.args + -- builtin_formatter._opts.to_stdin = formatter.stdin or builtin_formatter._opts.to_stdin + table.insert(M.requested_providers, builtin_formatter) + u.lvim_log(string.format("Using format provider: [%s]", formatter.exe)) end - if type == "formatting" then - executables = lvim.lang[filetype].formatter.exe + + for _, linter in pairs(lvim.lang[filetype].linters) do + local builtin_diagnoser = null_ls.builtins.diagnostics[linter.exe] + -- FIXME: why doesn't this work? + -- builtin_diagnoser._opts.args = linter.args or builtin_diagnoser._opts.args + -- builtin_diagnoser._opts.to_stdin = linter.stdin or builtin_diagnoser._opts.to_stdin + table.insert(M.requested_providers, builtin_diagnoser) + u.lvim_log(string.format("Using linter provider: [%s]", linter.exe)) end - if utils.is_table(executables) then - for _, exe in pairs(executables) do - if exe ~= "" then - setup_ls(exe, type) - end + for idx, provider in pairs(M.requested_providers) do + if not validate_provider(provider) then + table.remove(M.requested_providers, idx) end end - if utils.is_string(executables) and executables ~= "" then - setup_ls(executables, type) - end -end - --- TODO: return the formatter if one was registered, then turn off the builtin formatter -function M.setup(filetype) - setup(filetype, "formatting") - setup(filetype, "diagnostics") - lvim.sources = sources - return sources + null_ls.register { sources = M.requested_providers } end return M -- cgit v1.2.3 From 8157f50d1308f42f3db1c7f69c226eb2e5c0b796 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Sat, 31 Jul 2021 15:04:22 +0200 Subject: feat: get null-ls registered providers by filetype (#1186) --- lua/lsp/null-ls.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'lua/lsp/null-ls.lua') diff --git a/lua/lsp/null-ls.lua b/lua/lsp/null-ls.lua index d2222602..468d12a6 100644 --- a/lua/lsp/null-ls.lua +++ b/lua/lsp/null-ls.lua @@ -6,6 +6,17 @@ local nodejs_local_providers = { "prettier", "prettierd", "prettier_d_slim", "es M.requested_providers = {} +function M.get_registered_providers_by_filetype(ft) + local matches = {} + for _, provider in pairs(M.requested_providers) do + if vim.tbl_contains(provider.filetypes, ft) then + table.insert(matches, provider.name) + end + end + + return matches +end + local function is_nodejs_provider(provider) for _, local_provider in ipairs(nodejs_local_providers) do if local_provider == provider.exe then -- cgit v1.2.3 From de200da87d22c0a6e6505c3618fa64a53f9bf4c1 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Sat, 31 Jul 2021 19:59:52 +0430 Subject: fix eslint_d issue (#1189) --- lua/lsp/null-ls.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'lua/lsp/null-ls.lua') diff --git a/lua/lsp/null-ls.lua b/lua/lsp/null-ls.lua index 468d12a6..2098ea9e 100644 --- a/lua/lsp/null-ls.lua +++ b/lua/lsp/null-ls.lua @@ -27,10 +27,6 @@ local function is_nodejs_provider(provider) end local function is_provider_found(provider) - -- special case: fallback to "eslint" - -- https://github.com/jose-elias-alvarez/null-ls.nvim/blob/9b8458bd1648e84169a7e8638091ba15c2f20fc0/doc/BUILTINS.md#eslint - provider._opts.command = provider._opts.command == "eslint_d" and "eslint" or provider._opts.command - local retval = { is_local = false, path = nil } if vim.fn.executable(provider._opts.command) == 1 then return false, provider._opts.command @@ -76,6 +72,11 @@ function M.setup(filetype) -- builtin_diagnoser._opts.args = linter.args or builtin_diagnoser._opts.args -- builtin_diagnoser._opts.to_stdin = linter.stdin or builtin_diagnoser._opts.to_stdin table.insert(M.requested_providers, builtin_diagnoser) + -- special case: fallback to "eslint" + -- https://github.com/jose-elias-alvarez/null-ls.nvim/blob/9b8458bd1648e84169a7e8638091ba15c2f20fc0/doc/BUILTINS.md#eslint + if linter.exe == "eslint_d" then + table.insert(M.requested_providers, null_ls.builtins.diagnostics.eslint.with { command = "eslint_d" }) + end u.lvim_log(string.format("Using linter provider: [%s]", linter.exe)) end -- cgit v1.2.3 From c4bff33745eb765ba49b170db2776284f5d015ef Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Sat, 31 Jul 2021 20:12:12 +0430 Subject: show the actual command (#1191) --- lua/lsp/null-ls.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lua/lsp/null-ls.lua') diff --git a/lua/lsp/null-ls.lua b/lua/lsp/null-ls.lua index 2098ea9e..fde6c5bd 100644 --- a/lua/lsp/null-ls.lua +++ b/lua/lsp/null-ls.lua @@ -10,7 +10,7 @@ function M.get_registered_providers_by_filetype(ft) local matches = {} for _, provider in pairs(M.requested_providers) do if vim.tbl_contains(provider.filetypes, ft) then - table.insert(matches, provider.name) + table.insert(matches, provider._opts.command) end end -- cgit v1.2.3 From 2badb25f361ddeae32fcd482384cccdab96f8e68 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Sat, 31 Jul 2021 20:26:25 +0430 Subject: why is eslint_d so bad (#1192) --- lua/lsp/null-ls.lua | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'lua/lsp/null-ls.lua') diff --git a/lua/lsp/null-ls.lua b/lua/lsp/null-ls.lua index fde6c5bd..1d9f1ec1 100644 --- a/lua/lsp/null-ls.lua +++ b/lua/lsp/null-ls.lua @@ -10,7 +10,13 @@ function M.get_registered_providers_by_filetype(ft) local matches = {} for _, provider in pairs(M.requested_providers) do if vim.tbl_contains(provider.filetypes, ft) then - table.insert(matches, provider._opts.command) + local provider_name = provider.name + -- special case: show "eslint_d" instead of eslint + -- https://github.com/jose-elias-alvarez/null-ls.nvim/blob/9b8458bd1648e84169a7e8638091ba15c2f20fc0/doc/BUILTINS.md#eslint + if string.find(provider._opts.command, "eslint_d") then + provider_name = "eslint_d" + end + table.insert(matches, provider_name) end end @@ -19,7 +25,7 @@ end local function is_nodejs_provider(provider) for _, local_provider in ipairs(nodejs_local_providers) do - if local_provider == provider.exe then + if local_provider == provider._opts.command then return true end end @@ -46,7 +52,7 @@ end local function validate_provider(provider) local is_local, provider_path = is_provider_found(provider) if not provider_path then - u.lvim_log(string.format("Unable to find the path for: [%s]", provider)) + u.lvim_log(string.format("Unable to find the path for: [%s]", vim.inspect(provider))) return false end if is_local then -- cgit v1.2.3 From 8ee070833e17efede8b01c81ff9d8439ec52fdb8 Mon Sep 17 00:00:00 2001 From: christianchiarulli Date: Sat, 31 Jul 2021 19:45:42 -0400 Subject: fix linter present when executable not found --- lua/lsp/null-ls.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lua/lsp/null-ls.lua') diff --git a/lua/lsp/null-ls.lua b/lua/lsp/null-ls.lua index 1d9f1ec1..798c02ee 100644 --- a/lua/lsp/null-ls.lua +++ b/lua/lsp/null-ls.lua @@ -77,7 +77,10 @@ function M.setup(filetype) -- FIXME: why doesn't this work? -- builtin_diagnoser._opts.args = linter.args or builtin_diagnoser._opts.args -- builtin_diagnoser._opts.to_stdin = linter.stdin or builtin_diagnoser._opts.to_stdin - table.insert(M.requested_providers, builtin_diagnoser) + -- NOTE: validate before inserting to table + if validate_provider(builtin_diagnoser) then + table.insert(M.requested_providers, builtin_diagnoser) + end -- special case: fallback to "eslint" -- https://github.com/jose-elias-alvarez/null-ls.nvim/blob/9b8458bd1648e84169a7e8638091ba15c2f20fc0/doc/BUILTINS.md#eslint if linter.exe == "eslint_d" then @@ -86,6 +89,7 @@ function M.setup(filetype) u.lvim_log(string.format("Using linter provider: [%s]", linter.exe)) end + -- FIXME: why would we need to remove if we never add? for idx, provider in pairs(M.requested_providers) do if not validate_provider(provider) then table.remove(M.requested_providers, idx) -- cgit v1.2.3 From 30ad4b81f5dbccb6d49eb28ffdd33cefcb758ee5 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Sun, 1 Aug 2021 14:27:15 +0430 Subject: Hotfix/eslint d (#1198) --- lua/lsp/null-ls.lua | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'lua/lsp/null-ls.lua') diff --git a/lua/lsp/null-ls.lua b/lua/lsp/null-ls.lua index 798c02ee..b8f9bfe6 100644 --- a/lua/lsp/null-ls.lua +++ b/lua/lsp/null-ls.lua @@ -34,18 +34,17 @@ end local function is_provider_found(provider) local retval = { is_local = false, path = nil } - if vim.fn.executable(provider._opts.command) == 1 then - return false, provider._opts.command - end if is_nodejs_provider(provider) then vim.cmd "let root_dir = FindRootDirectory()" local root_dir = vim.api.nvim_get_var "root_dir" local local_provider_command = root_dir .. "/node_modules/.bin/" .. provider._opts.command if vim.fn.executable(local_provider_command) == 1 then - retval.is_local = true - retval.path = local_provider_command + return true, local_provider_command end end + if vim.fn.executable(provider._opts.command) == 1 then + return false, provider._opts.command + end return retval.is_local, retval.path end @@ -78,23 +77,17 @@ function M.setup(filetype) -- builtin_diagnoser._opts.args = linter.args or builtin_diagnoser._opts.args -- builtin_diagnoser._opts.to_stdin = linter.stdin or builtin_diagnoser._opts.to_stdin -- NOTE: validate before inserting to table - if validate_provider(builtin_diagnoser) then - table.insert(M.requested_providers, builtin_diagnoser) - end -- special case: fallback to "eslint" -- https://github.com/jose-elias-alvarez/null-ls.nvim/blob/9b8458bd1648e84169a7e8638091ba15c2f20fc0/doc/BUILTINS.md#eslint if linter.exe == "eslint_d" then - table.insert(M.requested_providers, null_ls.builtins.diagnostics.eslint.with { command = "eslint_d" }) + builtin_diagnoser = null_ls.builtins.diagnostics.eslint.with { command = "eslint_d" } + end + if validate_provider(builtin_diagnoser) then + table.insert(M.requested_providers, builtin_diagnoser) end u.lvim_log(string.format("Using linter provider: [%s]", linter.exe)) end - -- FIXME: why would we need to remove if we never add? - for idx, provider in pairs(M.requested_providers) do - if not validate_provider(provider) then - table.remove(M.requested_providers, idx) - end - end null_ls.register { sources = M.requested_providers } end -- cgit v1.2.3 From e2dd993ce753f8d28e6c32c4697ba51cc8ace2bb Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Sun, 1 Aug 2021 12:02:10 +0200 Subject: refactor null-ls (#1202) --- lua/lsp/null-ls.lua | 67 +++++++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 35 deletions(-) (limited to 'lua/lsp/null-ls.lua') diff --git a/lua/lsp/null-ls.lua b/lua/lsp/null-ls.lua index b8f9bfe6..51fab00b 100644 --- a/lua/lsp/null-ls.lua +++ b/lua/lsp/null-ls.lua @@ -23,40 +23,37 @@ function M.get_registered_providers_by_filetype(ft) return matches end -local function is_nodejs_provider(provider) - for _, local_provider in ipairs(nodejs_local_providers) do - if local_provider == provider._opts.command then - return true - end +local function validate_nodejs_provider(requests, provider) + vim.cmd "let root_dir = FindRootDirectory()" + local root_dir = vim.api.nvim_get_var "root_dir" + local local_nodejs_command = root_dir .. "/node_modules/.bin/" .. provider._opts.command + u.lvim_log(string.format("checking for local node module: [%s]", vim.inspect(provider))) + if vim.fn.executable(local_nodejs_command) == 1 then + provider._opts.command = local_nodejs_command + table.insert(requests, provider) + elseif vim.fn.executable(provider._opts.command) == 1 then + u.lvim_log(string.format("checking in global path instead for node module: [%s]", provider._opts.command)) + table.insert(requests, provider) + else + u.lvim_log(string.format("Unable to find node module: [%s]", provider._opts.command)) + return false end - return false + return true end -local function is_provider_found(provider) - local retval = { is_local = false, path = nil } - if is_nodejs_provider(provider) then - vim.cmd "let root_dir = FindRootDirectory()" - local root_dir = vim.api.nvim_get_var "root_dir" - local local_provider_command = root_dir .. "/node_modules/.bin/" .. provider._opts.command - if vim.fn.executable(local_provider_command) == 1 then - return true, local_provider_command - end +local function validate_provider_request(requests, provider) + if provider == "" or provider == nil then + return false end - if vim.fn.executable(provider._opts.command) == 1 then - return false, provider._opts.command + -- NOTE: we can't use provider.name because eslint_d uses eslint name + if vim.tbl_contains(nodejs_local_providers, provider._opts.command) then + return validate_nodejs_provider(requests, provider) end - return retval.is_local, retval.path -end - -local function validate_provider(provider) - local is_local, provider_path = is_provider_found(provider) - if not provider_path then + if vim.fn.executable(provider._opts.command) ~= 1 then u.lvim_log(string.format("Unable to find the path for: [%s]", vim.inspect(provider))) return false end - if is_local then - provider._opts.command = provider_path - end + table.insert(requests, provider) return true end @@ -67,25 +64,25 @@ function M.setup(filetype) -- FIXME: why doesn't this work? -- builtin_formatter._opts.args = formatter.args or builtin_formatter._opts.args -- builtin_formatter._opts.to_stdin = formatter.stdin or builtin_formatter._opts.to_stdin - table.insert(M.requested_providers, builtin_formatter) - u.lvim_log(string.format("Using format provider: [%s]", formatter.exe)) + if validate_provider_request(M.requested_providers, builtin_formatter) then + u.lvim_log(string.format("Using format provider: [%s]", formatter.exe)) + end end for _, linter in pairs(lvim.lang[filetype].linters) do local builtin_diagnoser = null_ls.builtins.diagnostics[linter.exe] - -- FIXME: why doesn't this work? - -- builtin_diagnoser._opts.args = linter.args or builtin_diagnoser._opts.args - -- builtin_diagnoser._opts.to_stdin = linter.stdin or builtin_diagnoser._opts.to_stdin - -- NOTE: validate before inserting to table -- special case: fallback to "eslint" -- https://github.com/jose-elias-alvarez/null-ls.nvim/blob/9b8458bd1648e84169a7e8638091ba15c2f20fc0/doc/BUILTINS.md#eslint + -- if provider.exe if linter.exe == "eslint_d" then builtin_diagnoser = null_ls.builtins.diagnostics.eslint.with { command = "eslint_d" } end - if validate_provider(builtin_diagnoser) then - table.insert(M.requested_providers, builtin_diagnoser) + -- FIXME: why doesn't this work? + -- builtin_diagnoser._opts.args = linter.args or builtin_diagnoser._opts.args + -- builtin_diagnoser._opts.to_stdin = linter.stdin or builtin_diagnoser._opts.to_stdin + if validate_provider_request(M.requested_providers, builtin_diagnoser) then + u.lvim_log(string.format("Using linter provider: [%s]", linter.exe)) end - u.lvim_log(string.format("Using linter provider: [%s]", linter.exe)) end null_ls.register { sources = M.requested_providers } -- cgit v1.2.3 From 4c3c3f388557a182794bffdbf923129c66af885a Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Tue, 3 Aug 2021 18:10:54 +0200 Subject: feat: add lvim.lsp.smart_cwd (#1218) - Enable querying the language-server for the `root_dir` - Use `root_dir` to set the current working-directory (CWD) - Make vim-rooter configurable and add an option to disable it Inspired by "ahmedkhalf/lsp-rooter.nvim" --- lua/lsp/null-ls.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'lua/lsp/null-ls.lua') diff --git a/lua/lsp/null-ls.lua b/lua/lsp/null-ls.lua index 51fab00b..d3f7931b 100644 --- a/lua/lsp/null-ls.lua +++ b/lua/lsp/null-ls.lua @@ -24,10 +24,14 @@ function M.get_registered_providers_by_filetype(ft) end local function validate_nodejs_provider(requests, provider) - vim.cmd "let root_dir = FindRootDirectory()" - local root_dir = vim.api.nvim_get_var "root_dir" + local ts_client = require("utils").get_active_client_by_ft "typescript" + if ts_client == nil then + u.lvim_log "Unable to determine root directory since tsserver didn't start correctly" + return + end + local root_dir = ts_client.config.root_dir local local_nodejs_command = root_dir .. "/node_modules/.bin/" .. provider._opts.command - u.lvim_log(string.format("checking for local node module: [%s]", vim.inspect(provider))) + u.lvim_log(string.format("checking [%s] for local node module: [%s]", local_nodejs_command, vim.inspect(provider))) if vim.fn.executable(local_nodejs_command) == 1 then provider._opts.command = local_nodejs_command table.insert(requests, provider) -- cgit v1.2.3 From 6c6fb67a8835cdcf911ef48ec2c19d553fe7d1a1 Mon Sep 17 00:00:00 2001 From: christianchiarulli Date: Tue, 3 Aug 2021 23:02:09 -0400 Subject: use old vim rooter logic, fallback on new way if vimrooter is disabled --- lua/lsp/null-ls.lua | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'lua/lsp/null-ls.lua') diff --git a/lua/lsp/null-ls.lua b/lua/lsp/null-ls.lua index d3f7931b..8bdea227 100644 --- a/lua/lsp/null-ls.lua +++ b/lua/lsp/null-ls.lua @@ -24,12 +24,22 @@ function M.get_registered_providers_by_filetype(ft) end local function validate_nodejs_provider(requests, provider) - local ts_client = require("utils").get_active_client_by_ft "typescript" - if ts_client == nil then - u.lvim_log "Unable to determine root directory since tsserver didn't start correctly" - return + local root_dir = "" + if lvim.builtin.rooter.active then + --- old logic to set root_dir + vim.cmd "let root_dir = FindRootDirectory()" + root_dir = vim.api.nvim_get_var "root_dir" + else + --- new logic to set root_dir + local ts_client = require("utils").get_active_client_by_ft "typescript" + if ts_client then + local root_dir = ts_client.config.root_dir + end + if ts_client == nil then + u.lvim_log "Unable to determine root directory since tsserver didn't start correctly" + return + end end - local root_dir = ts_client.config.root_dir local local_nodejs_command = root_dir .. "/node_modules/.bin/" .. provider._opts.command u.lvim_log(string.format("checking [%s] for local node module: [%s]", local_nodejs_command, vim.inspect(provider))) if vim.fn.executable(local_nodejs_command) == 1 then -- cgit v1.2.3 From e504e1f08cde5893cf6a6c39fd1029fced21b996 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Wed, 4 Aug 2021 09:58:24 +0430 Subject: fix formatting and linting (#1220) --- lua/lsp/null-ls.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lua/lsp/null-ls.lua') diff --git a/lua/lsp/null-ls.lua b/lua/lsp/null-ls.lua index 8bdea227..04e35976 100644 --- a/lua/lsp/null-ls.lua +++ b/lua/lsp/null-ls.lua @@ -33,7 +33,7 @@ local function validate_nodejs_provider(requests, provider) --- new logic to set root_dir local ts_client = require("utils").get_active_client_by_ft "typescript" if ts_client then - local root_dir = ts_client.config.root_dir + root_dir = ts_client.config.root_dir end if ts_client == nil then u.lvim_log "Unable to determine root directory since tsserver didn't start correctly" -- cgit v1.2.3 From 7cd03ff4e332e1427497b54d5ca8b037afbc0982 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Wed, 4 Aug 2021 08:35:51 +0200 Subject: chore: minor cleanup to root_dir comments (#1222) --- lua/lsp/null-ls.lua | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'lua/lsp/null-ls.lua') diff --git a/lua/lsp/null-ls.lua b/lua/lsp/null-ls.lua index 04e35976..27cd1f78 100644 --- a/lua/lsp/null-ls.lua +++ b/lua/lsp/null-ls.lua @@ -24,21 +24,19 @@ function M.get_registered_providers_by_filetype(ft) end local function validate_nodejs_provider(requests, provider) - local root_dir = "" + local root_dir if lvim.builtin.rooter.active then - --- old logic to set root_dir + --- use vim-rooter to set root_dir vim.cmd "let root_dir = FindRootDirectory()" root_dir = vim.api.nvim_get_var "root_dir" else - --- new logic to set root_dir + --- use LSP to set root_dir local ts_client = require("utils").get_active_client_by_ft "typescript" - if ts_client then - root_dir = ts_client.config.root_dir - end if ts_client == nil then u.lvim_log "Unable to determine root directory since tsserver didn't start correctly" return end + root_dir = ts_client.config.root_dir end local local_nodejs_command = root_dir .. "/node_modules/.bin/" .. provider._opts.command u.lvim_log(string.format("checking [%s] for local node module: [%s]", local_nodejs_command, vim.inspect(provider))) -- cgit v1.2.3 From 76a16b6676183af564359c53184de1ebf6028b37 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Thu, 5 Aug 2021 16:34:25 +0200 Subject: stop registering duplicate null-ls providers (#1240) --- lua/lsp/null-ls.lua | 52 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 22 deletions(-) (limited to 'lua/lsp/null-ls.lua') diff --git a/lua/lsp/null-ls.lua b/lua/lsp/null-ls.lua index 27cd1f78..7adfa218 100644 --- a/lua/lsp/null-ls.lua +++ b/lua/lsp/null-ls.lua @@ -23,7 +23,8 @@ function M.get_registered_providers_by_filetype(ft) return matches end -local function validate_nodejs_provider(requests, provider) +local function validate_nodejs_provider(provider) + local command_path local root_dir if lvim.builtin.rooter.active then --- use vim-rooter to set root_dir @@ -41,43 +42,45 @@ local function validate_nodejs_provider(requests, provider) local local_nodejs_command = root_dir .. "/node_modules/.bin/" .. provider._opts.command u.lvim_log(string.format("checking [%s] for local node module: [%s]", local_nodejs_command, vim.inspect(provider))) if vim.fn.executable(local_nodejs_command) == 1 then - provider._opts.command = local_nodejs_command - table.insert(requests, provider) + command_path = local_nodejs_command elseif vim.fn.executable(provider._opts.command) == 1 then u.lvim_log(string.format("checking in global path instead for node module: [%s]", provider._opts.command)) - table.insert(requests, provider) + command_path = provider._opts.command else u.lvim_log(string.format("Unable to find node module: [%s]", provider._opts.command)) - return false end - return true + return command_path end -local function validate_provider_request(requests, provider) +local function validate_provider_request(provider) if provider == "" or provider == nil then - return false + return end -- NOTE: we can't use provider.name because eslint_d uses eslint name if vim.tbl_contains(nodejs_local_providers, provider._opts.command) then - return validate_nodejs_provider(requests, provider) + return validate_nodejs_provider(provider) end if vim.fn.executable(provider._opts.command) ~= 1 then u.lvim_log(string.format("Unable to find the path for: [%s]", vim.inspect(provider))) - return false + return end - table.insert(requests, provider) - return true + return provider._opts.command end -- TODO: for linters and formatters with spaces and '-' replace with '_' function M.setup(filetype) for _, formatter in pairs(lvim.lang[filetype].formatters) do local builtin_formatter = null_ls.builtins.formatting[formatter.exe] - -- FIXME: why doesn't this work? - -- builtin_formatter._opts.args = formatter.args or builtin_formatter._opts.args - -- builtin_formatter._opts.to_stdin = formatter.stdin or builtin_formatter._opts.to_stdin - if validate_provider_request(M.requested_providers, builtin_formatter) then - u.lvim_log(string.format("Using format provider: [%s]", formatter.exe)) + if not vim.tbl_contains(M.requested_providers, builtin_formatter) then + -- FIXME: why doesn't this work? + -- builtin_formatter._opts.args = formatter.args or builtin_formatter._opts.args + -- builtin_formatter._opts.to_stdin = formatter.stdin or builtin_formatter._opts.to_stdin + local resolved_path = validate_provider_request(builtin_formatter) + if resolved_path then + builtin_formatter._opts.command = resolved_path + table.insert(M.requested_providers, builtin_formatter) + u.lvim_log(string.format("Using format provider: [%s]", builtin_formatter.name)) + end end end @@ -89,11 +92,16 @@ function M.setup(filetype) if linter.exe == "eslint_d" then builtin_diagnoser = null_ls.builtins.diagnostics.eslint.with { command = "eslint_d" } end - -- FIXME: why doesn't this work? - -- builtin_diagnoser._opts.args = linter.args or builtin_diagnoser._opts.args - -- builtin_diagnoser._opts.to_stdin = linter.stdin or builtin_diagnoser._opts.to_stdin - if validate_provider_request(M.requested_providers, builtin_diagnoser) then - u.lvim_log(string.format("Using linter provider: [%s]", linter.exe)) + if not vim.tbl_contains(M.requested_providers, builtin_diagnoser) then + -- FIXME: why doesn't this work? + -- builtin_diagnoser._opts.args = linter.args or builtin_diagnoser._opts.args + -- builtin_diagnoser._opts.to_stdin = linter.stdin or builtin_diagnoser._opts.to_stdin + local resolved_path = validate_provider_request(builtin_diagnoser) + if resolved_path then + builtin_diagnoser._opts.command = resolved_path + table.insert(M.requested_providers, builtin_diagnoser) + u.lvim_log(string.format("Using linter provider: [%s]", builtin_diagnoser.name)) + end end end -- cgit v1.2.3 From 47ebd70817c99c657271e399c0b98b920f765f29 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Fri, 6 Aug 2021 16:27:19 +0200 Subject: Add LunarVim info panel (Experimental) (#1241) * feat: lunarvim info (Experimental) * Add missing providers info * Use nvim api directly to create the popup * width tweaks --- lua/lsp/null-ls.lua | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'lua/lsp/null-ls.lua') diff --git a/lua/lsp/null-ls.lua b/lua/lsp/null-ls.lua index 7adfa218..19727e15 100644 --- a/lua/lsp/null-ls.lua +++ b/lua/lsp/null-ls.lua @@ -23,6 +23,26 @@ function M.get_registered_providers_by_filetype(ft) return matches end +function M.get_missing_providers_by_filetype(ft) + local matches = {} + for _, provider in pairs(M.requested_providers) do + if vim.tbl_contains(provider.filetypes, ft) then + local provider_name = provider.name + + table.insert(matches, provider_name) + end + end + + return matches +end + +local function register_failed_request(ft, provider, operation) + if not lvim.lang[ft][operation]._failed_requests then + lvim.lang[ft][operation]._failed_requests = {} + end + table.insert(lvim.lang[ft][operation]._failed_requests, provider) +end + local function validate_nodejs_provider(provider) local command_path local root_dir @@ -80,6 +100,9 @@ function M.setup(filetype) builtin_formatter._opts.command = resolved_path table.insert(M.requested_providers, builtin_formatter) u.lvim_log(string.format("Using format provider: [%s]", builtin_formatter.name)) + else + -- mark it here to avoid re-doing the lookup again + register_failed_request(filetype, formatter.exe, "formatters") end end end @@ -101,6 +124,9 @@ function M.setup(filetype) builtin_diagnoser._opts.command = resolved_path table.insert(M.requested_providers, builtin_diagnoser) u.lvim_log(string.format("Using linter provider: [%s]", builtin_diagnoser.name)) + else + -- mark it here to avoid re-doing the lookup again + register_failed_request(filetype, linter.exe, "linters") end end end -- cgit v1.2.3 From 405423108fc31981c40116a827e845a1179c9053 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Mon, 9 Aug 2021 19:02:37 +0200 Subject: feat: Add an async logger using plenary (#1207) Co-authored-by: rebuilt --- lua/lsp/null-ls.lua | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'lua/lsp/null-ls.lua') diff --git a/lua/lsp/null-ls.lua b/lua/lsp/null-ls.lua index 19727e15..c5388109 100644 --- a/lua/lsp/null-ls.lua +++ b/lua/lsp/null-ls.lua @@ -1,5 +1,6 @@ local M = {} -local u = require "utils" +local Log = require "core.log" + local null_ls = require "null-ls" local nodejs_local_providers = { "prettier", "prettierd", "prettier_d_slim", "eslint_d", "eslint" } @@ -54,20 +55,21 @@ local function validate_nodejs_provider(provider) --- use LSP to set root_dir local ts_client = require("utils").get_active_client_by_ft "typescript" if ts_client == nil then - u.lvim_log "Unable to determine root directory since tsserver didn't start correctly" + Log:get_default().error "Unable to determine root directory since tsserver didn't start correctly" return end root_dir = ts_client.config.root_dir end local local_nodejs_command = root_dir .. "/node_modules/.bin/" .. provider._opts.command - u.lvim_log(string.format("checking [%s] for local node module: [%s]", local_nodejs_command, vim.inspect(provider))) + Log:get_default().debug("checking for local node module: ", vim.inspect(provider)) + if vim.fn.executable(local_nodejs_command) == 1 then command_path = local_nodejs_command elseif vim.fn.executable(provider._opts.command) == 1 then - u.lvim_log(string.format("checking in global path instead for node module: [%s]", provider._opts.command)) + Log:get_default().debug("checking in global path instead for node module", provider._opts.command) command_path = provider._opts.command else - u.lvim_log(string.format("Unable to find node module: [%s]", provider._opts.command)) + Log:get_default().debug("Unable to find node module", provider._opts.command) end return command_path end @@ -81,7 +83,7 @@ local function validate_provider_request(provider) return validate_nodejs_provider(provider) end if vim.fn.executable(provider._opts.command) ~= 1 then - u.lvim_log(string.format("Unable to find the path for: [%s]", vim.inspect(provider))) + Log:get_default().warn("Unable to find the path for", vim.inspect(provider)) return end return provider._opts.command @@ -90,6 +92,7 @@ end -- TODO: for linters and formatters with spaces and '-' replace with '_' function M.setup(filetype) for _, formatter in pairs(lvim.lang[filetype].formatters) do + Log:get_default().debug("validating format provider: ", formatter.exe) local builtin_formatter = null_ls.builtins.formatting[formatter.exe] if not vim.tbl_contains(M.requested_providers, builtin_formatter) then -- FIXME: why doesn't this work? @@ -99,7 +102,7 @@ function M.setup(filetype) if resolved_path then builtin_formatter._opts.command = resolved_path table.insert(M.requested_providers, builtin_formatter) - u.lvim_log(string.format("Using format provider: [%s]", builtin_formatter.name)) + Log:get_default().info("Using format provider", builtin_formatter.name) else -- mark it here to avoid re-doing the lookup again register_failed_request(filetype, formatter.exe, "formatters") @@ -109,6 +112,7 @@ function M.setup(filetype) for _, linter in pairs(lvim.lang[filetype].linters) do local builtin_diagnoser = null_ls.builtins.diagnostics[linter.exe] + Log:get_default().debug("validating lint provider: ", linter.exe) -- special case: fallback to "eslint" -- https://github.com/jose-elias-alvarez/null-ls.nvim/blob/9b8458bd1648e84169a7e8638091ba15c2f20fc0/doc/BUILTINS.md#eslint -- if provider.exe @@ -123,7 +127,7 @@ function M.setup(filetype) if resolved_path then builtin_diagnoser._opts.command = resolved_path table.insert(M.requested_providers, builtin_diagnoser) - u.lvim_log(string.format("Using linter provider: [%s]", builtin_diagnoser.name)) + Log:get_default().info("Using linter provider", builtin_diagnoser.name) else -- mark it here to avoid re-doing the lookup again register_failed_request(filetype, linter.exe, "linters") -- cgit v1.2.3 From 44e43e225bee70cef004529d3a62ab82f2ca1a74 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Tue, 10 Aug 2021 22:17:24 +0430 Subject: remove the violent message for provider not found (#1283) --- lua/lsp/null-ls.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lua/lsp/null-ls.lua') diff --git a/lua/lsp/null-ls.lua b/lua/lsp/null-ls.lua index c5388109..697eac39 100644 --- a/lua/lsp/null-ls.lua +++ b/lua/lsp/null-ls.lua @@ -83,7 +83,8 @@ local function validate_provider_request(provider) return validate_nodejs_provider(provider) end if vim.fn.executable(provider._opts.command) ~= 1 then - Log:get_default().warn("Unable to find the path for", vim.inspect(provider)) + Log:get_default().debug("Unable to find the path for", vim.inspect(provider)) + Log:get_default().warn("Unable to find the path for ", provider._opts.command) return end return provider._opts.command -- cgit v1.2.3