Closed shashanknimje closed 2 years ago
Hi @shashanknimje,
I'm not completely getting the problem I feel, I don't see why you need to run flutter.attach
after running flutter.run
. That should already automatically attach such that you can see the logs and hot restart and such.
As for using nvim-dap
for flutter I haven't tried that yet, usually just switch to the dart devtools or vscode for debugging. Could you link some docs on how to setup nvim-dap
for CoC?
Hi @Kavantix,
Thank you for your quick response! And great questions.
It is true that flutter.run should automatically attach to the device running. But that doesn't seem to be the case for the device "web-server" for some reason.
Here is a sample output of running the command "flutter run -d web-server --web-port=xxxxx"
`❯ flutter run -d web-server --web-port=42751
Launching lib/main.dart on Web Server in debug mode...
Waiting for connection from debug service on Web Server... 15.0s
lib/main.dart is being served at http://localhost:42751
The web-server device requires the Dart Debug Chrome extension for debugging.
Consider using the Chrome or Edge devices for an improved development workflow.
🔥 To hot restart changes while running, press "r" or "R".
For a more detailed help message, press "h". To quit, press "q".`
**When I press "h" in the above prompt I get the below message.**
`v Open Flutter DevTools.`
When I press "v" to Open Flutter DevTools, nothing happens.
Also running "sudo ss -ltp | grep flutter" gives the below information.
`❯ sudo ss -ltp | grep flutter
LISTEN 0 128 127.0.0.1:42061 0.0.0.0:* users:(("dart:flutter_to",pid=41498,fd=18))
LISTEN 0 128 [::1]:42751 [::]:* users:(("dart:flutter_to",pid=41498,fd=17))
LISTEN 0 128 [::1]:42061 [::]:* users:(("dart:flutter_to",pid=41498,fd=19))`
I am able to access the application at http://localhost:42751, but when I visit http://localhost:42061 (hoping this is where the Flutter Dev Tools program is running) I get the below message.
404 Not Found Only WebSocket connections are supported.
When I try to run manually to the web-server device despite being attached to it as seen above, in hopes of being able to activate the Flutter Dev Tools, I get the below message.
`❯ flutter devices --show-web-server-device
3 connected devices:
Linux (desktop) • linux • linux-x64 • Arch Linux 5.18.7-zen1-1-zen
Web Server (web) • web-server • web-javascript • Flutter Tools
Chrome (web) • chrome • web-javascript • Google Chrome 102.0.5005.115
❯ flutter attach -d web-server
Waiting for a connection from Flutter on Web Server...
Error connecting to the service protocol: Exception: connection to device ended
too early
`
Now as for using "mfussenegger/nvim-dap" plugin for debugging, here is what I use.
call plug#begin('~/.vim/plugged')
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'dart-lang/dart-vim-plugin'
Plug 'mfussenegger/nvim-dap'
Plug 'rcarriga/nvim-dap-ui'
call plug#end()
"lua script dependent plugin settings"
lua << EOF
require("dapui").setup({
icons = { expanded = "▾", collapsed = "▸" },
mappings = {
-- Use a table to apply multiple mappings
expand = { "<CR>", "<2-LeftMouse>" },
open = "o",
remove = "d",
edit = "e",
repl = "r",
toggle = "t",
},
-- Expand lines larger than the window
-- Requires >= 0.7
expand_lines = vim.fn.has("nvim-0.7"),
-- Layouts define sections of the screen to place windows.
-- The position can be "left", "right", "top" or "bottom".
-- The size specifies the height/width depending on position. It can be an Int
-- or a Float. Integer specifies height/width directly (i.e. 20 lines/columns) while
-- Float value specifies percentage (i.e. 0.3 - 30% of available lines/columns)
-- Elements are the elements shown in the layout (in order).
-- Layouts are opened in order so that earlier layouts take priority in window sizing.
layouts = {
{
elements = {
-- Elements can be strings or table with id and size keys.
{ id = "scopes", size = 0.25 },
"breakpoints",
"stacks",
"watches",
},
size = 40, -- 40 columns
position = "left",
},
{
elements = {
"repl",
"console",
},
size = 0.25, -- 25% of total lines
position = "bottom",
},
},
floating = {
max_height = nil, -- These can be integers or a float between 0 and 1.
max_width = nil, -- Floats will be treated as percentage of your screen.
border = "single", -- Border style. Can be "single", "double" or "rounded"
mappings = {
close = { "q", "<Esc>" },
},
},
windows = { indent = 1 },
render = {
max_type_length = nil, -- Can be integer or nil.
}
})
require("dapui").setup()
local dap, dapui = require("dap"), require("dapui")
dap.adapters.dart = {
type = "executable",
command = "node",
args = {"/home/user/development/Dart-Code/out/dist/debug.js", "flutter"}
}
dap.configurations.dart = {
{
type = "dart",
request = "launch",
name = "Launch flutter",
dartSdkPath = os.getenv('HOME').."/development/flutter/bin/cache/dart-sdk/",
flutterSdkPath = os.getenv('HOME').."/development/flutter/",
program = "${workspaceFolder}/lib/main.dart",
cwd = "${workspaceFolder}",
}
}
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
EOF
And obviously, there reason I am here is because I use iamcco/coc-flutter as LSP.
Here is the documentation on how to setup mfussenegger/nvim-dap plugin Debug-Adapter for Dart language. PS - Make sure to include the line "local dap = require('dap')" before the code provided in that guide for it to work.
Thank you once again for going through the provided information and helping me out. Very much appreciate it!
Sorry for the late response! I looked into it a bit and my conclusion so far is that the web server device is simply not meant for debugging. But either way I’m afraid it is indeed out of scope for this plugin so I’ll close this issue.
https://github.com/iamcco/coc-flutter/blob/32aaad1edc5b6f51734653771ef136ccf0c181f4/src/commands/global.ts#L83
Hi,
Thank you very much for this amazing plugin! Currently, I'm trying to use nvim via ssh to run a flutter "web-server" device using a command like so.
"flutter run -d web-server --web-port=12345"
This runs the web-server just fine even when I use the coc-flutter command "flutter.run -d web-server --web-port=xxxxx". The problem arises however when after successfully running the web-server device, the neovim instance is still unable attach to it either using "flutter.attach" or "flutter.devices" option from the coc-flutter list of commands / menu options.
The ability to run something along the lines of "flutter devices --show-web-server-device" is much needed, which would then populate the device list with an additional device listing like so.
"Web Server (web) • web-server • web-javascript • Flutter Tools"
This will then allow the user to be able to select 'web-server' as the device, which would then enable the use of other extensions like nvim-dap to be able to use flutter debug tools from within neovim. Currently nvim-dap is unable to run, as coc-flutter shows no attached device despite running the web-server device using "flutter.run -d web-server --web-port=12345" via the menu options under neovim.
So really it is a two part request. One is the ability to list the web-server in the list of devices and the second is to be able to attach to it.
Thank you for you help on this!