37 lines
1.2 KiB
Lua
37 lines
1.2 KiB
Lua
local M = {}
|
|
|
|
function M.root(path)
|
|
local root = vim.fs.root(path, { "pubspec.yaml" })
|
|
if not root then return nil end
|
|
|
|
local pubspec = table.concat(vim.fn.readfile(root .. "/pubspec.yaml"), "\n")
|
|
if pubspec:match("\nresolution:%s*workspace%s*[^\n]*") or pubspec:match("^resolution:%s*workspace%s*[^\n]*") then
|
|
local parent = vim.fs.dirname(root)
|
|
while parent do
|
|
local candidate = vim.fs.root(parent, { "pubspec.yaml" })
|
|
if not candidate then break end
|
|
local contents = table.concat(vim.fn.readfile(candidate .. "/pubspec.yaml"), "\n")
|
|
if contents:match("\nworkspace:%s*[^\n]*") or contents:match("^workspace:%s*[^\n]*") then
|
|
return candidate
|
|
end
|
|
local next_parent = vim.fs.dirname(candidate)
|
|
if next_parent == candidate then break end
|
|
parent = next_parent
|
|
end
|
|
end
|
|
return root
|
|
end
|
|
|
|
function M.executable(root)
|
|
if root then
|
|
local fvm_dart = root .. "/.fvm/flutter_sdk/bin/dart"
|
|
if vim.fn.executable(fvm_dart) == 1 then
|
|
return fvm_dart
|
|
end
|
|
end
|
|
|
|
return "dart"
|
|
end
|
|
|
|
return M
|