forked from nvim-flutter/flutter-tools.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdap.lua
56 lines (50 loc) · 1.76 KB
/
dap.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
local lazy = require("flutter-tools.lazy")
local path = lazy.require("flutter-tools.utils.path") ---@module "flutter-tools.utils.path"
local ui = require("flutter-tools.ui")
local success, dap = pcall(require, "dap")
if not success then
ui.notify(string.format("nvim-dap is not installed!\n%s", dap), ui.ERROR)
return
end
local M = {}
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 function search_pubspec_for_flutter_sdk()
local pubspec_path = path.join(root_dir, "pubspec.yaml")
return pcall(vim.cmd, "silent 1vimgrep! /sdk:\\_s\\+flutter\\C/j" .. pubspec_path)
end
local is_flutter_project = vim.loop.fs_stat(path.join(root_dir, ".metadata")) or search_pubspec_for_flutter_sdk()
if is_flutter_project then
dap.adapters.dart = {
type = "executable",
command = paths.flutter_bin,
args = { "debug-adapter" },
}
opts.register_configurations(paths)
else
dap.adapters.dart = {
type = "executable",
command = paths.dart_bin,
args = { "debug_adapter" },
}
dap.configurations.dart = {
{
type = "dart",
request = "launch",
name = "Launch Dart",
dartSdkPath = paths.dart_sdk,
program = "${workspaceFolder}/bin/main.dart",
cwd = "${workspaceFolder}",
},
}
end
if opts.exception_breakpoints and type(opts.exception_breakpoints) == "table" then
dap.defaults.dart.exception_breakpoints = opts.exception_breakpoints
end
end)
end
return M