From 641a71e381e23f1d1d6a0722a8b796fda896b55b Mon Sep 17 00:00:00 2001 From: Wuelner Martínez Date: Sat, 11 Feb 2023 19:43:43 -0600 Subject: fix(stylelint_lsp): update root directory pattern (#2447) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(stylelint_lsp): update root directory pattern Signed-off-by: Wuelner Martínez * feat(util): add `add_package_json_to_config_files_if_field_exists` function Signed-off-by: Wuelner Martínez * fix(stylelint_lsp): update update root directory pattern implementation Signed-off-by: Wuelner Martínez * fix(eslint): update update root directory pattern implementation Signed-off-by: Wuelner Martínez * fix(util): update `is_windows` detection Co-authored-by: Raphael * fix(util): update new function name Co-authored-by: Raphael * fix(server_configurations): update new function name implementation Signed-off-by: Wuelner Martínez * fix(stylelint_lsp): fix duplicate equals Signed-off-by: Wuelner Martínez --------- Signed-off-by: Wuelner Martínez Co-authored-by: Raphael --- lua/lspconfig/util.lua | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'lua/lspconfig/util.lua') diff --git a/lua/lspconfig/util.lua b/lua/lspconfig/util.lua index 698cd2d9..ae2b1ada 100644 --- a/lua/lspconfig/util.lua +++ b/lua/lspconfig/util.lua @@ -4,6 +4,8 @@ local api = vim.api local lsp = vim.lsp local uv = vim.loop +local is_windows = uv.os_uname().sysname == 'Windows_NT' + local M = {} M.default_config = { @@ -94,8 +96,6 @@ end -- Some path utilities M.path = (function() - local is_windows = uv.os_uname().version:match 'Windows' - local function escape_wildcards(path) return path:gsub('([%[%]%?%*])', '\\%1') end @@ -487,6 +487,21 @@ function M.find_package_json_ancestor(startpath) end) end +function M.insert_package_json(config_files, field) + local root_with_package = M.find_package_json_ancestor(vim.fn.expand '%:p:h') + + if root_with_package then + -- only add package.json if it contains field parameter + local path_sep = is_windows and '\\' or '/' + for line in io.lines(root_with_package .. path_sep .. 'package.json') do + if line:find(field) then + return table.insert(config_files, 'package.json') + end + end + end + return config_files +end + function M.get_active_clients_list_by_ft(filetype) local clients = vim.lsp.get_active_clients() local clients_list = {} -- cgit v1.2.3-70-g09d2