aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordundargoc <gocdundar@gmail.com>2024-12-13 14:02:48 +0100
committerdundargoc <33953936+dundargoc@users.noreply.github.com>2024-12-13 14:31:20 +0100
commitf675f8c430ae3012f6d140899c2cec3b59e9cb43 (patch)
treeff617d1fe953f467dfdd7d3f20a511f220e877fc
parentdocs: update configs.md (diff)
downloadnvim-lspconfig-f675f8c430ae3012f6d140899c2cec3b59e9cb43.tar
nvim-lspconfig-f675f8c430ae3012f6d140899c2cec3b59e9cb43.tar.gz
nvim-lspconfig-f675f8c430ae3012f6d140899c2cec3b59e9cb43.tar.bz2
nvim-lspconfig-f675f8c430ae3012f6d140899c2cec3b59e9cb43.tar.lz
nvim-lspconfig-f675f8c430ae3012f6d140899c2cec3b59e9cb43.tar.xz
nvim-lspconfig-f675f8c430ae3012f6d140899c2cec3b59e9cb43.tar.zst
nvim-lspconfig-f675f8c430ae3012f6d140899c2cec3b59e9cb43.zip
refactor: deprecate util.find_package_json_ancestor
Work on https://github.com/neovim/nvim-lspconfig/issues/2079.
-rw-r--r--.github/ci/run_sanitizer.sh2
-rw-r--r--doc/lspconfig.txt16
-rw-r--r--lua/lspconfig/configs/cssmodules_ls.lua6
-rw-r--r--lua/lspconfig/configs/pug.lua6
-rw-r--r--lua/lspconfig/configs/rome.lua2
-rw-r--r--lua/lspconfig/configs/tailwindcss.lua2
-rw-r--r--lua/lspconfig/util.lua16
7 files changed, 27 insertions, 23 deletions
diff --git a/.github/ci/run_sanitizer.sh b/.github/ci/run_sanitizer.sh
index 8adeaafa..9f6fd358 100644
--- a/.github/ci/run_sanitizer.sh
+++ b/.github/ci/run_sanitizer.sh
@@ -15,7 +15,7 @@ if git diff --pickaxe-all -U0 -G "${SEARCH_PATTERN}" "${REF_BRANCH}" "${PR_BRANC
exit 1
fi
-SEARCH_PATTERN='(util\.path\.dirname|util\.path\.sanitize|util\.path\.exists|util\.path\.is_file|util\.path\.is_dir|util\.find_mercurial_ancestor|util\.find_node_modules_ancestor)'
+SEARCH_PATTERN='(util\.path\.dirname|util\.path\.sanitize|util\.path\.exists|util\.path\.is_file|util\.path\.is_dir|util\.find_mercurial_ancestor|util\.find_node_modules_ancestor|util\.find_package_json_ancestor)'
if git diff --pickaxe-all -U0 -G "${SEARCH_PATTERN}" "${REF_BRANCH}" "${PR_BRANCH}" -- '*.lua' | grep -Ev '\.lua$' | grep -E "^\+.*${SEARCH_PATTERN}" ; then
echo
diff --git a/doc/lspconfig.txt b/doc/lspconfig.txt
index 0590a5d4..f9ba9bfb 100644
--- a/doc/lspconfig.txt
+++ b/doc/lspconfig.txt
@@ -304,10 +304,18 @@ below returns a function that takes as its argument the current buffer path.
vim.fs.root(root_dir, "node_modules")
<
can be used instead.
- - Note: The old `util.find_node_modules_ancestor` API is deprecated and will be removed.
-- `util.find_package_json_ancestor`: a function that locates the first parent
- directory containing a `package.json`. >
- root_dir = util.find_package_json_ancestor
+ - Note: The old `util.find_node_modules_ancestor` API is deprecated and will
+ be removed.
+
+- Locate the first parent dir containing a "package.json" dir: >lua
+ vim.fs.find('package.json', { path = root_dir, upward = true })[1]
+<
+ If you have Nvim 0.10 or newer then >lua
+ vim.fs.root(root_dir, "package.json")
+<
+ can be used instead.
+ - Note: The old `util.find_package_json_ancestor` API is deprecated and will
+ be removed.
<
Note: On Windows, `lspconfig` always assumes forward slash normalized paths with
capitalized drive letters.
diff --git a/lua/lspconfig/configs/cssmodules_ls.lua b/lua/lspconfig/configs/cssmodules_ls.lua
index 28973be7..b05d66ff 100644
--- a/lua/lspconfig/configs/cssmodules_ls.lua
+++ b/lua/lspconfig/configs/cssmodules_ls.lua
@@ -1,10 +1,10 @@
-local util = require 'lspconfig.util'
-
return {
default_config = {
cmd = { 'cssmodules-language-server' },
filetypes = { 'javascript', 'javascriptreact', 'typescript', 'typescriptreact' },
- root_dir = util.find_package_json_ancestor,
+ root_dir = function(fname)
+ return vim.fs.find('package.json', { path = fname, upward = true })[1]
+ end,
},
docs = {
description = [[
diff --git a/lua/lspconfig/configs/pug.lua b/lua/lspconfig/configs/pug.lua
index 28f7db61..444e9830 100644
--- a/lua/lspconfig/configs/pug.lua
+++ b/lua/lspconfig/configs/pug.lua
@@ -1,10 +1,10 @@
-local util = require 'lspconfig.util'
-
return {
default_config = {
cmd = { 'pug-lsp' },
filetypes = { 'pug' },
- root_dir = util.find_package_json_ancestor,
+ root_dir = function(fname)
+ return vim.fs.find('package.json', { path = fname, upward = true })[1]
+ end,
},
docs = {
description = [[
diff --git a/lua/lspconfig/configs/rome.lua b/lua/lspconfig/configs/rome.lua
index 831469e4..09a3e6c4 100644
--- a/lua/lspconfig/configs/rome.lua
+++ b/lua/lspconfig/configs/rome.lua
@@ -12,7 +12,7 @@ return {
'typescriptreact',
},
root_dir = function(fname)
- return util.find_package_json_ancestor(fname)
+ return vim.fs.find('package.json', { path = fname, upward = true })[1]
or vim.fs.find('node_modules', { path = fname, upward = true })[1]
or util.find_git_ancestor(fname)
end,
diff --git a/lua/lspconfig/configs/tailwindcss.lua b/lua/lspconfig/configs/tailwindcss.lua
index 56ed05b4..994e90f6 100644
--- a/lua/lspconfig/configs/tailwindcss.lua
+++ b/lua/lspconfig/configs/tailwindcss.lua
@@ -109,7 +109,7 @@ return {
'postcss.config.cjs',
'postcss.config.mjs',
'postcss.config.ts'
- )(fname) or util.find_package_json_ancestor(fname) or vim.fs.find(
+ )(fname) or vim.fs.find('package.json', { path = fname, upward = true })[1] or vim.fs.find(
'node_modules',
{ path = fname, upward = true }
)[1] or util.find_git_ancestor(fname)
diff --git a/lua/lspconfig/util.lua b/lua/lspconfig/util.lua
index 7b894ee3..a5cf67fd 100644
--- a/lua/lspconfig/util.lua
+++ b/lua/lspconfig/util.lua
@@ -246,18 +246,9 @@ function M.find_git_ancestor(startpath)
end)
end
-function M.find_package_json_ancestor(startpath)
- return M.search_ancestors(startpath, function(path)
- local jsonpath = M.path.join(path, 'package.json')
- if (vim.loop.fs_stat(jsonpath) or {}).type == 'file' then
- return path
- end
- end)
-end
-
function M.insert_package_json(config_files, field, fname)
local path = vim.fn.fnamemodify(fname, ':h')
- local root_with_package = M.find_package_json_ancestor(path)
+ local root_with_package = vim.fs.find('package.json', { path = path, upward = true })[1]
if root_with_package then
-- only add package.json if it contains field parameter
@@ -397,4 +388,9 @@ function M.find_node_modules_ancestor(startpath)
return vim.fs.find('node_modules', { path = startpath, upward = true })[1]
end
+--- @deprecated use `vim.fs.find('package.json', { path = startpath, upward = true })[1]` instead
+function M.find_package_json_ancestor(startpath)
+ return vim.fs.find('package.json', { path = startpath, upward = true })[1]
+end
+
return M