svaante / dape

Debug Adapter Protocol for Emacs
GNU General Public License v3.0
477 stars 31 forks source link

`flutter` DAP: Timeout reached for seq 1 #9

Closed muzaffar-omer closed 1 year ago

muzaffar-omer commented 1 year ago

Hello,

Thank you so much for the so needed awesome package!! :-)

Description

When I try dape with flutter debug adapter, I get the below error in *dape-debug* buffer:

[info] Starting new single session
[info] Process started ("flutter" "debug_adapter")
[io] Sending:
(:arguments
 (:clientID "dape" :adapterID "flutter" :pathFormat "path"
        :linesStartAt1 t :columnsStartAt1 t
        :supportsRunInTerminalRequest t :supportsProgressReporting
        t :supportsStartDebuggingRequest t)
 :type "request" :command "initialize" :seq 1)

[error] Timeout for reached for seq 1

Although, in the debug adapter logs (buffer *dape-processes*) It looks like the response for seq 1 request was sent from the adapter:

Content-Length: 556
Content-Type: application/vscode-jsonrpc; charset=utf-8

{"seq":1,"type":"response","body":{"exceptionBreakpointFilters":[{"default":false,"filter":"All","label":"All Exceptions"},{"default":true,"filter":"Unhandled","label":"Uncaught Exceptions"}],"supportsClipboardContext":true,"supportsConditionalBreakpoints":true,"supportsConfigurationDoneRequest":true,"supportsDelayedStackTraceLoading":true,"supportsEvaluateForHovers":true,"supportsLogPoints":true,"supportsRestartRequest":false,"supportsTerminateRequest":true,"supportsValueFormattingOptions":true},"command":"initialize","request_seq":1,"success":true}Content-Length: 56
Content-Type: application/vscode-jsonrpc; charset=utf-8

{"seq":2,"type":"event","body":{},"event":"initialized"}

How to reproduce

  1. Install flutter SDK as described in the manual SDK installation.

  2. Install the dart-mode package.

  3. Add flutter dape config:

    (add-to-list 'dape-configs
             '(flutter
               modes (dart-mode)
               command "flutter"
               command-args ("debug_adapter")
               command-cwd dape-cwd-fn
               :type "flutter"
               :request "launch"
               :cwd dape-cwd-fn
               :dartSdkPath "<path-where-flutter-archive-was-unzipped>/flutter/bin/cache/dart-sdk"
               :flutterSdkPath "<path-where-flutter-archive-was-unzipped>/flutter/"
               :program dape-cwd-fn
               :sendLogsToClient t
               :noDebug t))

    I used https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/debug_adapters/README.md as a reference for the configuration.

  4. Create a flutter app from the CLI using the command:

    flutter create testapp

  5. Open the testapp/lib/main.dart file, and start dape.

svaante commented 1 year ago

It looks like flutter is not following the spec... Only Content-Length is specified as a valid header.

But nevertheless could you try the following for me?

(setq dape--content-length-re
  "\\(?:.*: .*\r?\n\\)*\
Content-Length: [[:digit:]]+\r?\n\
\\(?:.*: .*\r?\n\\)*\
\r?\n"
muzaffar-omer commented 1 year ago

But nevertheless could you try the following for me?

Sure!. After setting the dape--content-length-re:

(setq dape--content-length-re
  "\\(?:.*: .*\r?\n\\)*\
Content-Length: [[:digit:]]+\r?\n\
\\(?:.*: .*\r?\n\\)*\
\r?\n")

Now in the *dape-debug* buffer I get:

[info] Starting new single session
[info] Process started ("flutter" "debug_adapter")
[io] Sending:
(:arguments
 (:clientID "dape" :adapterID "flutter" :pathFormat "path"
        :linesStartAt1 t :columnsStartAt1 t
        :supportsRunInTerminalRequest t :supportsProgressReporting
        t :supportsStartDebuggingRequest t)
 :type "request" :command "initialize" :seq 1)

[io] Received:
(:seq 2 :type "event" :body nil :event "initialized")

[io] Sending:
(:type "request" :command "configurationDone" :seq 2)

[io] Received:
(:seq 3 :type "response" :command "configurationDone" :request_seq 2
      :success t)

[error] Timeout for reached for seq 1

And the *dape-processes* buffer is empty

svaante commented 1 year ago

After some testing this seams like an Dape parsing issue. Working on it :)

svaante commented 1 year ago

There where a couple of issues with Dape that stopped flutter debug_adapter from working.

But they should be fixed.

Used the following config to run the application on macos. You will need to change "macos" in ["-d" "macos"] and used dape-find-file-buffer-default to point to /lib/main.dart.

(flutter-macos
     modes (dart-mode)
     command "flutter"
     command-args ("debug_adapter" "--verbose")
     command-cwd dape-cwd-fn
     :type "dart"
     :request "launch"
     :cwd dape-cwd-fn
     :program dape-find-file-buffer-default
     :toolArgs ["-d" "macos"])

Ran into some issues where the flutter app would crash when using eldoc hover and watch when entering some scopes, but this was reproducible in vscode as well so that is an flutter issue.

I believe it's the same as https://github.com/Dart-Code/Dart-Code/issues/3185

Please get back to me when you have tested with the new changes.

muzaffar-omer commented 1 year ago

The fix works perfectly!!! :ok_hand: :partying_face:

Thank you so much for the quick fix :-)

image

Closing the issue.