diff options
| author | Stéphan Kochen <git@stephank.nl> | 2022-08-23 14:28:28 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-23 20:28:28 +0800 |
| commit | 7305324e12c97ea778b480ddc045f38171f203e1 (patch) | |
| tree | 6b66a2f7b6f1249d24ba614fed8114114f8efef4 | |
| parent | docs: update server_configurations.md (diff) | |
| download | nvim-lspconfig-7305324e12c97ea778b480ddc045f38171f203e1.tar nvim-lspconfig-7305324e12c97ea778b480ddc045f38171f203e1.tar.gz nvim-lspconfig-7305324e12c97ea778b480ddc045f38171f203e1.tar.bz2 nvim-lspconfig-7305324e12c97ea778b480ddc045f38171f203e1.tar.lz nvim-lspconfig-7305324e12c97ea778b480ddc045f38171f203e1.tar.xz nvim-lspconfig-7305324e12c97ea778b480ddc045f38171f203e1.tar.zst nvim-lspconfig-7305324e12c97ea778b480ddc045f38171f203e1.zip | |
feat: allow attaching to paths inside archives (#1687)
| -rw-r--r-- | lua/lspconfig/util.lua | 18 | ||||
| -rw-r--r-- | test/lspconfig_spec.lua | 23 |
2 files changed, 38 insertions, 3 deletions
diff --git a/lua/lspconfig/util.lua b/lua/lspconfig/util.lua index 09a22163..956be435 100644 --- a/lua/lspconfig/util.lua +++ b/lua/lspconfig/util.lua @@ -21,11 +21,13 @@ M.default_config = { M.on_setup = nil function M.bufname_valid(bufname) - if bufname and bufname ~= '' and (bufname:match '^([a-zA-Z]:).*' or bufname:match '^/') then - return true - else + if not bufname then return false end + if bufname:match '^/' or bufname:match '^[a-zA-Z]:' or bufname:match '^zipfile://' or bufname:match '^tarfile:' then + return true + end + return false end function M.validate_bufnr(bufnr) @@ -341,6 +343,7 @@ function M.root_pattern(...) end end return function(startpath) + startpath = M.strip_archive_subpath(startpath) return M.search_ancestors(startpath, matcher) end end @@ -437,4 +440,13 @@ function M.get_managed_clients() return clients end +-- For zipfile: or tarfile: virtual paths, returns the path to the archive. +-- Other paths are returned unaltered. +function M.strip_archive_subpath(path) + -- Matches regex from zip.vim / tar.vim + path = vim.fn.substitute(path, 'zipfile://\\(.\\{-}\\)::[^\\\\].*$', '\\1', '') + path = vim.fn.substitute(path, 'tarfile:\\(.\\{-}\\)::.*$', '\\1', '') + return path +end + return M diff --git a/test/lspconfig_spec.lua b/test/lspconfig_spec.lua index 8fc117c5..89effd47 100644 --- a/test/lspconfig_spec.lua +++ b/test/lspconfig_spec.lua @@ -190,6 +190,29 @@ describe('lspconfig', function() ]]) end) end) + + describe('strip_archive_subpath', function() + it('strips zipfile subpaths', function() + ok(exec_lua [[ + local lspconfig = require("lspconfig") + return lspconfig.util.strip_archive_subpath("zipfile:///one/two.zip::three/four") == "/one/two.zip" + ]]) + end) + + it('strips tarfile subpaths', function() + ok(exec_lua [[ + local lspconfig = require("lspconfig") + return lspconfig.util.strip_archive_subpath("tarfile:/one/two.tgz::three/four") == "/one/two.tgz" + ]]) + end) + + it('returns non-archive paths as-is', function() + ok(exec_lua [[ + local lspconfig = require("lspconfig") + return lspconfig.util.strip_archive_subpath("/one/two.zip") == "/one/two.zip" + ]]) + end) + end) end) describe('config', function() it('normalizes user, server, and base default configs', function() |
