nvim-flutter / flutter-tools.nvim

Tools to help create flutter apps in neovim using the native lsp
MIT License
1.07k stars 83 forks source link

[BUG] Unable to restart debugging. Please try ending the debug session and starting again. #404

Closed thanhdatvo closed 1 week ago

thanhdatvo commented 3 weeks ago

Is there an existing issue for this?

Current Behavior

Cannot debug flutter with launch.json

Expected Behavior

Could debug flutter with launch.json

Steps To Reproduce

My setup for flutter-tools in Lazyvim:

return {
  "akinsho/flutter-tools.nvim",
  lazy = false,
  dependencies = {
    "nvim-lua/plenary.nvim",
    "stevearc/dressing.nvim", -- optional for vim.ui.select
  },
  config = function()
    require("flutter-tools").setup({
      debugger = {
        enabled = true,
        register_configurations = function(paths)
          local dap = require("dap")
          dap.configurations.dart = {}
          require("dap.ext.vscode").load_launchjs()
        end,
      },
    })
  end,
}

This is my launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "test_delte",
      "program": "${workspaceFolder}/lib/main.dart",
      "request": "launch",
      "type": "dart",
      "flutterMode": "debug"
    }
  ]
}

Screenshot 2024-11-09 at 3 14 08 PM

I could debug the app with option 1., but could not debug the app with option 2. and 3. (from launch.json)

This is the error in debug console

Screenshot 2024-11-09 at 3 15 28 PM

Environment

- OS: MacOS
- Flutter version:3.24.1
- Is flutter in $PATH: yes
- neovim version: v0.10.0

Anything else?

No response

sidlatau commented 3 weeks ago

I'm using "program": "lib/main.dart" without {workspaceFolder}. Could you try this in your setup? Why are there three run options? Is the complete launch.json file shared?

thanhdatvo commented 2 weeks ago

@sidlatau Thank you for your suggestion! I removed {workspaceFolder} but the error persists.

Why are there three run options? A: I don't know.

Is the complete launch.json file shared? A: Yes, it is

sidlatau commented 2 weeks ago

Following your provided setup, there should only be a single DAP configuration. However, it looks like more configurations are added somewhere in your config. You may try to remove register_configurations, your config does not add any custom flags, flutter_tools should be able to run the project with default values.

thanhdatvo commented 2 weeks ago

Hi @sidlatau , I removed register_configurations, but the repeats still persist, and I could not start debugging (same error appeared).

I double-checked the DAP configuration in the LazyVim setup. I have only two files configured for DAP: one for Golang and one for Flutter. I’m not sure if I mistakenly installed any LazyVim plugin that might be affecting how flutter_tools works This is the list of Lazy Vim plugins I installed:

Screenshot 2024-11-14 at 4 29 06 PM

sidlatau commented 2 weeks ago

@thanhdatvo I can not debug your local config. Please try to get a minimal init.lua with exact reproduction steps.

thanhdatvo commented 2 weeks ago

@sidlatau thank you for your reply. I really appreciate you taking time to help me. I will try to config nvim with only flutter_tools to see how it works, and will come back to you.

thanhdatvo commented 2 weeks ago

@sidlatau Today, I tried to run nvim with Lazyvim starter I only installed flutter_tools and enabled dap.core in LazyExtra Screenshot 2024-11-16 at 12 46 21 PM

I kept the same config for flutter_tools. All the mentioned issues still persist.

sidlatau commented 2 weeks ago

I am not familiar with Lazyvim, so maybe it causes an issue. Could you try a minimal setup without Lazyvim? I did not see such problem as you are facing before, so I still assume it is a local config issue.

thanhdatvo commented 2 weeks ago

@sidlatau I used to use Packer before switching to LazyVim. However, Packer is now outdated, and I am currently only familiar with LazyVim.

Since you mentioned a minimal init.lua, you likely know how to create one. Could you kindly provide me with a minimal init.lua configuration for Neovim that includes flutter_tools? I’d like to configure and test flutter_tools using this setup.

Thank you very much!

sidlatau commented 2 weeks ago

I suggest to setup everything in a single file, then you could easily share it. I think the easiest way to do it would be with https://github.com/nvim-lua/kickstart.nvim - just remove what you are not using, add flutter-tools and try to reproduce the issue.

thanhdatvo commented 1 week ago

Hi @sidlatau, As you suggested, I used the Neovim kickstart configuration with only flutter-tools, and it worked perfectly. (Note that I did not use nvim-dap.)

Screenshot 2024-11-18 at 9 34 18 AM

It seems that flutter-tools might not work properly with LazyVim (https://www.lazyvim.org/) for certain reasons.

thanhdatvo commented 1 week ago

@sidlatau For some reason, when I switched back to my old LazyVim configuration, it resolved the duplication issue in the VSCode launch configuration (now only showing one test_delete instead of two as before). Screenshot 2024-11-18 at 10 01 57 AM

However, I tried to run test_delete, the old error Unable to restart debugging. Please try ending the debug session and starting again still persisted.

sidlatau commented 1 week ago

You still haven't provided any minimum reproducible steps.

thanhdatvo commented 1 week ago

@sidlatau Here’s what I experimented with:

For 2nd Attempt: I failed to config nvim-dap to debug.


About 2nd Attempt: Since the Kickstart Neovim configuration you mentioned organizes its dependencies across multiple files, I will list all the files I have configured below:

- dap-ui.lua

return { 'rcarriga/nvim-dap-ui', -- dependencies = { 'nvim-neotest/nvim-nio' }, -- stylua: ignore keys = { { "du", function() require("dapui").toggle({ }) end, desc = "Dap UI" }, { "de", function() require("dapui").eval() end, desc = "Eval", mode = {"n", "v"} }, }, opts = {}, config = function(_, opts) local dap = require 'dap' local dapui = require 'dapui' dapui.setup(opts) dap.listeners.after.event_initialized['dapui_config'] = function() dapui.open {} end dap.listeners.before.event_terminated['dapui_config'] = function() dapui.close {} end dap.listeners.before.event_exited['dapui_config'] = function() dapui.close {} end end, }

- dap.lua

return { 'mfussenegger/nvim-dap', recommended = true, desc = 'Debugging support. Requires language specific adapters to be configured. (see lang extras)',

dependencies = { 'rcarriga/nvim-dap-ui', -- virtual text for the debugger -- { -- 'theHamsta/nvim-dap-virtual-text', -- opts = {}, -- }, },

-- stylua: ignore keys = { { "d", "", desc = "+debug", mode = {"n", "v"} }, { "dB", function() require("dap").set_breakpoint(vim.fn.input('Breakpoint condition: ')) end, desc = "Breakpoint Condition" }, { "db", function() require("dap").toggle_breakpoint() end, desc = "Toggle Breakpoint" }, { "dc", function() require("dap").continue() end, desc = "Run/Continue" }, { "da", function() require("dap").continue({ before = get_args }) end, desc = "Run with Args" }, { "dC", function() require("dap").run_tocursor() end, desc = "Run to Cursor" }, { "dg", function() require("dap").goto() end, desc = "Go to Line (No Execute)" }, { "di", function() require("dap").step_into() end, desc = "Step Into" }, { "dj", function() require("dap").down() end, desc = "Down" }, { "dk", function() require("dap").up() end, desc = "Up" }, { "dl", function() require("dap").run_last() end, desc = "Run Last" }, { "do", function() require("dap").step_out() end, desc = "Step Out" }, { "dO", function() require("dap").step_over() end, desc = "Step Over" }, { "dp", function() require("dap").pause() end, desc = "Pause" }, { "dr", function() require("dap").repl.toggle() end, desc = "Toggle REPL" }, { "ds", function() require("dap").session() end, desc = "Session" }, { "dt", function() require("dap").terminate() end, desc = "Terminate" }, { "dw", function() require("dap.ui.widgets").hover() end, desc = "Widgets" }, },

config = function() -- load mason-nvim-dap here, after all adapters have been setup if LazyVim.has 'mason-nvim-dap.nvim' then require('mason-nvim-dap').setup(LazyVim.opts 'mason-nvim-dap.nvim') end

vim.api.nvim_set_hl(0, 'DapStoppedLine', { default = true, link = 'Visual' })

-- for name, sign in pairs(LazyVim.config.icons.dap) do
--   sign = type(sign) == 'table' and sign or { sign }
--   vim.fn.sign_define('Dap' .. name, { text = sign[1], texthl = sign[2] or 'DiagnosticInfo', linehl = sign[3], numhl = sign[3] })
-- end

-- setup dap config by VsCode launch.json file
local vscode = require 'dap.ext.vscode'
local json = require 'plenary.json'
vscode.json_decode = function(str)
  return vim.json.decode(json.json_strip_comments(str))
end

end, }

- mason.lua

return { 'williamboman/mason.nvim', }



I already installed dart debug adapter with command: `MasonInstall dart-debug-adapter`

-----
I believe I have provided detailed information about all my attempts. However, using nvim kickstart may not align with my configuration. The simplest way to reproduce the issue is to use LazyVim with only flutter-tools installed.

Please let me know if you need any additional information from me.
sidlatau commented 1 week ago

Are you running on Windows? I see this in your config:

 -- windows users will need to set 'detached' to false
options = {
  detached = false,
},
thanhdatvo commented 1 week ago

@sidlatau

  1. I continues to fix problem nvim-dap with kickstart When I ran : lua require("dap").continue() I encountered the following error: Config references missing adapter dart. Available are: However, then I started debug session using: FlutterRun it worked fine

  2. I think I figured it out. I reverted back to my config with LazyVim When I tried to start a debug session using the command: lua require("dap").continue() I encountered the error: Unable to restart debugging. Please try ending the debug session and starting again. However, when I started the session using: FlutterRun it worked fine.

I think I’m fine at the moment; however, the description in the README should be updated: from To use the debugger you need to run :lua require('dap').continue()<CR> to To use the debugger you need to run :FlutterRun

I will close this issue for now.

Thank you a lot!