Skip to content
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

Make hot reload a standard request #398

Open
helin24 opened this issue May 30, 2023 · 8 comments
Open

Make hot reload a standard request #398

helin24 opened this issue May 30, 2023 · 8 comments
Labels
feature-request Request for new features or functionality

Comments

@helin24
Copy link

helin24 commented May 30, 2023

Within the Dart extension, we use a custom request to ask our running application to update source code files that have changed (see https://github.com/Dart-Code/Dart-Code/blob/master/src/extension/dart/hot_reload_save_handler.ts#L116). We’re wondering if this could be made into a standard event type, e.g.:

interface HotReloadRequest extends Request {
  command: 'hotReload';

  arguments: HotReloadArguments;
}

interface HotReloadArguments {
  /** This describes how the hot reload was triggered, e.g. manual request vs automatically on save */
  reason: string;
}
@DanTup
Copy link
Contributor

DanTup commented May 30, 2023

Searching for "hot reload" in the VS Code repo suggests there are other frameworks that support this (besides Dart/Flutter). Having it as a first-class feature would make it easier to get into other editors (it's less likely this will happen if it's language-specific).

Additionally, there are unresolved issues about breakpoints and source modifications in microsoft/vscode#175872. The DA is not given enough information to correctly handle changing breakpoints in unsaved files. By having the editor understand when hot-reload occurs, it can better tell whether the lines it's tracking for breakpoints are valid for the code that's currently loaded, or whether stale code is running (in which case re-sending the full set of breakpoints for a file might mess things up).

@roblourens
Copy link
Member

Even if other runtimes support this, I wonder whether they would agree on the exact semantics enough for it to make sense to be driven by the editor. I'd probably prefer to fix the issues with breakpoints and modified source files to enable debuggers to implement it however they need to for their runtime.

@roblourens roblourens added the feature-request Request for new features or functionality label Jun 1, 2023
@DanTup
Copy link
Contributor

DanTup commented Jun 1, 2023

One additional issue with being completely custom, is that the UI requires completely custom work in the editor. There's no way for DAP to say "I have this custom command, show it in the command palette and this button on the debug toolbar" so it requires a language-specific plugin in the editor.

While it would be nice to allow a DA to provide this, because the UI differs between DAP clients it would be hard to define "show this button in the debug toolbar next to the restart button" for VS Code in a way that is generic for other editors.

(but, I agree it would be good to fix the breakpoint issues in any case 🙂)

@puremourning
Copy link
Contributor

The way the Java debug adapter works is that it tells the DAP Client "The source has changed, issue the following request to hot-reload". This affords the client the ability to ask the user if they wish to reload:

Screenshot 2023-06-01 at 12 53 16

If I recall correctly, the Dart approach is that the DAP Client is expected to somehow "just know" when to send this request? I believe some vimspector users have configured up a way to do this on save: https://github.com/puremourning/vimspector/wiki/Additional-Language-Support#hot-reload

My response is basically this: puremourning/vimspector#619 (comment)

@DanTup
Copy link
Contributor

DanTup commented Jun 1, 2023

The way the Java debug adapter works is that it tells the DAP Client "The source has changed, issue the following request to hot-reload".

Presumably this involves custom events and custom code in the editor?

If I recall correctly, the Dart approach is that the DAP Client is expected to somehow "just know" when to send this request?

The user can explicitly trigger Hot Reload by clicking a debug toolbar button or triggering the command from the command palette. Additionally, the Dart extension provides a setting that lets you trigger it automatically on-save.

It seems like both Java and DAP have their own non-standard ways of doing this, which is exactly the reason for this issue.

@puremourning
Copy link
Contributor

The way the Java debug adapter works is that it tells the DAP Client "The source has changed, issue the following request to hot-reload".

Presumably this involves custom events and custom code in the editor?

Yes, indeed it does. So I fully support having a DAP-blessed protocol for this. Just raising here that there are already 2 different approaches that I am aware of.

If I recall correctly, the Dart approach is that the DAP Client is expected to somehow "just know" when to send this request?

The user can explicitly trigger Hot Reload by clicking a debug toolbar button or triggering the command from the command palette. Additionally, the Dart extension provides a setting that lets you trigger it automatically on-save.

Right

It seems like both Java and DAP have their own non-standard ways of doing this, which is exactly the reason for this issue.

Completely agree!

@DanTup
Copy link
Contributor

DanTup commented Jun 1, 2023

So I fully support having a DAP-blessed protocol for this. Just raising here that there are already 2 different approaches that I am aware of.

Ah, gotcha! I thought you were suggesting Dart could do what Java was doing, but I understand now. Sorry for the noise :-)

@puremourning
Copy link
Contributor

So I fully support having a DAP-blessed protocol for this. Just raising here that there are already 2 different approaches that I am aware of.

Ah, gotcha! I thought you were suggesting Dart could do what Java was doing, but I understand now. Sorry for the noise :-)

I don't especially have a preference between the two approaches; I happened to have implemented the java one in vimspector, as it doesn't require any additional UI or teaching users that the feature exists, but it can be a bit annoying if it keeps popping up...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

4 participants