mfussenegger / nvim-dap

Debug Adapter Protocol client implementation for Neovim
GNU General Public License v3.0
5.17k stars 180 forks source link

Dart adapter not working #1020

Closed Zeioth closed 10 months ago

Zeioth commented 10 months ago

Debug adapter definition and debug configuration

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

Debug adapter version

v3.70.0

Steps to Reproduce

In this hello world flutter project I wrote, I insert a breakpoint and call :DapContinue.

screenshot_2023-08-26_10-44-36_646188880

As you can see I can debug ok other languages so my setup should be about correct

screenshot_2023-08-26_10-45-31_501013868

I've also checked the sdk dir and seems to be correct: screenshot_2023-08-26_10-47-42_416888677 screenshot_2023-08-26_10-47-49_328696879

Expected Result

DAP opens

Actual Result

Nothing happens

Zeioth commented 10 months ago

This is the result of :DapShowLog

[ WARN ] 2023-08-26T10:56:28Z+0200 ] ...ioth/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:985 ]  "No event handler for " {
  body = {
    message = "Launching…",
    progressId = "launch"
  },
  event = "dart.progressStart",
  seq = 2,
  type = "event"
}
[ WARN ] 2023-08-26T10:56:28Z+0200 ] ...ioth/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:985 ]  "No event handler for " {
  body = {
    category = 9,
    message = 'Spawning /opt/flutter/bin/flutter with args ["run","--machine","--start-paused","--target","lib/main.dart"]',
    severity = 0
  },
  event = "dart.log",
  seq = 4,
  type = "event"
}
[ WARN ] 2023-08-26T10:56:28Z+0200 ] ...ioth/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:985 ]  "No event handler for " {
  body = {
    category = 9,
    message = "..  in /home/zeioth/.local/share/nvim/lazy/compiler.nvim/tests/examples/dart/flutter/lib",
    severity = 0
  },
  event = "dart.log",
  seq = 5,
  type = "event"
}
[ WARN ] 2023-08-26T10:56:28Z+0200 ] ...ioth/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:985 ]  "No event handler for " {
  body = {
    category = 9,
    message = "    PID: 344342",
    severity = 0
  },
  event = "dart.log",
  seq = 6,
  type = "event"
}
[ WARN ] 2023-08-26T10:56:28Z+0200 ] ...ioth/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:985 ]  "No event handler for " {
  body = {
    category = 9,
    message = "<== Changing current working directory to: /home/zeioth/.local/share/nvim/lazy/compiler.nvim/tests/examples/dart/flutter\r\n",
    severity = 0
  },
  event = "dart.log",
  seq = 7,
  type = "event"
}
[ WARN ] 2023-08-26T10:56:28Z+0200 ] ...ioth/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:985 ]  "No event handler for " {
  body = {
    category = 9,
    message = '<== [{"event":"daemon.connected","params":{"version":"0.6.1","pid":344352}}]\r\n',
    severity = 0
  },
  event = "dart.log",
  seq = 9,
  type = "event"
}
[ WARN ] 2023-08-26T10:56:28Z+0200 ] ...ioth/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:985 ]  "No event handler for " {
  body = {
    category = 9,
    message = '<== [{"event":"app.start","params":{"appId":"cc7a6607-2497-433a-a851-d1a933425a00","deviceId":"linux","directory":"/home/zeioth/.local/share/nvim/lazy/compiler.nvim/tests/examples/dart/flutter","supportsRestart":true,"launchMode":"run","mode":"debug"}}]\r\n',
    severity = 0
  },
  event = "dart.log",
  seq = 10,
  type = "event"
}
[ WARN ] 2023-08-26T10:56:28Z+0200 ] ...ioth/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:985 ]  "No event handler for " {
  body = {
    category = 9,
    message = "<== Launching lib/main.dart on Linux in debug mode...\r\n",
    severity = 0
  },
  event = "dart.log",
  seq = 11,
  type = "event"
}
[ WARN ] 2023-08-26T10:56:28Z+0200 ] ...ioth/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:985 ]  "No event handler for " {
  body = {
    category = 9,
    message = '<== [{"event":"app.progress","params":{"appId":"cc7a6607-2497-433a-a851-d1a933425a00","id":"0","progressId":null,"message":"Building Linux application...","finished":false}}]\r\n',
    severity = 0
  },
  event = "dart.log",
  seq = 13,
  type = "event"
}
[ WARN ] 2023-08-26T10:56:28Z+0200 ] ...ioth/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:985 ]  "No event handler for " {
  body = {
    message = "Building Linux application...",
    progressId = "launch"
  },
  event = "dart.progressUpdate",
  seq = 14,
  type = "event"
}
[ WARN ] 2023-08-26T10:56:28Z+0200 ] ...ioth/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:985 ]  "No event handler for " {
  body = {
    category = 9,
    message = "CMake Error: The current CMakeCache.txt directory /home/zeioth/.local/share/nvim/lazy/compiler.nvim/tests/examples/dart/flutter/build/linux/x64/debug/CMakeCache.txt is different than the directory /home/zeioth/.local/share/nvim/lazy/compiler.nvim/tests/examples/dart/build/build/linux/x64/debug where CMakeCache.txt was created. This may result in binaries being created in the wrong place. If you are not sure, reedit the CMakeCache.txt\n",
    severity = 2
  },
  event = "dart.log",
  seq = 15,
  type = "event"
}
[ WARN ] 2023-08-26T10:56:28Z+0200 ] ...ioth/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:985 ]  "No event handler for " {
  body = {
    category = 9,
    message = 'CMake Error: The source "/home/zeioth/.local/share/nvim/lazy/compiler.nvim/tests/examples/dart/flutter/linux/CMakeLists.txt" does not match the source "/home/zeioth/.local/share/nvim/lazy/compiler.nvim/tests/examples/dart/build/linux/CMakeLists.txt" used to generate cache.  Re-run cmake with a different source directory.\n',
    severity = 2
  },
  event = "dart.log",
  seq = 17,
  type = "event"
}
[ WARN ] 2023-08-26T10:56:28Z+0200 ] ...ioth/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:985 ]  "No event handler for " {
  body = {
    category = 9,
    message = '<== [{"event":"app.progress","params":{"appId":"cc7a6607-2497-433a-a851-d1a933425a00","id":"0","progressId":null,"finished":true}}]\r\n',
    severity = 0
  },
  event = "dart.log",
  seq = 19,
  type = "event"
}
Zeioth commented 10 months ago

Ok it works fine. I solved it

screenshot_2023-08-26_11-07-34_089917097

Updating wiki.

Zeioth commented 10 months ago

Report: It also works for pure Dart with this config

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

screenshot_2023-08-26_11-18-25_746930892

Zeioth commented 10 months ago

Ok awesome, I've managed a config that can debug both dart and flutter. Tested and working

      -- 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 = "dart",
          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}",
        }
      }

screenshot_2023-08-26_11-29-02_252531671