2023-09-17 07:58:53 +00:00
|
|
|
-- Return the node_modules path for this project. If the project root contains a
|
|
|
|
-- frontend/ directory, assume node_modules lives there.
|
|
|
|
function Get_project_node_modules_path()
|
2023-09-19 05:21:43 +00:00
|
|
|
local root_path = vim.fn.getcwd()
|
|
|
|
local frontend_path = root_path .. "/frontend"
|
|
|
|
local is_frontend = vim.fn.isdirectory(frontend_path) ~= 0
|
|
|
|
local base_path = root_path
|
|
|
|
if is_frontend then
|
|
|
|
base_path = frontend_path
|
|
|
|
end
|
|
|
|
return base_path .. "/node_modules"
|
2023-09-17 07:58:53 +00:00
|
|
|
end
|
2023-09-22 03:33:39 +00:00
|
|
|
|
|
|
|
-- Return the project's go module path from go.mod, or an empty string if the file cannot be read.
|
|
|
|
function Get_project_go_module_path()
|
|
|
|
local root_path = vim.fn.getcwd()
|
|
|
|
local mod_path = root_path .. "/go.mod"
|
|
|
|
if vim.fn.filereadable(mod_path) == 0 then
|
|
|
|
return ""
|
|
|
|
end
|
|
|
|
|
|
|
|
local file = io.open(mod_path, "r")
|
|
|
|
if file == nil then
|
|
|
|
return ""
|
|
|
|
end
|
|
|
|
|
|
|
|
io.input(file)
|
|
|
|
-- The first line of go.mod, something like:
|
|
|
|
-- module github.com/username/repo
|
|
|
|
local line = io.read()
|
|
|
|
io.close(file)
|
|
|
|
|
|
|
|
local match = string.match(line, "^module (.+)")
|
|
|
|
if match == nil then
|
|
|
|
return ""
|
|
|
|
end
|
|
|
|
|
|
|
|
return match
|
|
|
|
end
|