SublimeDebugger icon indicating copy to clipboard operation
SublimeDebugger copied to clipboard

Is it possible to write a custom adapter?

Open kennethnym opened this issue 3 years ago • 14 comments

First of all great work on the plugin. I am trying to integrate Dart/Flutter with this plugin, and I noticed there aren't any documentation on writing/installing custom adapters. Is it possible to write a custom adapter? If so, how would I get around doing it? If it isn't possible, I am more than happy to make a PR to add Dart/Flutter support.

kennethnym avatar Dec 18 '21 17:12 kennethnym

You should take a look at the existing adapters they are all implemented here https://github.com/daveleroy/sublime_debugger/tree/master/modules/adapters

Someone else was asking about dart/flutter awhile ago and I created this branch https://github.com/daveleroy/sublime_debugger/tree/dart which has the very basics working for dart.

Flutter support probably requires more configuration stuff you would have to see/ask what they are doing here https://github.com/Dart-Code/Dart-Code

daveleroy avatar Dec 18 '21 22:12 daveleroy

Flutter also supports DAP apparently. I will take a look at existing adapters and see what I come up with.

kennethnym avatar Dec 19 '21 00:12 kennethnym

Interesting I don't think any of this existed when I initially looked into it (maybe a year ago?). Dart now official supports it as well https://github.com/dart-lang/sdk/tree/main/pkg/dds/tool/dap

Both of these look much simpler and don't need a ton of additional configuration stuff

daveleroy avatar Dec 19 '21 02:12 daveleroy

I don't think it's released though, because flutter debug-adapter doesn't work properly.

I tried to run the Dart debugger in the example/dart folder, but I got this error: image

Unable to restart debugging. Please try ending the debug session and starting again.

When I view the console, this exception was logged:

<Future pending>
Traceback (most recent call last):
  File "/home/kenneth/.config/sublime-text/Packages/Debugger/modules/core/sublime_event_loop.py", line 14, in __call__
    self.callback(*self.args)
  File "/home/kenneth/.config/sublime-text/Packages/Debugger/modules/core/core.py", line 58, in done
    exception = task.exception() 
asyncio.exceptions.CancelledError

Is it something to do with the event loop?

kennethnym avatar Dec 19 '21 18:12 kennethnym

That exception is unrelated "Unable to restart debugging. Please try ending the debug session and starting again." is from the dart adapter so there is probably some issue with the configuration where it needs more stuff. It likely outputs that error message and then closes the connection.

What do you mean flutter debug-adapter doesn't work properly?

daveleroy avatar Dec 19 '21 19:12 daveleroy

That exception is unrelated "Unable to restart debugging. Please try ending the debug session and starting again." is from the dart adapter so there is probably some issue with the configuration where it needs more stuff. It likely outputs that error message and then closes the connection.

OK, I'll look into it.

What do you mean flutter debug-adapter doesn't work properly? When I try to run that command, I get the following error:

Could not find a command named "debug-adapter".


Run 'flutter -h' (or 'flutter <command> -h') for available flutter commands and options.

which is why I think it is not released yet.

kennethnym avatar Dec 19 '21 21:12 kennethnym

You might just need to update flutter. Both dart debug-adapter and flutter debug-adapter seem to start the debug adapter process for me (I downloaded the latest flutter version last night).

Here is my output forflutter --version

Flutter 2.8.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 77d935af4d (3 days ago) • 2021-12-16 08:37:33 -0800
Engine • revision 890a5fca2e
Tools • Dart 2.15.1

daveleroy avatar Dec 19 '21 22:12 daveleroy

Actually it might not be the version the command should be flutter debug_adapter not flutter debug-adapter

daveleroy avatar Dec 19 '21 22:12 daveleroy

I updated the dart adapter to use dart debug_adapter and it seems to be working for me https://github.com/daveleroy/sublime_debugger/commit/89c481fbde5780dffbe7249dab4f3384ecd57b71

It required a small change to the transport protocol https://github.com/daveleroy/sublime_debugger/commit/a3ee3e3de654883ecbc017a735905bc18e096823 described here https://microsoft.github.io/debug-adapter-protocol/overview so it can handle more than just the Content-Length header since they seem to be sending some additional headers

daveleroy avatar Dec 19 '21 22:12 daveleroy

I pulled in the latest commit, and now it will stuck at "Starting" and will not actually start the debug session.

kennethnym avatar Dec 24 '21 22:12 kennethnym

Sorry I missed this.

If you right click on the debugger panel and select Show Protocol you can see what parsed messages were passed back and forth between the debugger ui and the debug adapter. I suspect probably nothing is sent from the debug adapter because there is another issue with the transport protocol parsing maybe? That is done here https://github.com/daveleroy/sublime_debugger/blob/89c481fbde5780dffbe7249dab4f3384ecd57b71/modules/dap/transport.py#L56

You could put a print statement in there and see what is actually being send from the debug adapter.

daveleroy avatar Jan 08 '22 16:01 daveleroy

Thanks, I'll try that when I'm free.

kennethnym avatar Jan 08 '22 16:01 kennethnym

Hi @daveleroy, turns out my path to the main dart file is misconfigured. Everything seems to be working fine now after I fixed the path by adding ${workspacePath}. The only issue I have now is #121.

kennethnym avatar Jan 13 '22 19:01 kennethnym

@kennethnym assuming you are on Windows you can try increasing the hardcoded value here https://github.com/daveleroy/sublime_debugger/blob/8f8bbd3273a77ff8b3c4fb09526bac7ef29c0d80/modules/ui/layout_view.py#L153

If you have a value that works for you let me know what it is this is.

daveleroy avatar Jan 15 '22 13:01 daveleroy