How can I get the VM Service URI of current Dart Analyzer process

55 views
Skip to first unread message

Alexandre “BuyMyBeard” Lacombe

unread,
Jun 5, 2024, 10:38:30 AM6/5/24
to Dart Analyzer Discussion
I am trying to make Remi Rousslet's custom_lint package debuggable so I can debug my lint package. As far as I am aware, custom_lint is built with analyzer_plugin, and to be able to debug my package, I need to attach the debugger to a provided VM service URI outputted in a log file. The log file doesn't have anything of the sort, and when I asked Remi for help, he told me: "Could be a bug in the reporter, but it works for me".

If I understand well, since the lint package is a plugin to the analyzer, all I need is the current process VM URI of the dart analysis server in VSCode. Is there any way I can get my hands on that?

What I tried: 
running  dart --enable-vm-service --pause-isolates-on-start path/to/your/dart-sdk/bin/snapshots/analysis_server.dart.snapshot --sdk path/to/your/dart-sdk
Issue with that is that it creates a different process.

adding the lines     "dart.vmServiceLogFile": "W:/DevXpress/Logs/{name}",
    "dart.analyzerInstrumentationLogFile": "W:/DevXpress/Logs/analysis.log"
to my settings.json
The log files contain a load of information, but nothing that resembles what I'm looking for. I've provided one of those log files in this discussion.

analysis.log

dark...@gmail.com

unread,
Jun 5, 2024, 11:33:54 AM6/5/24
to Dart Analyzer Discussion, buymy...@gmail.com
It'd be good if you could make an issue on custom_lint with a way to reproduce the non-debuggable output.

But otherwise, I believe the VM service URI is available using dart:developer. From memory, it's something among the lines of "Isolate.current.getVmServiceUri()"

The exact syntax may be different. But that should give you an idea of what to look for.

Danny Tuppeny

unread,
Jun 6, 2024, 7:55:07 AM6/6/24
to Dart Analyzer Discussion, buymy...@gmail.com
You need to use the dart.analyzerVmServicePort setting in VS Code to enable the VM Service for the analyzer it spawns. You set a port (for example 8222) and then you can attach a debugger to it (for example using the "Debug: Attach to Dart Process" command). There are some more details about this here:


It's worth noting that plugins are copied during server startup, so having your plugin/lint source code open in VS Code and setting breakpoints in it might not work. You might need to add a debugger() statement somewhere and trigger it so that VS Code opens the file from the copy (there's a little discussion of this at https://github.com/Dart-Code/Dart-Code/issues/4298). It may be easier to debug if you're able to reproduce your issue in a test or similar.. debugging a live analysis server can tricky even without plugins.
Reply all
Reply to author
Forward
0 new messages