Skip to content

Commit 7f93847

Browse files
feat: add flutter dependency detection (#326)
Co-authored-by: mikeborodin-af <mykhailo.borodin@appsfactory.de>
1 parent b65ad58 commit 7f93847

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

lua/flutter-tools/dap.lua

+11-4
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,20 @@ end
1111

1212
local M = {}
1313

14+
local function has_flutter_dependency_in_pubspec()
15+
local pubspec = vim.fn.glob("pubspec.yaml")
16+
if pubspec == "" then return false end
17+
local pubspec_content = vim.fn.readfile(pubspec)
18+
local joined_content = table.concat(pubspec_content, "\n")
19+
20+
local flutter_dependency = string.match(joined_content, "flutter:\n[%s\t]*sdk:[%s\t]*flutter")
21+
return flutter_dependency ~= nil
22+
end
23+
1424
function M.setup(config)
1525
local opts = config.debugger
1626
require("flutter-tools.executable").get(function(paths)
17-
local root_patterns = { ".git", "pubspec.yaml" }
18-
local current_dir = vim.fn.expand("%:p:h")
19-
local root_dir = path.find_root(root_patterns, current_dir) or current_dir
20-
local is_flutter_project = vim.loop.fs_stat(path.join(root_dir, ".metadata"))
27+
local is_flutter_project = has_flutter_dependency_in_pubspec()
2128

2229
if is_flutter_project then
2330
dap.adapters.dart = {

0 commit comments

Comments
 (0)