akinsho / flutter-tools.nvim

Tools to help create flutter apps in neovim using the native lsp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] Debug adapter does not respond; `run_via_dap=true`, Windows 11

akriese opened this issue · comments

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

When running :FlutterStart or dap.continue(), a new shell window is opened, where the debug adapter is run. In nvim, the message pops up: Debug adapter didn't respond. Either the adapter is slow or there is a problem with your adapter or 'dart' configuration.

I am using the following config for flutter-tools:

require("flutter-tools").setup({
    debugger = { -- integrate with nvim dap + install dart code debugger
        enabled = true,
        run_via_dap = true, -- use dap instead of a plenary job to run flutter apps
        exception_breakpoints = {},
    },
    lsp = {
        on_attach = on_attach,
        capabilities = capabilities,
    },
})

I've tried using run_via_dap=false and this works, but obviously, the debug functionality of dap then is missing. I haven't changed anything about the section and it worked about half a year ago.
So, these are the possible problems:

  • Other parts of my config changed
  • DAP changed
  • flutter-tools.nvim changed
  • flutter's debug adapter changed
  • Something about the terminal opening a new window where the adapter runs in???

I'd like to fix this somehow, but I don't see a good starting point to dig deeper.

Expected Behavior

The debug adapter does not time out and dap-ui etc. is started.

Steps To Reproduce

Config:

local lazypath = vim.fn.stdpath("data") .. "/lazy.alt/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({
        "git",
        "clone",
        "--filter=blob:none",
        "https://github.com/folke/lazy.nvim.git",
        "--branch=stable", -- latest stable release
        lazypath,
    })
end
vim.opt.rtp:prepend(lazypath)

local plugins = {
    {
        "akinsho/flutter-tools.nvim",
        lazy = false,
        dependencies = { "nvim-lua/plenary.nvim", "stevearc/dressing.nvim", "mfussenegger/nvim-dap" },
        config = true,
    },
}

require("lazy").setup(plugins)

require("dap").set_log_level("TRACE")

require("flutter-tools").setup({
    debugger = { -- integrate with nvim dap + install dart code debugger
        enabled = true,
        run_via_dap = true, -- use dap instead of a plenary job to run flutter apps
        exception_breakpoints = {},
    },
})

Environment

- OS: Windows 11
- Flutter version: 3.12.0-1.1.pre, channel beta
- Is flutter in $PATH: yes
- neovim version: 0.9.0-dev-1258+ge789d6529

Anything else?

Dap log with TRACE:

[ DEBUG ] 2023-07-14T13:57:21Z+0200 ] ...ppData/Local/nvim-data/lazy/nvim-dap/lua/dap/session.lua:1292 ]        "Spawning debug adapter"        {
  args = { "debug-adapter" },
  command = "C:\\tools\\flutter\\bin\\flutter.BAT",
  type = "executable"
}
[ DEBUG ] 2023-07-14T13:57:21Z+0200 ] ...ppData/Local/nvim-data/lazy/nvim-dap/lua/dap/session.lua:1605 ]        "request"       {
  arguments = {
    adapterID = "nvim-dap",
    clientId = "neovim",
    clientname = "neovim",
    columnsStartAt1 = true,
    linesStartAt1 = true,
    locale = "en_US",
    pathFormat = "path",
    supportsProgressReporting = true,
    supportsRunInTerminalRequest = true,
    supportsStartDebuggingRequest = true,
    supportsVariableType = true
  },
  command = "initialize",
  seq = 0,
  type = "request"
}
[ DEBUG ] 2023-07-14T13:57:33Z+0200 ] ...ppData/Local/nvim-data/lazy/nvim-dap/lua/dap/session.lua:1605 ]        "request"       {
  arguments = {
    restart = false,
    terminateDebuggee = true
  },
  command = "disconnect",
  seq = 1,
  type = "request"
}

UPDATE: It might have something to do with my config somehow, as I recently switched from vim-plug to lazy.nvim. Just tried out the old config with the same versions of everything that aren't working with my current config, and that works...

Nevermind, I had altered the flutter-tools code in the repo clone of my old config. My new config used a fresh clone of the repo without my "fix", that's why it didnt work.
What's fixing the issue for me is setting the option detached to false in the adapter config. Like so:

function M.setup(config)
  local opts = config.debugger
  require("flutter-tools.executable").get(function(paths)
    dap.adapters.dart = {
      type = "executable",
      command = paths.flutter_bin,
      args = { "debug-adapter" },
      options = {
        detached = false,
      },
    }
    opts.register_configurations(paths)
    if opts.exception_breakpoints and type(opts.exception_breakpoints) == "table" then
      dap.defaults.dart.exception_breakpoints = opts.exception_breakpoints
    end
  end)
end

I am wondering, wheather this is a useful fix, or if it can be done differently. Also, I am wondering why I seem to be the only person to encounter this issue. If a maintainer of flutter-tools sees this, could you give me some feedback on this? I guess, otherwise this could be closed :)

Hello,

  1. Try to config debugger apapter:https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation#dart,
  2. Set flutter-tools config debugger:
 debugger = { 
    enabled = false,
    run_via_dap = false, -- use dap instead of a plenary job to run flutter apps
    -- if empty dap will not stop on any exceptions, otherwise it will stop on those specified
    -- see |:help dap.set_exception_breakpoints()| for more info
    exception_breakpoints = {}
    register_configurations = function(paths)<------------- HERE put debugger config as nvim-dap doc
      require("dap").configurations.dart = {
        <put here config that you would find in .vscode/launch.json>
      }
    end,

Yep, that works. So how would I use it with dap now? I am using dap-ui and that does not open automatically, as run_with_dap is false.

You must have enabled in true , and run_via_dap too.