aboutsummaryrefslogtreecommitdiffstats
path: root/lua/lspconfig/util.lua
diff options
context:
space:
mode:
authorWuelner Martínez <wuelner.martinez@outlook.com>2023-02-11 19:43:43 -0600
committerGitHub <noreply@github.com>2023-02-12 09:43:43 +0800
commit641a71e381e23f1d1d6a0722a8b796fda896b55b (patch)
tree1c06a8c91d0aa6bc87f4dc0ec31331b223c5928a /lua/lspconfig/util.lua
parentdocs: update server_configurations.md (diff)
downloadnvim-lspconfig-641a71e381e23f1d1d6a0722a8b796fda896b55b.tar
nvim-lspconfig-641a71e381e23f1d1d6a0722a8b796fda896b55b.tar.gz
nvim-lspconfig-641a71e381e23f1d1d6a0722a8b796fda896b55b.tar.bz2
nvim-lspconfig-641a71e381e23f1d1d6a0722a8b796fda896b55b.tar.lz
nvim-lspconfig-641a71e381e23f1d1d6a0722a8b796fda896b55b.tar.xz
nvim-lspconfig-641a71e381e23f1d1d6a0722a8b796fda896b55b.tar.zst
nvim-lspconfig-641a71e381e23f1d1d6a0722a8b796fda896b55b.zip
fix(stylelint_lsp): update root directory pattern (#2447)
* fix(stylelint_lsp): update root directory pattern Signed-off-by: Wuelner Martínez <wuelner.martinez@outlook.com> * feat(util): add `add_package_json_to_config_files_if_field_exists` function Signed-off-by: Wuelner Martínez <wuelner.martinez@outlook.com> * fix(stylelint_lsp): update update root directory pattern implementation Signed-off-by: Wuelner Martínez <wuelner.martinez@outlook.com> * fix(eslint): update update root directory pattern implementation Signed-off-by: Wuelner Martínez <wuelner.martinez@outlook.com> * fix(util): update `is_windows` detection Co-authored-by: Raphael <glephunter@gmail.com> * fix(util): update new function name Co-authored-by: Raphael <glephunter@gmail.com> * fix(server_configurations): update new function name implementation Signed-off-by: Wuelner Martínez <wuelner.martinez@outlook.com> * fix(stylelint_lsp): fix duplicate equals Signed-off-by: Wuelner Martínez <wuelner.martinez@outlook.com> --------- Signed-off-by: Wuelner Martínez <wuelner.martinez@outlook.com> Co-authored-by: Raphael <glephunter@gmail.com>
Diffstat (limited to 'lua/lspconfig/util.lua')
-rw-r--r--lua/lspconfig/util.lua19
1 files changed, 17 insertions, 2 deletions
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 = {}