diff options
| author | dundargoc <gocdundar@gmail.com> | 2025-01-18 16:09:05 +0100 |
|---|---|---|
| committer | dundargoc <33953936+dundargoc@users.noreply.github.com> | 2025-01-19 22:09:13 +0100 |
| commit | 9ee2e7dac2e1c74538a0e0d79b9e2d59a8517bd6 (patch) | |
| tree | 6f84b6dceb38267ebe855f82548b99959d75638b /lua/lspconfig/util.lua | |
| parent | docs: update configs.md (diff) | |
| download | nvim-lspconfig-9ee2e7dac2e1c74538a0e0d79b9e2d59a8517bd6.tar nvim-lspconfig-9ee2e7dac2e1c74538a0e0d79b9e2d59a8517bd6.tar.gz nvim-lspconfig-9ee2e7dac2e1c74538a0e0d79b9e2d59a8517bd6.tar.bz2 nvim-lspconfig-9ee2e7dac2e1c74538a0e0d79b9e2d59a8517bd6.tar.lz nvim-lspconfig-9ee2e7dac2e1c74538a0e0d79b9e2d59a8517bd6.tar.xz nvim-lspconfig-9ee2e7dac2e1c74538a0e0d79b9e2d59a8517bd6.tar.zst nvim-lspconfig-9ee2e7dac2e1c74538a0e0d79b9e2d59a8517bd6.zip | |
refactor: comment util.path.is_descendant to prepare deperecation in future
We don't deprecate it currently as the suggested replacement
(vim.fs.relpath) isn't available on the minimum supported neovim
version.
Work on https://github.com/neovim/nvim-lspconfig/issues/2079.
Diffstat (limited to 'lua/lspconfig/util.lua')
| -rw-r--r-- | lua/lspconfig/util.lua | 100 |
1 files changed, 47 insertions, 53 deletions
diff --git a/lua/lspconfig/util.lua b/lua/lspconfig/util.lua index e2bba2e1..56013415 100644 --- a/lua/lspconfig/util.lua +++ b/lua/lspconfig/util.lua @@ -5,7 +5,7 @@ local nvim_eleven = vim.fn.has 'nvim-0.11' == 1 local iswin = vim.loop.os_uname().version:match 'Windows' -local M = {} +local M = { path = {} } M.default_config = { log_level = lsp.protocol.MessageType.Warning, @@ -95,57 +95,6 @@ function M.create_module_commands(module_name, commands) end end --- Some path utilities -M.path = (function() - --- @param path string - --- @return boolean - local function is_fs_root(path) - if iswin then - return path:match '^%a:$' - else - return path == '/' - end - end - - -- Traverse the path calling cb along the way. - local function traverse_parents(path, cb) - path = vim.loop.fs_realpath(path) - local dir = path - -- Just in case our algo is buggy, don't infinite loop. - for _ = 1, 100 do - dir = vim.fs.dirname(dir) - if not dir then - return - end - -- If we can't ascend further, then stop looking. - if cb(dir, path) then - return dir, path - end - if is_fs_root(dir) then - break - end - end - end - - local function is_descendant(root, path) - if not path then - return false - end - - local function cb(dir, _) - return dir == root - end - - local dir, _ = traverse_parents(path, cb) - - return dir == root - end - - return { - is_descendant = is_descendant, - } -end)() - function M.search_ancestors(startpath, func) if nvim_eleven then validate('func', func, 'function') @@ -294,7 +243,52 @@ function M.strip_archive_subpath(path) return path end ---- Functions that can be removed once minimum required neovim version is high enough +--- Public functions that can be deprecated once minimum required neovim version is high enough + +local function is_fs_root(path) + if iswin then + return path:match '^%a:$' + else + return path == '/' + end +end + +-- Traverse the path calling cb along the way. +local function traverse_parents(path, cb) + path = vim.loop.fs_realpath(path) + local dir = path + -- Just in case our algo is buggy, don't infinite loop. + for _ = 1, 100 do + dir = vim.fs.dirname(dir) + if not dir then + return + end + -- If we can't ascend further, then stop looking. + if cb(dir, path) then + return dir, path + end + if is_fs_root(dir) then + break + end + end +end + +--- This can be replaced with `vim.fs.relpath` once minimum neovim version is at least 0.11. +function M.path.is_descendant(root, path) + if not path then + return false + end + + local function cb(dir, _) + return dir == root + end + + local dir, _ = traverse_parents(path, cb) + + return dir == root +end + +--- Helper functions that can be removed once minimum required neovim version is high enough function M.tbl_flatten(t) --- @diagnostic disable-next-line:deprecated |
