sidlatau / neotest-dart

30 stars 8 forks source link

Unable to debug flutter test #10

Closed n1h41 closed 8 months ago

n1h41 commented 9 months ago

When trying to debug test the following error is being thrown

neotest-dart: ...al/AppData/Local/nvim-data/lazy/neotest/lua/nio/init.lua:105: The coroutine failed with this message: ...AppData/Local/nvim-data/lazy/neotest/lua/nio/control.lua:208: ...ppData/Local/nvim-data/lazy/nvim-dap/lua/dap/session.lua:1420: Error running flutter: ENOENT: no such file or directory stack traceback: [C]: in function 'error' ...AppData/Local/nvim-data/lazy/neotest/lua/nio/control.lua:208: in function 'with' ...data/lazy/neotest/lua/neotest/client/strategies/init.lua:37: in function 'run' ...cal/nvim-data/lazy/neotest/lua/neotest/client/runner.lua:129: in function '_run_spec' ...cal/nvim-data/lazy/neotest/lua/neotest/client/runner.lua:89: in function <...cal/nvim-data/lazy/neotest/lua/neotest/client/runner.lua:88>

The test's are running without any issues when not debugging

This is my neotest config file

require("neotest").setup({ adapters = { require("neotest-dart")({ command = "flutter", use_lsp = true, }) } })

this is my dap configuration for flutter

`local dap = require('dap') local dapui = require('dapui')

dap.adapters.dart = { type = 'executable', command = vim.fn.stdpath('data') .. '/mason/bin/dart-debug-adapter.cmd', args = { 'flutter' }, options = { detached = false, }, }

dap.configurations.dart = { { type = "flutter", request = "launch", name = "Launch flutter", dartSdkPath = "C:/src/flutter/bin/cache/dart-sdk/", flutterSdkPath = "C:/src/flutter/", program = "${workspaceFolder}/lib/main.dart", cwd = "${workspaceFolder}", console = 'externalTerminal', }, { type = 'flutter', request = 'attach', name = 'Attach Program', dartSdkPath = "C:/src/flutter/bin/cache/dart-sdk/", flutterSdkPath = "C:/src/flutter/", program = "${workspaceFolder}/lib/main.dart", cwd = "${workspaceFolder}", console = 'externalTerminal', } }`

And this is my config file for flutter-tools.nvim

`local flutter = require('flutter-tools')

-- alternatively you can override the default configs flutter.setup { ui = { -- the border type to use for all floating windows, the same options/formats -- used for ":h nvim_open_win" e.g. "single" | "shadow" | {} border = "rounded", -- This determines whether notifications are show with vim.notify or with the plugin's custom UI -- please note that this option is eventually going to be deprecated and users will need to -- depend on plugins like nvim-notify instead. notification_style = 'plugin' }, decorations = { statusline = { -- set to true to be able use the 'flutter_tools_decorations.app_version' in your statusline -- this will show the current version of the flutter app from the pubspec.yaml file app_version = true, -- set to true to be able use the 'flutter_tools_decorations.device' in your statusline -- this will show the currently running device if an application was started with a specific -- device device = true, -- set to true to be able use the 'flutter_tools_decorations.project_config' in your statusline -- this will show the currently selected project configuration project_config = true, } }, debugger = { -- integrate with nvim dap + install dart code debugger enabled = false, run_via_dap = true, -- 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 = {} }, flutter_path = "C:/src/flutter/bin/flutter.bat", -- <-- this takes priority over the lookup fvm = false, -- takes priority over path, uses /.fvm/flutter_sdk if enabled widget_guides = { enabled = true, }, dev_log = { enabled = true, notify_errors = false, -- if there is an error whilst running then notify the user open_cmd = "tabnew", -- command to use to open the log buffer }, dev_tools = { autostart = true, -- autostart devtools server if not detected auto_open_browser = false, -- Automatically opens devtools in the browser }, outline = { open_cmd = "30vnew", -- command to use to open the outline buffer auto_open = false -- if true this will open the outline automatically when it is first populated }, lsp = { color = { -- show the derived colours for dart variables enabled = true, -- whether or not to highlight color variables at all, only supported on flutter >= 2.10 background = true, -- highlight the background background_color = { r = 19, g = 17, b = 24 }, -- required, when background is transparent (i.e. background_color = { r = 19, g = 17, b = 24},) foreground = false, -- highlight the foreground virtual_text = true, -- show the highlight using virtual text -- virtual_text_str = "■", -- the virtual text character to highlight }, on_attach = on_attach, capabilities = capabilities, -- e.g. lsp_status capabilities -- see the link below for details on each option: -- https://github.com/dart-lang/sdk/blob/master/pkg/analysis_server/tool/lsp_spec/README.md#client-workspace-configuration settings = { showTodos = true, completeFunctionCalls = true, analysisExcludedFolders = { "C:/Users/nihal/AppData/Local/Pub/Cache"--[[ , "C:/src/flutter", ]] }, renameFilesWithClasses = "prompt", -- "always" enableSnippets = true, updateImportsOnRename = true, -- Whether to update imports and other directives when files are renamed. Required for FlutterRename command. } } }`

sidlatau commented 9 months ago

I see DAP can not find file Error running flutter: ENOENT: no such file or directory - please check if all files mentioned in your config exist, i.e. this one command = vim.fn.stdpath('data') .. '/mason/bin/dart-debug-adapter.cmd',

dizzib commented 1 week ago

I hit the same problem because I was using puro which modifies the flutter path.

It seems neotest-dart accommodates raw flutter and fvm but not puro:

https://github.com/sidlatau/neotest-dart/blob/33b9335cd8c2be4dcf9dd8f196b24325e7c2e8e7/lua/neotest-dart/init.lua#L104

Here’s the line in nvim-dap where the error is thrown

Adding flutter to my env PATH fixed it, as a workaround.