Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(util.find_git_ancestor): added exclude flag (#2915) #2916

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions doc/lspconfig.txt
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,12 @@ below returns a function that takes as its argument the current buffer path.
>
root_dir = util.root_pattern('pyproject.toml', 'requirements.txt')
<
- `util.find_git_ancestor`: a function that locates the first parent directory
containing a `.git` directory.
- `util.find_git_ancestor`: a function which takes a path and an optional flag
that locates the first parent directory containing a `.git` directory or file.
>
root_dir = util.find_git_ancestor
root_dir = util.find_git_ancestor(fname, {
exclude_git_files = true
})

- `util.find_node_modules_ancestor`: a function that locates the first parent
directory containing a `node_modules` directory.
Expand Down
8 changes: 6 additions & 2 deletions lua/lspconfig/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,14 @@ function M.root_pattern(...)
end
end

function M.find_git_ancestor(startpath)
function M.find_git_ancestor(startpath, options)
local _options = {
exclude_git_files = options and options.exclude_git_files,
}

return M.search_ancestors(startpath, function(path)
-- Support git directories and git files (worktrees)
if M.path.is_dir(M.path.join(path, '.git')) or M.path.is_file(M.path.join(path, '.git')) then
if M.path.is_dir(M.path.join(path, '.git')) or (M.path.is_file(M.path.join(path, '.git')) and not _options.exclude_git_files) then
return path
end
end)
Expand Down
Loading