-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support scriptParsed
like event in the protocol.
#108
Comments
Based on some discussion with @andrewcrawley, we think it would make more sense to have a new event that provides notification of new scripts instead of overloading the module event. The event would have a reference to the source file and some metadata about the script. |
Here is the an event I prototyped for doing this. Note that scripts can have children if they have related files. For example a .js script might have its .ts script as a child. /** Event message for 'script' event type.
The event indicates that some information about a script has changed.
*/
export interface ScriptEvent extends Event {
// event: 'script';
body: {
/** The reason for the event. */
reason: 'new' | 'removed';
/** The new or removed script. In case of 'removed' only the script id is used. */
script: Script;
};
}
/** A Script object represents a source that is dynamically loaded by the debugger.
An id identifies a script and is used in a ScriptEvent for identifying a script for loading or unloading.
*/
export interface Script {
/** Unique identifier for the script. */
id: number;
/** The source for the script. */
source: Source;
/** An optional list of scripts that are related to the main source.
These may be the source that generated the main source.
These will be displayed in a tree in the UI.
*/
children?: Script[];
} |
We'll probably need a request for retrieving all loaded scripts as well, to handle attach scenarios where we didn't receive the initial events. The other option would be for debug adapters to send a bunch of script events immediately after an attach, but that's kind of ad-hoc. Suggested: export interface Capabilities {
// ...
/** The debug adapter supports the 'scripts' request. */
supportsScriptsRequest?: boolean;
// ...
}
/** Retrieves the set of script documents currently loaded by the debugged process. */
export interface ScriptsRequest extends Request {
// command: 'scripts';
arguments: ScriptsArguments;
}
/** Arguments for 'scripts' request.
The 'scripts' request has no standardized arguments.
*/
export interface ScriptsArguments {
}
/** Response to 'scripts' request. */
export interface ScriptsResponse extends Response {
body?: {
/** Set of loaded script documents. */
scripts: Script[];
};
} |
@weinand - Any thoughts on this? We've implemented this event in the VS host and the node2 adapter for verification, and it looks like Richard's proposal will meet our needs. I can send a PR against the schema if you'd like. |
We have prototyped something similar as part of microsoft/vscode#28521. The motivation behind that effort was to design and create debug extension API that would support to create a "Script Explorer" solely in an extension (instead of VS Code), because it is difficult to provide a generic "Script Explorer" in the VS Code core debugger that supports the various requirements of different debuggers/runtimes. The "Script Explorer" will appear in tomorrows Insider build. Currently this "Script Explorer" relies on two custom protocol additions: a "scriptLoaded" event and a "getLoadedScripts" request. The next step is to consolidate the custom protocol additions with the proposal at hand and/or the existing modules support. |
I don't see commits associated with any of those issues - can you point me towards the schema changes? |
Those protocol additions are custom (aka "private") events and requests. They are not part of the schema or protocol. They are used in the node-debug extension between the DA and the extension. They do not appear outside of the extension. They are introduced in an ad-hoc way here https://github.com/Microsoft/vscode-node-debug/blob/master/src/node/nodeDebug.ts#L437 and here https://github.com/Microsoft/vscode-node-debug/blob/master/src/node/nodeDebug.ts#L3718. The event has just a "path" attribute and the request an array of paths (strings). The Script Explorer shows the scripts in a tree grouped by various categories (internal modules, workspace scripts, external scripts). The explorer receives the events here: https://github.com/Microsoft/vscode-node-debug/blob/master/src/node/extension/loadedScripts.ts#L75 and requests them here: https://github.com/Microsoft/vscode-node-debug/blob/master/src/node/extension/loadedScripts.ts#L305 In this screenshot you can see the loaded scripts of two parallel debug sessions: |
Thanks for the info. Maybe I'm misunderstanding, but I don't think a simple path string is enough for us to implement the features we want. For instance:
What's the difficulty in providing a generic "Loaded Scripts" tree? Is there an existing discussion on this I can read? VS has a generic "Script Documents" tree that multiple debuggers integrate with. If every debug adapter out there has to invent their own custom UI and a set of messages for populating it, there's no way we're going to be able to map them onto VS's system. |
I probably didn't make it clear enough, but my info from above is neither a proposal nor a counter-proposal. It is just a summary of an experiment that we did. The motivation behind that effort was to design and create VS Code debug extension API that would support to create a "Script Explorer". It is only related to the debug adapter protocol in so far as it uses an internal and private request to retrieve the loaded scripts. We could have used any other example and not touch the "scriptParsed" issue in any way, but since we had already a half-baked QuickPick based version of the Loaded Scripts functionality we decided to go the whole nine yards. The VS Code debug extension API is the api that extension authors can use to interact with any VS Code debug session from an extension. This makes it even possible to create custom UI for specific debug functionality (which is not possible from a debug adapter alone). The VS Code debug extension API is completely unrelated to the debug protocol. Since we now have a prototype of a extension-based "Script Explorer", we can use it as the vehicle to design/validate the debug protocol and the UI. So the next step will be to use the "official debug adapter protocol for loaded scripts" instead of the private "getLoadedScripts" request. But before we "bless" the proposal from this protocol change request into the "official debug adapter protocol for loaded scripts", I would like to understand a few things: "Scripts" are not a concept that all runtimes/debuggers support. For C# and C++ we've introduced a full "modules" complex some time ago, and we envisioned that "modules" would cover node's "scripts" as well.
I just want to avoid that we introduce another very specific protocol complex "scripts" although we got already the "modules" complex for that. /cc @dlebu @andrewcrawley @richardstanton @gregg-miskelly @DavidKarlas |
Thanks for the clarification! As you note, "Scripts" and "Modules" are similar concepts. My original thought (see comment 2) was to make a script be a kind of module, but we ended up leaning towards making "scripts" a separate concept because of several semantic differences:
To answer your specific questions:
|
Could we try to avoid introducing the If we introduce a new One way to improve this would be by making a But if we look closer at the two additional attributes
So my proposal would be to fold Alternatively (to "sources") we could introduce a dictionary "related" where the key denotes the type of relation (e.g. "sources") and the value is the set of linked sources. But since I'm not aware of a convincing example for another type of "related" sources, I think we do not need this now. Here is the modified proposal: export interface Source {
//.... existing attributes
/** An optional list of sources that are related to the main source.
These may be the source that generated the main source.
*/
sources?: Source[];
}
/** Event message for 'loadedSource' event type.
The event indicates that some source has been added or removed from the set of all loaded sources.
*/
export interface LoadedSourceEvent extends Event {
// event: 'loadedSource';
body: {
/** The reason for the event. */
reason: 'new' | 'removed';
/** The new or removed source. */
source: Source;
};
}
export interface Capabilities {
// ...
/** The debug adapter supports the 'loadedSources' request. */
supportsLoadedSourcesRequest?: boolean;
// ...
}
/** Retrieves the set of all sources currently loaded by the debugged process. */
export interface LoadedSourcesRequest extends Request {
// command: 'loadedSources';
arguments: LoadedSourcesArguments;
}
/** Arguments for 'loadedSources' request.
The 'loadedSources' request has no standardized arguments.
*/
export interface LoadedSourcesArguments {
}
/** Response to 'loadedSources' request. */
export interface LoadedSourcesResponse extends Response {
body?: {
/** Set of loaded sources. */
sources: Source[];
};
} @dlebu @andrewcrawley @richardstanton @roblourens @gregg-miskelly |
Yeah, our intent with the The purpose of the "id" property was basically just to make it easier to figure out what script is being unloaded in a I'm OK with your proposal. @richardstanton, any thoughts? |
The Chrome debugging protocol has a
scriptParsed
event that is being fired every time the virtual machine parses a script.I talked to @roblourens about this and he told me about the Open Loaded Script command which causes the debug adapter to return a list of all loaded scripts, but an event would be a lot better since it eliminates polling.
The text was updated successfully, but these errors were encountered: