feat/pack (#1)
Reviewed-on: #1 Co-authored-by: Tomas Mirchev <contact@tomastm.com> Co-committed-by: Tomas Mirchev <contact@tomastm.com>
This commit was merged in pull request #1.
This commit is contained in:
@@ -1,33 +1,24 @@
|
||||
-- utils.lua
|
||||
local M = {}
|
||||
|
||||
--- Appends `new_names` to `root_files` 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
|
||||
---
|
||||
--- @param root_files string[] List of root-marker files to append to.
|
||||
--- @param new_names string[] Potential root-marker filenames (e.g. `{ 'package.json', 'package.json5' }`) to inspect for the given `field`.
|
||||
--- @param field string Field to search for in the given `new_names` files.
|
||||
--- @param fname string Full path of the current buffer name to start searching upwards from.
|
||||
function M.root_markers_with_field(root_files, new_names, field, fname)
|
||||
local path = vim.fn.fnamemodify(fname, ':h')
|
||||
local found = vim.fs.find(new_names, { path = path, upward = true })
|
||||
function M.await(fn, timeout, interval)
|
||||
local done = false
|
||||
local ok, data
|
||||
|
||||
for _, f in ipairs(found or {}) do
|
||||
-- Match the given `field`.
|
||||
for line in io.lines(f) do
|
||||
if line:find(field) then
|
||||
root_files[#root_files + 1] = vim.fs.basename(f)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
-- Wrap resolve in vim.schedule so it runs on main loop
|
||||
fn(function(success, result)
|
||||
vim.schedule(function()
|
||||
done = true
|
||||
ok = success
|
||||
data = result
|
||||
end)
|
||||
end)
|
||||
|
||||
return root_files
|
||||
end
|
||||
vim.wait(timeout, function()
|
||||
return done
|
||||
end, interval)
|
||||
|
||||
function M.insert_package_json(root_files, field, fname)
|
||||
return M.root_markers_with_field(root_files, { 'package.json', 'package.json5' }, field, fname)
|
||||
return { ok = ok or false, data = data }
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user