-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- custom maps - better root detection - integrate java-test & java-debug
- Loading branch information
1 parent
772885b
commit 16cd2e8
Showing
2 changed files
with
99 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
local M = {} | ||
|
||
local getparent = function(p) | ||
return vim.fn.fnamemodify(p, ':h') | ||
end | ||
local function find_root(markers, dirname) | ||
while getparent(dirname) ~= dirname do | ||
for _, marker in ipairs(markers) do | ||
if vim.loop.fs_stat(dirname .. '/' .. marker) then | ||
return dirname | ||
end | ||
end | ||
dirname = getparent(dirname) | ||
end | ||
end | ||
|
||
|
||
--- file pattern based root directory detection with priority | ||
---@param patterns table<table<string>> Two-dimensional array for detect file pattern | ||
function M.detect_root(patterns) | ||
local bufname = vim.api.nvim_buf_get_name(vim.api.nvim_get_current_buf()) | ||
local dirname = vim.fn.fnamemodify(bufname, ':p:h') | ||
for _, list in ipairs(patterns) do | ||
local root_path = find_root(list, dirname) | ||
if root_path ~= nil then | ||
return root_path | ||
end | ||
end | ||
end | ||
|
||
|
||
return M |