-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrooter.lua
More file actions
42 lines (35 loc) · 983 Bytes
/
rooter.lua
File metadata and controls
42 lines (35 loc) · 983 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
local M = {}
local markers = {
-- Version control systems
".git",
".hg",
".svn",
-- Python specific project markers
"pyproject.toml",
"setup.py",
"setup.cfg",
"requirements.txt",
"Pipfile",
"poetry.lock",
-- Configuration files often at project root
".python-version",
"tox.ini",
"pytest.ini",
".flake8",
".isort.cfg",
"mypy.ini",
}
--- Find the absolute path of the Python project's root. Defaults to `path`'s current directory
--- opened file if failed to locate the root.
---@param path string The absolute path to search from
---@return string root_dir_path Normalized absolute path of the project root directory.
M.find_root_dir_path = function(path)
local current_dir = vim.fs.dirname(path)
local marker_path = vim.fs.find(markers, {
path = path,
upward = true,
limit = 1,
})[1]
return marker_path and vim.fs.dirname(marker_path) or current_dir
end
return M