Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add flutter dependency detection #326

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions lua/flutter-tools/dap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@ end

local M = {}

local function has_flutter_dependency_in_pubspec()
local pubspec = vim.fn.glob("pubspec.yaml")
if pubspec == "" then return false end
local pubspec_content = vim.fn.readfile(pubspec)
local joined_content = table.concat(pubspec_content, "\n")

local flutter_dependency = string.match(joined_content, "flutter:\n[%s\t]*sdk:[%s\t]*flutter")
return flutter_dependency ~= nil
end

function M.setup(config)
local opts = config.debugger
require("flutter-tools.executable").get(function(paths)
local root_patterns = { ".git", "pubspec.yaml" }
local current_dir = vim.fn.expand("%:p:h")
local root_dir = path.find_root(root_patterns, current_dir) or current_dir
local is_flutter_project = vim.loop.fs_stat(path.join(root_dir, ".metadata"))
local is_flutter_project = has_flutter_dependency_in_pubspec()

if is_flutter_project then
dap.adapters.dart = {
Expand Down