-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prettier fix
- Loading branch information
Showing
5 changed files
with
267 additions
and
1 deletion.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
// Adapter from https://github.com/microsoft/vscode-java-debug/blob/main/src/hotCodeReplace.ts | ||
|
||
import * as vscode from "vscode"; | ||
|
||
import { SCALA_LANGID } from "./consts"; | ||
import { window } from "vscode"; | ||
|
||
const suppressedReasons: Set<string> = new Set(); | ||
|
||
export const YES_BUTTON = "Yes"; | ||
|
||
export const NO_BUTTON = "No"; | ||
|
||
const NEVER_BUTTON = "Do not show again"; | ||
|
||
enum HcrChangeType { | ||
ERROR = "ERROR", | ||
WARNING = "WARNING", | ||
STARTING = "STARTING", | ||
END = "END", | ||
BUILD_COMPLETE = "BUILD_COMPLETE", | ||
} | ||
|
||
export function initializeHotCodeReplace(context: vscode.ExtensionContext) { | ||
vscode.commands.executeCommand( | ||
"setContext", | ||
"scalaHotReloadOn", | ||
hotReplaceIsOn() | ||
); | ||
vscode.workspace.onDidChangeConfiguration((event) => { | ||
if (event.affectsConfiguration("metals.debug.settings.hotCodeReplace")) { | ||
vscode.commands.executeCommand( | ||
"setContext", | ||
"scalaHotReloadOn", | ||
hotReplaceIsOn() | ||
); | ||
} | ||
}); | ||
vscode.debug.onDidStartDebugSession((session) => { | ||
if (session?.configuration.noDebug && !vscode.debug.activeDebugSession) { | ||
vscode.commands.executeCommand("setContext", "scalaHotReloadOn", false); | ||
} | ||
}); | ||
vscode.debug.onDidChangeActiveDebugSession((session) => { | ||
vscode.commands.executeCommand( | ||
"setContext", | ||
"scalaHotReloadOn", | ||
session && !session.configuration.noDebug | ||
); | ||
}); | ||
context.subscriptions.push( | ||
vscode.debug.onDidTerminateDebugSession((session) => { | ||
const t = session ? session.type : undefined; | ||
if (t === SCALA_LANGID) { | ||
suppressedReasons.clear(); | ||
} | ||
}) | ||
); | ||
} | ||
|
||
export function handleHotCodeReplaceCustomEvent( | ||
hcrEvent: vscode.DebugSessionCustomEvent | ||
) { | ||
if (hcrEvent.body.changeType === HcrChangeType.BUILD_COMPLETE) { | ||
if (hotReplaceIsOn()) { | ||
return vscode.window.withProgress( | ||
{ location: vscode.ProgressLocation.Window }, | ||
(progress) => { | ||
progress.report({ message: "Applying code changes..." }); | ||
return hcrEvent.session.customRequest("redefineClasses"); | ||
} | ||
); | ||
} | ||
} | ||
|
||
if ( | ||
hcrEvent.body.changeType === HcrChangeType.ERROR || | ||
hcrEvent.body.changeType === HcrChangeType.WARNING | ||
) { | ||
if (!suppressedReasons.has(hcrEvent.body.message)) { | ||
window | ||
.showWarningMessage( | ||
`Hot code replace failed - ${hcrEvent.body.message}. Would you like to restart the debug session?` | ||
) | ||
.then((res) => { | ||
if (res === NEVER_BUTTON) { | ||
suppressedReasons.add(hcrEvent.body.message); | ||
} else if (res === YES_BUTTON) { | ||
vscode.commands.executeCommand("workbench.action.debug.restart"); | ||
} | ||
}); | ||
} | ||
} | ||
return undefined; | ||
} | ||
|
||
function hotReplaceIsOn(): boolean { | ||
return ( | ||
vscode.workspace | ||
.getConfiguration("metals.debug.settings") | ||
.get("hotCodeReplace") ?? false | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters