From 2a6517453feb6f00e3d64bcb4fde61934897f4bd Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 4 May 2025 14:11:18 -0700 Subject: fix(configs): eliminate some usages of root_pattern #3820 Problem: `root_pattern` is not necessary for non-glob patterns. Solution: Replace non-glob cases with `vim.fs.root()`.. --- lua/lspconfig/util.lua | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lua/lspconfig/util.lua') diff --git a/lua/lspconfig/util.lua b/lua/lspconfig/util.lua index 2807edf3..5d9c213c 100644 --- a/lua/lspconfig/util.lua +++ b/lua/lspconfig/util.lua @@ -24,6 +24,9 @@ local function escape_wildcards(path) return path:gsub('([%[%]%?%*])', '\\%1') end +--- Returns a function which matches a filepath against the given glob/wildcard patterns. +--- +--- Also works with zipfile:/tarfile: buffers (via `strip_archive_subpath`). function M.root_pattern(...) local patterns = M.tbl_flatten { ... } return function(startpath) @@ -44,6 +47,11 @@ function M.root_pattern(...) end end +--- Appends package.json-like files to the `config_files` list if `field` +--- is found in any such file in any ancestor of `fname`. +--- +--- NOTE: this does a "breadth-first" search, so is broken for multi-project workspaces: +--- https://github.com/neovim/nvim-lspconfig/issues/3818#issuecomment-2848836794 function M.insert_package_json(config_files, field, fname) local path = vim.fn.fnamemodify(fname, ':h') local root_with_package = vim.fs.find({ 'package.json', 'package.json5' }, { path = path, upward = true })[1] -- cgit v1.2.3-70-g09d2