Update lua.lua
This commit is contained in:
+18
-7
@@ -24,15 +24,26 @@ M.config = {
|
|||||||
|
|
||||||
-- Function to get the project root directory
|
-- Function to get the project root directory
|
||||||
function M.get_project_root()
|
function M.get_project_root()
|
||||||
local project_root = vim.fn.expand(M.config.project_root)
|
-- Find the .polydev file in the current directory or any parent directories
|
||||||
-- You can customize this based on how your project structure looks
|
local current_dir = vim.fn.expand('%:p:h') -- Get current file's directory
|
||||||
-- Here we check if the "init.lua" exists in the directory
|
|
||||||
if vim.fn.isdirectory(project_root) == 1 then
|
-- Search upwards for the .polydev file
|
||||||
return project_root
|
local polydev_file = vim.fn.findfile(".polydev", current_dir .. ";")
|
||||||
else
|
if polydev_file == "" then
|
||||||
print("Error: Project root directory not found.")
|
print("Error: .polydev file not found in the current or parent directories.")
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Extract the name of the project from the .polydev file (excluding the extension)
|
||||||
|
local project_name = polydev_file:match("([^/]+)%.polydev$")
|
||||||
|
if not project_name then
|
||||||
|
print("Error: Unable to extract project name from .polydev file.")
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Construct the project root path based on the project name
|
||||||
|
local project_root = vim.fn.expand(M.config.project_root) .. "/" .. project_name
|
||||||
|
return project_root
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Function to setup the configuration
|
-- Function to setup the configuration
|
||||||
|
|||||||
Reference in New Issue
Block a user