Skip to content

DAP support dart

Zeioth edited this page Aug 26, 2023 · 4 revisions

Nothing special needs to be done for Dart/Flutter.

How to setup DAP to debug with Dart/Flutter

Please note that this section has nothing to do with compiler.nvim. I'm documenting this to make your life easier. To debug Dart/Flutter with DAP you have to:

  • Install the mason package dart-debug-adapter.
  • :cd your project root before running DAP.
  • Note that on dart projects, your program code is in ./lib, a dir above that you have the project root.

Here you have an example of how to configure DAP for Dart/Flutter

local dap = require("dap")

-- Dart / Flutter
dap.adapters.dart = {
  type = 'executable',
  command = vim.fn.stdpath('data')..'/mason/bin/dart-debug-adapter',
  args = {'dart'}
}
dap.adapters.flutter = {
  type = 'executable',
  command = vim.fn.stdpath('data')..'/mason/bin/dart-debug-adapter',
  args = {'flutter'}
}
dap.configurations.dart = {
  {
    type = "dart",
    request = "launch",
    name = "Launch dart",
    dartSdkPath = "/opt/flutter/bin/cache/dart-sdk/", -- ensure this is correct
    flutterSdkPath = "/opt/flutter",                  -- ensure this is correct
    program = "${workspaceFolder}/lib/main.dart",     -- ensure this is correct
    cwd = "${workspaceFolder}",
  },
  {
    type = "flutter",
    request = "launch",
    name = "Launch flutter",
    dartSdkPath = "/opt/flutter/bin/cache/dart-sdk/", -- ensure this is correct
    flutterSdkPath = "/opt/flutter",                  -- ensure this is correct
    program = "${workspaceFolder}/lib/main.dart",     -- ensure this is correct
    cwd = "${workspaceFolder}",
  }
}

How to check if everything works

Just insert a breakpoint, run :DapContinue and you will see something like

screenshot_2023-08-26_11-36-48_831911888 Example of debugging dart screenshot_2023-08-26_11-18-25_746930892 Example of debugging flutter screenshot_2023-08-26_11-07-34_089917097

Congratulations, now you can compile and debug Dart/Flutter.

Important for you to know

  • You don't need to manually compile the program in debug mode before calling DAP. The debug adapter takes care of everything.
  • If you find any issue while configuring DAP, run :DapSetLogLevel trace and :DapShowLog to find the reason.