diff options
| -rw-r--r-- | .github/ci/lint.sh | 5 | ||||
| -rw-r--r-- | lsp/fennel_ls.lua | 4 | ||||
| -rw-r--r-- | lsp/foam_ls.lua | 4 | ||||
| -rw-r--r-- | lsp/vala_ls.lua | 4 | ||||
| -rw-r--r-- | lua/lspconfig/util.lua | 43 |
5 files changed, 30 insertions, 30 deletions
diff --git a/.github/ci/lint.sh b/.github/ci/lint.sh index 7b16c8fc..6a030e16 100644 --- a/.github/ci/lint.sh +++ b/.github/ci/lint.sh @@ -52,6 +52,11 @@ _check_deprecated_in_nvim_0_11() { echo 'Use vim.fs.relpath() instead of util.path.is_descendant()' exit 1 fi + if git grep -P 'search_ancestors' -- 'lsp/*.lua' ; then + echo + echo 'Use vim.iter(vim.fs.parents(fname)):find(…) instead of util.path.search_ancestors(fname,…)' + exit 1 + fi } _check_deprecated_utils() { diff --git a/lsp/fennel_ls.lua b/lsp/fennel_ls.lua index bbcb0a99..4023e021 100644 --- a/lsp/fennel_ls.lua +++ b/lsp/fennel_ls.lua @@ -7,8 +7,6 @@ --- fennel-ls is configured using the closest file to your working directory named `flsproject.fnl`. --- All fennel-ls configuration options [can be found here](https://git.sr.ht/~xerool/fennel-ls/tree/HEAD/docs/manual.md#configuration). -local util = require 'lspconfig.util' - return { cmd = { 'fennel-ls' }, filetypes = { 'fennel' }, @@ -18,7 +16,7 @@ return { local fnlpath = vim.fs.joinpath(path, 'flsproject.fnl') return (vim.uv.fs_stat(fnlpath) or {}).type == 'file' end - on_dir(util.search_ancestors(fname, has_fls_project_cfg) or vim.fs.root(0, '.git')) + on_dir(vim.iter(vim.fs.parents(fname)):find(has_fls_project_cfg) or vim.fs.root(0, '.git')) end, settings = {}, capabilities = { diff --git a/lsp/foam_ls.lua b/lsp/foam_ls.lua index c7a47f3c..bbc9d728 100644 --- a/lsp/foam_ls.lua +++ b/lsp/foam_ls.lua @@ -7,14 +7,12 @@ --- npm install -g foam-language-server --- ``` -local util = require 'lspconfig.util' - return { cmd = { 'foam-ls', '--stdio' }, filetypes = { 'foam', 'OpenFOAM' }, root_dir = function(bufnr, on_dir) local fname = vim.api.nvim_buf_get_name(bufnr) - on_dir(util.search_ancestors(fname, function(path) + on_dir(vim.iter(vim.fs.parents(fname)):find(function(path) if vim.uv.fs_stat(path .. '/system/controlDict') then return path end diff --git a/lsp/vala_ls.lua b/lsp/vala_ls.lua index 3faff1d8..a2d9059f 100644 --- a/lsp/vala_ls.lua +++ b/lsp/vala_ls.lua @@ -2,8 +2,6 @@ --- --- https://github.com/Prince781/vala-language-server -local util = require 'lspconfig.util' - local meson_matcher = function(path) local pattern = 'meson.build' local f = vim.fn.glob(table.concat({ path, pattern }, '/')) @@ -30,7 +28,7 @@ return { filetypes = { 'vala', 'genie' }, root_dir = function(bufnr, on_dir) local fname = vim.api.nvim_buf_get_name(bufnr) - local root = util.search_ancestors(fname, meson_matcher) + local root = vim.iter(vim.fs.parents(fname)):find(meson_matcher) on_dir(root or vim.fs.dirname(vim.fs.find('.git', { path = fname, upward = true })[1])) end, } diff --git a/lua/lspconfig/util.lua b/lua/lspconfig/util.lua index 2fcda8bf..f4322281 100644 --- a/lua/lspconfig/util.lua +++ b/lua/lspconfig/util.lua @@ -34,27 +34,6 @@ function M.validate_bufnr(bufnr) return bufnr == 0 and api.nvim_get_current_buf() or bufnr end -function M.search_ancestors(startpath, func) - if nvim_eleven then - validate('func', func, 'function') - end - if func(startpath) then - return startpath - end - local guard = 100 - for path in vim.fs.parents(startpath) do - -- Prevent infinite recursion if our algorithm breaks - guard = guard - 1 - if guard == 0 then - return - end - - if func(path) then - return path - end - end -end - local function escape_wildcards(path) return path:gsub('([%[%]%?%*])', '\\%1') end @@ -114,6 +93,28 @@ end --- --- Deprecated in Nvim 0.11 +function M.search_ancestors(startpath, func) + if nvim_eleven then + validate('func', func, 'function') + end + if func(startpath) then + return startpath + end + local guard = 100 + for path in vim.fs.parents(startpath) do + -- Prevent infinite recursion if our algorithm breaks + guard = guard - 1 + if guard == 0 then + return + end + + if func(path) then + return path + end + end +end + +--- Deprecated in Nvim 0.11 local function is_fs_root(path) if iswin then return path:match '^%a:$' |
