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

fix(dap): improve debugger integration with nvim-dap #455

Merged
merged 1 commit into from
Mar 16, 2025
Merged
Show file tree
Hide file tree
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
36 changes: 10 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,12 @@ require("flutter-tools").setup {
-- Invoking toString() has a performance cost and may introduce side-effects,
-- although users may expected this functionality. null is treated like false.
evaluate_to_string_in_debug_views = true,
register_configurations = function(paths)
require("dap").configurations.dart = {
--put here config that you would find in .vscode/launch.json
}
-- If you want to load .vscode launch.json automatically run the following:
-- require("dap.ext.vscode").load_launchjs()
end,
-- You can use the `debugger.register_configurations` to register custom runner configuration (for example for different targets or flavor). Plugin automatically registers the default configuration, but you can override it or add new ones.
-- register_configurations = function(paths)
-- require("dap").configurations.dart = {
-- -- your custom configuration
-- }
-- end,
},
flutter_path = "<full/path/if/needed>", -- <-- this takes priority over the lookup
flutter_lookup_cmd = nil, -- example "dirname $(which flutter)" or "asdf where flutter"
Expand Down Expand Up @@ -438,28 +437,13 @@ This can be accessed using `Telescope flutter fvm` or `require('telescope').exte
_Requires nvim-dap_

```lua
-- with packer
use 'mfussenegger/nvim-dap'
-- with lazy
return { 'mfussenegger/nvim-dap' }
```

This plugin integrates with [nvim-dap](https://github.com/mfussenegger/nvim-dap) to provide debug capabilities.
Currently if `debugger.enabled` is set to `true` in the user's config **it will expect `nvim-dap` to be installed**.
If `dap` is this plugin will use `flutter` or `dart` native debugger to debug your project.

You can use the `debugger.register_configurations` to register custom runner configuration (for example for different targets or flavor).
If your flutter repo contains launch configurations in `.vscode/launch.json` you can use them via this config :

```lua
debugger = {
enabled = true,
register_configurations = function(_)
require("dap").configurations.dart = {}
require("dap.ext.vscode").load_launchjs()
end,
},
```
This plugin integrates with [nvim-dap](https://github.com/mfussenegger/nvim-dap) to provide debug capabilities for Flutter and Dart applications.

Since there is an overlap between this plugin's log buffer and the repl buffer when running via dap, you may use the `dev_log.enabled` configuration option if you want.
The plugin will automatically set up `nvim-dap` for Flutter/Dart debugging.

Also see:

Expand Down
2 changes: 1 addition & 1 deletion lua/flutter-tools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ local function start()
if not _setup_started then
_setup_started = true
setup_commands()
if config.debugger.enabled then dap.setup(config) end
dap.setup(config)
if config.widget_guides.enabled then guides.setup() end
if config.decorations then decorations.apply(config.decorations) end
end
Expand Down
24 changes: 9 additions & 15 deletions lua/flutter-tools/dap.lua
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
local lazy = require("flutter-tools.lazy")
local ui = lazy.require("flutter-tools.ui") ---@module "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(_)
if opts.exception_breakpoints and type(opts.exception_breakpoints) == "table" then
dap.defaults.dart.exception_breakpoints = opts.exception_breakpoints
end
end)
local success, dap = pcall(require, "dap")
if success then
local opts = config.debugger
require("flutter-tools.executable").get(function(_)
if opts.exception_breakpoints and type(opts.exception_breakpoints) == "table" then
dap.defaults.dart.exception_breakpoints = opts.exception_breakpoints
end
end)
end
end

return M
6 changes: 5 additions & 1 deletion lua/flutter-tools/runners/debugger_runner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ local config = lazy.require("flutter-tools.config") ---@module "flutter-tools.co
local utils = lazy.require("flutter-tools.utils") ---@module "flutter-tools.utils"
local path = lazy.require("flutter-tools.utils.path") ---@module "flutter-tools.utils.path"
local vm_service_extensions = lazy.require("flutter-tools.runners.vm_service_extensions") ---@module "flutter-tools.runners.vm_service_extensions"
local _, dap = pcall(require, "dap")
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 fmt = string.format

Expand Down
Loading