From f50808119401b2b92da14c911f7ca0259bda980b Mon Sep 17 00:00:00 2001 From: Lucas Nouguier Date: Mon, 14 Aug 2023 15:55:43 +0200 Subject: [PATCH 1/5] added hot code reload button cleaning up allow hcr from specific metals version auto save files before hcr --- .../metals-vscode/icons/hot_code_replace.svg | 13 ++ packages/metals-vscode/package.json | 23 +++- packages/metals-vscode/src/extension.ts | 11 ++ packages/metals-vscode/src/hotCodeReplace.ts | 112 ++++++++++++++++++ packages/metals-vscode/yarn.lock | 57 +++++++++ 5 files changed, 215 insertions(+), 1 deletion(-) create mode 100644 packages/metals-vscode/icons/hot_code_replace.svg create mode 100644 packages/metals-vscode/src/hotCodeReplace.ts diff --git a/packages/metals-vscode/icons/hot_code_replace.svg b/packages/metals-vscode/icons/hot_code_replace.svg new file mode 100644 index 000000000..3e0704763 --- /dev/null +++ b/packages/metals-vscode/icons/hot_code_replace.svg @@ -0,0 +1,13 @@ + + + + +lightning +Created with Sketch. + + + + diff --git a/packages/metals-vscode/package.json b/packages/metals-vscode/package.json index 119eeb897..fbac4af1b 100644 --- a/packages/metals-vscode/package.json +++ b/packages/metals-vscode/package.json @@ -218,6 +218,11 @@ "configuration": { "title": "Metals", "properties": { + "metals.debug.settings.hotCodeReplace": { + "type": "boolean", + "default": false, + "markdownDescription": "Allow Hot Code Replace (HCR) while debugging. Only available since Metals 1.0.X" + }, "metals.serverVersion": { "type": "string", "default": "1.2.1", @@ -422,6 +427,14 @@ } }, "commands": [ + { + "command": "metals.debug.hotCodeReplace", + "title": "Hot Code Replace", + "icon": { + "light": "icons/hot_code_replace.svg", + "dark": "icons/hot_code_replace.svg" + } + }, { "command": "metals.reveal-active-file", "category": "Metals", @@ -695,6 +708,13 @@ "when": "view == metalsPackages" } ], + "debug/toolBar": [ + { + "command": "metals.debug.hotCodeReplace", + "group": "navigation@100", + "when": "scalaHotReloadOn" + } + ], "commandPalette": [ { "command": "metals.show-tasty", @@ -1088,7 +1108,8 @@ "metals-languageclient": "file:../metals-languageclient", "promisify-child-process": "4.1.1", "semver": "^7.5.2", - "vscode-languageclient": "8.1.0" + "vscode-languageclient": "8.1.0", + "vscode-extension-telemetry-wrapper": "^0.13.3" }, "extensionPack": [ "scala-lang.scala" diff --git a/packages/metals-vscode/src/extension.ts b/packages/metals-vscode/src/extension.ts index 9f5788520..b37ff2bdc 100644 --- a/packages/metals-vscode/src/extension.ts +++ b/packages/metals-vscode/src/extension.ts @@ -105,6 +105,8 @@ import { SCALA_LANGID, } from "./consts"; import { ScalaCodeLensesParams } from "./debugger/types"; +import { applyHCR, initializeHotCodeReplace } from "./hotCodeReplace"; +import { instrumentOperationAsVsCodeCommand } from "vscode-extension-telemetry-wrapper"; const outputChannel = window.createOutputChannel("Metals"); const downloadJava = "Download Java"; @@ -1188,6 +1190,15 @@ function launchMetals( } ); context.subscriptions.push(decorationsRangesDidChangeDispoasable); + context.subscriptions.push( + instrumentOperationAsVsCodeCommand( + "metals.debug.hotCodeReplace", + async () => { + await applyHCR(); + } + ) + ); + initializeHotCodeReplace(); }, (reason) => { if (reason instanceof Error) { diff --git a/packages/metals-vscode/src/hotCodeReplace.ts b/packages/metals-vscode/src/hotCodeReplace.ts new file mode 100644 index 000000000..b8f388e97 --- /dev/null +++ b/packages/metals-vscode/src/hotCodeReplace.ts @@ -0,0 +1,112 @@ +// 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 { DebugSession, commands } from "vscode"; + +export function initializeHotCodeReplace() { + 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 && hotReplaceIsOn() + ); + }); +} + +export async function applyHCR() { + const debugSession: DebugSession | undefined = + vscode.debug.activeDebugSession; + if (!debugSession) { + return; + } + + const serverVersion = + vscode.workspace.getConfiguration("metals").get("serverVersion") ?? + ""; + if (serverVersion < "1.0.1") { + vscode.workspace + .getConfiguration("metals.debug.settings") + .update("hotCodeReplace", false, vscode.ConfigurationTarget.Workspace); + vscode.window.showErrorMessage( + "Hot code replace is only supported since scala-debug-adapter 3.1.5,\nwhich is shipped with metals 1.0.1" + ); + return; + } + if (debugSession.configuration.noDebug) { + vscode.window + .showWarningMessage( + "Failed to apply the changes because hot code replace is not supported by run mode, " + + "would you like to restart the program?" + ) + .then((res) => { + if (res === "Yes") { + vscode.commands.executeCommand("workbench.action.debug.restart"); + } + }); + + return; + } + + await commands.executeCommand("workbench.action.files.save"); + const redefineRequest = debugSession.customRequest("redefineClasses"); + vscode.window.setStatusBarMessage( + "$(sync~spin) Applying code changes...", + redefineRequest + ); + const response = await redefineRequest; + + if (response?.errorMessage) { + vscode.window.showErrorMessage(response.errorMessage); + return; + } + + const NO_HCR = "Disable HCR"; + + if (!response?.changedClasses?.length) { + const res = await vscode.window.showWarningMessage( + "No classes were reloaded. Did you applied your changes ?", + "Ok", + NO_HCR + ); + + if (res === NO_HCR) { + vscode.workspace + .getConfiguration("metals.debug.settings") + .update("hotCodeReplace", false, vscode.ConfigurationTarget.Workspace); + vscode.commands.executeCommand("setContext", "scalaHotReloadOn", false); + } + return; + } + + const changed = response.changedClasses.length; + vscode.window.setStatusBarMessage( + `$(check) Class${changed > 1 ? "es" : ""} successfully reloaded`, + 5 * 1000 + ); +} + +function hotReplaceIsOn(): boolean { + return ( + vscode.workspace + .getConfiguration("metals.debug.settings") + .get("hotCodeReplace") ?? false + ); +} diff --git a/packages/metals-vscode/yarn.lock b/packages/metals-vscode/yarn.lock index 8bd7fdbdd..ad05b74ec 100644 --- a/packages/metals-vscode/yarn.lock +++ b/packages/metals-vscode/yarn.lock @@ -53,6 +53,42 @@ resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz#b520529ec21d8e5945a1851dfd1c32e94e39ff45" integrity sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA== +"@microsoft/1ds-core-js@3.2.13", "@microsoft/1ds-core-js@^3.2.3": + version "3.2.13" + resolved "https://registry.yarnpkg.com/@microsoft/1ds-core-js/-/1ds-core-js-3.2.13.tgz#0c105ed75091bae3f1555c0334704fa9911c58fb" + integrity sha512-CluYTRWcEk0ObG5EWFNWhs87e2qchJUn0p2D21ZUa3PWojPZfPSBs4//WIE0MYV8Qg1Hdif2ZTwlM7TbYUjfAg== + dependencies: + "@microsoft/applicationinsights-core-js" "2.8.15" + "@microsoft/applicationinsights-shims" "^2.0.2" + "@microsoft/dynamicproto-js" "^1.1.7" + +"@microsoft/1ds-post-js@^3.2.3": + version "3.2.13" + resolved "https://registry.yarnpkg.com/@microsoft/1ds-post-js/-/1ds-post-js-3.2.13.tgz#560aacac8a92fdbb79e8c2ebcb293d56e19f51aa" + integrity sha512-HgS574fdD19Bo2vPguyznL4eDw7Pcm1cVNpvbvBLWiW3x4e1FCQ3VMXChWnAxCae8Hb0XqlA2sz332ZobBavTA== + dependencies: + "@microsoft/1ds-core-js" "3.2.13" + "@microsoft/applicationinsights-shims" "^2.0.2" + "@microsoft/dynamicproto-js" "^1.1.7" + +"@microsoft/applicationinsights-core-js@2.8.15": + version "2.8.15" + resolved "https://registry.yarnpkg.com/@microsoft/applicationinsights-core-js/-/applicationinsights-core-js-2.8.15.tgz#8fa466474260e01967fe649f14dd9e5ff91dcdc8" + integrity sha512-yYAs9MyjGr2YijQdUSN9mVgT1ijI1FPMgcffpaPmYbHAVbQmF7bXudrBWHxmLzJlwl5rfep+Zgjli2e67lwUqQ== + dependencies: + "@microsoft/applicationinsights-shims" "2.0.2" + "@microsoft/dynamicproto-js" "^1.1.9" + +"@microsoft/applicationinsights-shims@2.0.2", "@microsoft/applicationinsights-shims@^2.0.2": + version "2.0.2" + resolved "https://registry.yarnpkg.com/@microsoft/applicationinsights-shims/-/applicationinsights-shims-2.0.2.tgz#92b36a09375e2d9cb2b4203383b05772be837085" + integrity sha512-PoHEgsnmcqruLNHZ/amACqdJ6YYQpED0KSRe6J7gIJTtpZC1FfFU9b1fmDKDKtFoUSrPzEh1qzO3kmRZP0betg== + +"@microsoft/dynamicproto-js@^1.1.7", "@microsoft/dynamicproto-js@^1.1.9": + version "1.1.9" + resolved "https://registry.yarnpkg.com/@microsoft/dynamicproto-js/-/dynamicproto-js-1.1.9.tgz#7437db7aa061162ee94e4131b69a62b8dad5dea6" + integrity sha512-n1VPsljTSkthsAFYdiWfC+DKzK2WwcRp83Y1YAqdX552BstvsDjft9YXppjUzp11BPsapDoO1LDgrDB0XVsfNQ== + "@nodelib/fs.scandir@2.1.5": version "2.1.5" resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz#7619c2eb21b25483f6d167548b4cfd5a7488c3d5" @@ -282,6 +318,14 @@ async "^3.2.2" semver "^7.3.5" +"@vscode/extension-telemetry@^0.6.2": + version "0.6.2" + resolved "https://registry.yarnpkg.com/@vscode/extension-telemetry/-/extension-telemetry-0.6.2.tgz#b86814ee680615730da94220c2b03ea9c3c14a8e" + integrity sha512-yb/wxLuaaCRcBAZtDCjNYSisAXz3FWsSqAha5nhHcYxx2ZPdQdWuZqVXGKq0ZpHVndBWWtK6XqtpCN2/HB4S1w== + dependencies: + "@microsoft/1ds-core-js" "^3.2.3" + "@microsoft/1ds-post-js" "^3.2.3" + "@vscode/test-electron@^2.3.0": version "2.3.0" resolved "https://registry.yarnpkg.com/@vscode/test-electron/-/test-electron-2.3.0.tgz#de0ba2f5d36546a83cd481b458cbdbb7cc0f7049" @@ -2445,6 +2489,19 @@ util-deprecate@^1.0.1, util-deprecate@~1.0.1: resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" integrity sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8= +uuid@^8.3.2: + version "8.3.2" + resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2" + integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg== + +vscode-extension-telemetry-wrapper@^0.13.3: + version "0.13.3" + resolved "https://registry.yarnpkg.com/vscode-extension-telemetry-wrapper/-/vscode-extension-telemetry-wrapper-0.13.3.tgz#685fe92843b07fe785e416926721e26f867c3a69" + integrity sha512-k/PbUbH9/xqiMXI2g2RXpDg+4/v08t3NzdPc7HuDPF3A1XcYkgYwsPnS/bqsKZNymSQdbLvVuie6STMxbDX9KQ== + dependencies: + "@vscode/extension-telemetry" "^0.6.2" + uuid "^8.3.2" + vscode-jsonrpc@8.1.0: version "8.1.0" resolved "https://registry.yarnpkg.com/vscode-jsonrpc/-/vscode-jsonrpc-8.1.0.tgz#cb9989c65e219e18533cc38e767611272d274c94" From db4e1d3c2a762218b7c04a3667340421b3c0ce2e Mon Sep 17 00:00:00 2001 From: Lucas Nouguier Date: Sun, 27 Aug 2023 11:31:15 +0200 Subject: [PATCH 2/5] applied review --- .vscode/settings.json | 22 +++++++++++++++++++- packages/metals-vscode/src/hotCodeReplace.ts | 14 +------------ 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 676628de0..805973529 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -10,5 +10,25 @@ "typescript.tsdk": "node_modules/typescript/lib", "files.watcherExclude": { "**/target": true - } + }, + "workbench.colorCustomizations": { + "activityBar.activeBackground": "#0083dc", + "activityBar.background": "#0083dc", + "activityBar.foreground": "#e7e7e7", + "activityBar.inactiveForeground": "#e7e7e799", + "activityBarBadge.background": "#9f005f", + "activityBarBadge.foreground": "#e7e7e7", + "commandCenter.border": "#e7e7e799", + "sash.hoverBorder": "#0083dc", + "statusBar.background": "#0065a9", + "statusBar.foreground": "#e7e7e7", + "statusBarItem.hoverBackground": "#0083dc", + "statusBarItem.remoteBackground": "#0065a9", + "statusBarItem.remoteForeground": "#e7e7e7", + "titleBar.activeBackground": "#0065a9", + "titleBar.activeForeground": "#e7e7e7", + "titleBar.inactiveBackground": "#0065a999", + "titleBar.inactiveForeground": "#e7e7e799" + }, + "peacock.color": "#0065A9" } diff --git a/packages/metals-vscode/src/hotCodeReplace.ts b/packages/metals-vscode/src/hotCodeReplace.ts index b8f388e97..ba76224e0 100644 --- a/packages/metals-vscode/src/hotCodeReplace.ts +++ b/packages/metals-vscode/src/hotCodeReplace.ts @@ -38,18 +38,6 @@ export async function applyHCR() { return; } - const serverVersion = - vscode.workspace.getConfiguration("metals").get("serverVersion") ?? - ""; - if (serverVersion < "1.0.1") { - vscode.workspace - .getConfiguration("metals.debug.settings") - .update("hotCodeReplace", false, vscode.ConfigurationTarget.Workspace); - vscode.window.showErrorMessage( - "Hot code replace is only supported since scala-debug-adapter 3.1.5,\nwhich is shipped with metals 1.0.1" - ); - return; - } if (debugSession.configuration.noDebug) { vscode.window .showWarningMessage( @@ -82,7 +70,7 @@ export async function applyHCR() { if (!response?.changedClasses?.length) { const res = await vscode.window.showWarningMessage( - "No classes were reloaded. Did you applied your changes ?", + "No classes were reloaded", "Ok", NO_HCR ); From 10feada6a5949038c658e386e55ac9a09585da20 Mon Sep 17 00:00:00 2001 From: Lucas Nouguier Date: Tue, 29 Aug 2023 13:56:26 +0200 Subject: [PATCH 3/5] applied review --- .vscode/settings.json | 22 +------- packages/metals-vscode/package.json | 7 ++- packages/metals-vscode/src/extension.ts | 12 ++--- packages/metals-vscode/src/hotCodeReplace.ts | 35 ++++-------- packages/metals-vscode/yarn.lock | 57 -------------------- 5 files changed, 18 insertions(+), 115 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 805973529..676628de0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -10,25 +10,5 @@ "typescript.tsdk": "node_modules/typescript/lib", "files.watcherExclude": { "**/target": true - }, - "workbench.colorCustomizations": { - "activityBar.activeBackground": "#0083dc", - "activityBar.background": "#0083dc", - "activityBar.foreground": "#e7e7e7", - "activityBar.inactiveForeground": "#e7e7e799", - "activityBarBadge.background": "#9f005f", - "activityBarBadge.foreground": "#e7e7e7", - "commandCenter.border": "#e7e7e799", - "sash.hoverBorder": "#0083dc", - "statusBar.background": "#0065a9", - "statusBar.foreground": "#e7e7e7", - "statusBarItem.hoverBackground": "#0083dc", - "statusBarItem.remoteBackground": "#0065a9", - "statusBarItem.remoteForeground": "#e7e7e7", - "titleBar.activeBackground": "#0065a9", - "titleBar.activeForeground": "#e7e7e7", - "titleBar.inactiveBackground": "#0065a999", - "titleBar.inactiveForeground": "#e7e7e799" - }, - "peacock.color": "#0065A9" + } } diff --git a/packages/metals-vscode/package.json b/packages/metals-vscode/package.json index fbac4af1b..a8db8a0fe 100644 --- a/packages/metals-vscode/package.json +++ b/packages/metals-vscode/package.json @@ -218,10 +218,10 @@ "configuration": { "title": "Metals", "properties": { - "metals.debug.settings.hotCodeReplace": { + "metals.hotCodeReplace": { "type": "boolean", "default": false, - "markdownDescription": "Allow Hot Code Replace (HCR) while debugging. Only available since Metals 1.0.X" + "markdownDescription": "Allow Hot Code Replace (HCR) while debugging" }, "metals.serverVersion": { "type": "string", @@ -1108,8 +1108,7 @@ "metals-languageclient": "file:../metals-languageclient", "promisify-child-process": "4.1.1", "semver": "^7.5.2", - "vscode-languageclient": "8.1.0", - "vscode-extension-telemetry-wrapper": "^0.13.3" + "vscode-languageclient": "8.1.0" }, "extensionPack": [ "scala-lang.scala" diff --git a/packages/metals-vscode/src/extension.ts b/packages/metals-vscode/src/extension.ts index b37ff2bdc..a7b8c1e05 100644 --- a/packages/metals-vscode/src/extension.ts +++ b/packages/metals-vscode/src/extension.ts @@ -106,7 +106,6 @@ import { } from "./consts"; import { ScalaCodeLensesParams } from "./debugger/types"; import { applyHCR, initializeHotCodeReplace } from "./hotCodeReplace"; -import { instrumentOperationAsVsCodeCommand } from "vscode-extension-telemetry-wrapper"; const outputChannel = window.createOutputChannel("Metals"); const downloadJava = "Download Java"; @@ -1190,14 +1189,9 @@ function launchMetals( } ); context.subscriptions.push(decorationsRangesDidChangeDispoasable); - context.subscriptions.push( - instrumentOperationAsVsCodeCommand( - "metals.debug.hotCodeReplace", - async () => { - await applyHCR(); - } - ) - ); + registerCommand("metals.debug.hotCodeReplace", () => { + applyHCR(); + }); initializeHotCodeReplace(); }, (reason) => { diff --git a/packages/metals-vscode/src/hotCodeReplace.ts b/packages/metals-vscode/src/hotCodeReplace.ts index ba76224e0..a09e5e94c 100644 --- a/packages/metals-vscode/src/hotCodeReplace.ts +++ b/packages/metals-vscode/src/hotCodeReplace.ts @@ -7,25 +7,28 @@ import * as vscode from "vscode"; import { DebugSession, commands } from "vscode"; +const HCR_CONFIG = "metals.hotCodeReplace"; +const HCR_ACTIVE = "scalaHotReloadOn"; + export function initializeHotCodeReplace() { vscode.workspace.onDidChangeConfiguration((event) => { - if (event.affectsConfiguration("metals.debug.settings.hotCodeReplace")) { + if (event.affectsConfiguration(HCR_CONFIG)) { vscode.commands.executeCommand( "setContext", - "scalaHotReloadOn", + HCR_ACTIVE, hotReplaceIsOn() ); } }); vscode.debug.onDidStartDebugSession((session) => { if (session?.configuration.noDebug && !vscode.debug.activeDebugSession) { - vscode.commands.executeCommand("setContext", "scalaHotReloadOn", false); + vscode.commands.executeCommand("setContext", HCR_ACTIVE, false); } }); vscode.debug.onDidChangeActiveDebugSession((session) => { vscode.commands.executeCommand( "setContext", - "scalaHotReloadOn", + HCR_ACTIVE, session && !session.configuration.noDebug && hotReplaceIsOn() ); }); @@ -66,21 +69,10 @@ export async function applyHCR() { return; } - const NO_HCR = "Disable HCR"; - if (!response?.changedClasses?.length) { - const res = await vscode.window.showWarningMessage( - "No classes were reloaded", - "Ok", - NO_HCR + vscode.window.showWarningMessage( + "No classes were reloaded, please check the logs" ); - - if (res === NO_HCR) { - vscode.workspace - .getConfiguration("metals.debug.settings") - .update("hotCodeReplace", false, vscode.ConfigurationTarget.Workspace); - vscode.commands.executeCommand("setContext", "scalaHotReloadOn", false); - } return; } @@ -91,10 +83,5 @@ export async function applyHCR() { ); } -function hotReplaceIsOn(): boolean { - return ( - vscode.workspace - .getConfiguration("metals.debug.settings") - .get("hotCodeReplace") ?? false - ); -} +const hotReplaceIsOn = () => + vscode.workspace.getConfiguration("metals").get("hotCodeReplace") ?? false; diff --git a/packages/metals-vscode/yarn.lock b/packages/metals-vscode/yarn.lock index ad05b74ec..8bd7fdbdd 100644 --- a/packages/metals-vscode/yarn.lock +++ b/packages/metals-vscode/yarn.lock @@ -53,42 +53,6 @@ resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz#b520529ec21d8e5945a1851dfd1c32e94e39ff45" integrity sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA== -"@microsoft/1ds-core-js@3.2.13", "@microsoft/1ds-core-js@^3.2.3": - version "3.2.13" - resolved "https://registry.yarnpkg.com/@microsoft/1ds-core-js/-/1ds-core-js-3.2.13.tgz#0c105ed75091bae3f1555c0334704fa9911c58fb" - integrity sha512-CluYTRWcEk0ObG5EWFNWhs87e2qchJUn0p2D21ZUa3PWojPZfPSBs4//WIE0MYV8Qg1Hdif2ZTwlM7TbYUjfAg== - dependencies: - "@microsoft/applicationinsights-core-js" "2.8.15" - "@microsoft/applicationinsights-shims" "^2.0.2" - "@microsoft/dynamicproto-js" "^1.1.7" - -"@microsoft/1ds-post-js@^3.2.3": - version "3.2.13" - resolved "https://registry.yarnpkg.com/@microsoft/1ds-post-js/-/1ds-post-js-3.2.13.tgz#560aacac8a92fdbb79e8c2ebcb293d56e19f51aa" - integrity sha512-HgS574fdD19Bo2vPguyznL4eDw7Pcm1cVNpvbvBLWiW3x4e1FCQ3VMXChWnAxCae8Hb0XqlA2sz332ZobBavTA== - dependencies: - "@microsoft/1ds-core-js" "3.2.13" - "@microsoft/applicationinsights-shims" "^2.0.2" - "@microsoft/dynamicproto-js" "^1.1.7" - -"@microsoft/applicationinsights-core-js@2.8.15": - version "2.8.15" - resolved "https://registry.yarnpkg.com/@microsoft/applicationinsights-core-js/-/applicationinsights-core-js-2.8.15.tgz#8fa466474260e01967fe649f14dd9e5ff91dcdc8" - integrity sha512-yYAs9MyjGr2YijQdUSN9mVgT1ijI1FPMgcffpaPmYbHAVbQmF7bXudrBWHxmLzJlwl5rfep+Zgjli2e67lwUqQ== - dependencies: - "@microsoft/applicationinsights-shims" "2.0.2" - "@microsoft/dynamicproto-js" "^1.1.9" - -"@microsoft/applicationinsights-shims@2.0.2", "@microsoft/applicationinsights-shims@^2.0.2": - version "2.0.2" - resolved "https://registry.yarnpkg.com/@microsoft/applicationinsights-shims/-/applicationinsights-shims-2.0.2.tgz#92b36a09375e2d9cb2b4203383b05772be837085" - integrity sha512-PoHEgsnmcqruLNHZ/amACqdJ6YYQpED0KSRe6J7gIJTtpZC1FfFU9b1fmDKDKtFoUSrPzEh1qzO3kmRZP0betg== - -"@microsoft/dynamicproto-js@^1.1.7", "@microsoft/dynamicproto-js@^1.1.9": - version "1.1.9" - resolved "https://registry.yarnpkg.com/@microsoft/dynamicproto-js/-/dynamicproto-js-1.1.9.tgz#7437db7aa061162ee94e4131b69a62b8dad5dea6" - integrity sha512-n1VPsljTSkthsAFYdiWfC+DKzK2WwcRp83Y1YAqdX552BstvsDjft9YXppjUzp11BPsapDoO1LDgrDB0XVsfNQ== - "@nodelib/fs.scandir@2.1.5": version "2.1.5" resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz#7619c2eb21b25483f6d167548b4cfd5a7488c3d5" @@ -318,14 +282,6 @@ async "^3.2.2" semver "^7.3.5" -"@vscode/extension-telemetry@^0.6.2": - version "0.6.2" - resolved "https://registry.yarnpkg.com/@vscode/extension-telemetry/-/extension-telemetry-0.6.2.tgz#b86814ee680615730da94220c2b03ea9c3c14a8e" - integrity sha512-yb/wxLuaaCRcBAZtDCjNYSisAXz3FWsSqAha5nhHcYxx2ZPdQdWuZqVXGKq0ZpHVndBWWtK6XqtpCN2/HB4S1w== - dependencies: - "@microsoft/1ds-core-js" "^3.2.3" - "@microsoft/1ds-post-js" "^3.2.3" - "@vscode/test-electron@^2.3.0": version "2.3.0" resolved "https://registry.yarnpkg.com/@vscode/test-electron/-/test-electron-2.3.0.tgz#de0ba2f5d36546a83cd481b458cbdbb7cc0f7049" @@ -2489,19 +2445,6 @@ util-deprecate@^1.0.1, util-deprecate@~1.0.1: resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" integrity sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8= -uuid@^8.3.2: - version "8.3.2" - resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2" - integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg== - -vscode-extension-telemetry-wrapper@^0.13.3: - version "0.13.3" - resolved "https://registry.yarnpkg.com/vscode-extension-telemetry-wrapper/-/vscode-extension-telemetry-wrapper-0.13.3.tgz#685fe92843b07fe785e416926721e26f867c3a69" - integrity sha512-k/PbUbH9/xqiMXI2g2RXpDg+4/v08t3NzdPc7HuDPF3A1XcYkgYwsPnS/bqsKZNymSQdbLvVuie6STMxbDX9KQ== - dependencies: - "@vscode/extension-telemetry" "^0.6.2" - uuid "^8.3.2" - vscode-jsonrpc@8.1.0: version "8.1.0" resolved "https://registry.yarnpkg.com/vscode-jsonrpc/-/vscode-jsonrpc-8.1.0.tgz#cb9989c65e219e18533cc38e767611272d274c94" From 2081c319f7aa1761b5fa738c556fca7ab1b45802 Mon Sep 17 00:00:00 2001 From: Adrien Piquerez Date: Mon, 19 Feb 2024 15:18:41 +0100 Subject: [PATCH 4/5] Rename settings --- packages/metals-vscode/package.json | 10 +++++----- .../metals-vscode/src/{ => debugger}/hotCodeReplace.ts | 8 ++++---- packages/metals-vscode/src/extension.ts | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) rename packages/metals-vscode/src/{ => debugger}/hotCodeReplace.ts (90%) diff --git a/packages/metals-vscode/package.json b/packages/metals-vscode/package.json index a8db8a0fe..d17246a41 100644 --- a/packages/metals-vscode/package.json +++ b/packages/metals-vscode/package.json @@ -218,11 +218,6 @@ "configuration": { "title": "Metals", "properties": { - "metals.hotCodeReplace": { - "type": "boolean", - "default": false, - "markdownDescription": "Allow Hot Code Replace (HCR) while debugging" - }, "metals.serverVersion": { "type": "string", "default": "1.2.1", @@ -348,6 +343,11 @@ "default": false, "markdownDescription": "When this option is enabled, when user pastes any snippet into a Scala file, Metals will try to adjust the indentation to that of the current cursor." }, + "metals.debug.hotCodeReplace": { + "type": "boolean", + "default": false, + "markdownDescription": "Enable Hot Code Replace while debugging." + }, "metals.verboseCompilation": { "type": "boolean", "default": false, diff --git a/packages/metals-vscode/src/hotCodeReplace.ts b/packages/metals-vscode/src/debugger/hotCodeReplace.ts similarity index 90% rename from packages/metals-vscode/src/hotCodeReplace.ts rename to packages/metals-vscode/src/debugger/hotCodeReplace.ts index a09e5e94c..92d27e6b9 100644 --- a/packages/metals-vscode/src/hotCodeReplace.ts +++ b/packages/metals-vscode/src/debugger/hotCodeReplace.ts @@ -1,18 +1,17 @@ // 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 +// Adapted from https://github.com/microsoft/vscode-java-debug/blob/main/src/hotCodeReplace.ts import * as vscode from "vscode"; import { DebugSession, commands } from "vscode"; -const HCR_CONFIG = "metals.hotCodeReplace"; const HCR_ACTIVE = "scalaHotReloadOn"; export function initializeHotCodeReplace() { vscode.workspace.onDidChangeConfiguration((event) => { - if (event.affectsConfiguration(HCR_CONFIG)) { + if (event.affectsConfiguration("metals.debug.hotCodeReplace")) { vscode.commands.executeCommand( "setContext", HCR_ACTIVE, @@ -84,4 +83,5 @@ export async function applyHCR() { } const hotReplaceIsOn = () => - vscode.workspace.getConfiguration("metals").get("hotCodeReplace") ?? false; + vscode.workspace.getConfiguration("metals").get("debug.hotCodeReplace") ?? + false; diff --git a/packages/metals-vscode/src/extension.ts b/packages/metals-vscode/src/extension.ts index a7b8c1e05..0ae86e169 100644 --- a/packages/metals-vscode/src/extension.ts +++ b/packages/metals-vscode/src/extension.ts @@ -105,7 +105,7 @@ import { SCALA_LANGID, } from "./consts"; import { ScalaCodeLensesParams } from "./debugger/types"; -import { applyHCR, initializeHotCodeReplace } from "./hotCodeReplace"; +import { applyHCR, initializeHotCodeReplace } from "./debugger/hotCodeReplace"; const outputChannel = window.createOutputChannel("Metals"); const downloadJava = "Download Java"; From 3630fa0ad6e0418e1ad04748ae399f6ecf7c9f1f Mon Sep 17 00:00:00 2001 From: Adrien Piquerez Date: Thu, 22 Feb 2024 11:42:20 +0100 Subject: [PATCH 5/5] remove hotCodeReplace setting --- packages/metals-vscode/package.json | 5 ----- .../src/debugger/hotCodeReplace.ts | 17 ++--------------- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/packages/metals-vscode/package.json b/packages/metals-vscode/package.json index d17246a41..8768c11c5 100644 --- a/packages/metals-vscode/package.json +++ b/packages/metals-vscode/package.json @@ -343,11 +343,6 @@ "default": false, "markdownDescription": "When this option is enabled, when user pastes any snippet into a Scala file, Metals will try to adjust the indentation to that of the current cursor." }, - "metals.debug.hotCodeReplace": { - "type": "boolean", - "default": false, - "markdownDescription": "Enable Hot Code Replace while debugging." - }, "metals.verboseCompilation": { "type": "boolean", "default": false, diff --git a/packages/metals-vscode/src/debugger/hotCodeReplace.ts b/packages/metals-vscode/src/debugger/hotCodeReplace.ts index 92d27e6b9..fb346cfea 100644 --- a/packages/metals-vscode/src/debugger/hotCodeReplace.ts +++ b/packages/metals-vscode/src/debugger/hotCodeReplace.ts @@ -10,15 +10,6 @@ import { DebugSession, commands } from "vscode"; const HCR_ACTIVE = "scalaHotReloadOn"; export function initializeHotCodeReplace() { - vscode.workspace.onDidChangeConfiguration((event) => { - if (event.affectsConfiguration("metals.debug.hotCodeReplace")) { - vscode.commands.executeCommand( - "setContext", - HCR_ACTIVE, - hotReplaceIsOn() - ); - } - }); vscode.debug.onDidStartDebugSession((session) => { if (session?.configuration.noDebug && !vscode.debug.activeDebugSession) { vscode.commands.executeCommand("setContext", HCR_ACTIVE, false); @@ -28,7 +19,7 @@ export function initializeHotCodeReplace() { vscode.commands.executeCommand( "setContext", HCR_ACTIVE, - session && !session.configuration.noDebug && hotReplaceIsOn() + session && !session.configuration.noDebug ); }); } @@ -77,11 +68,7 @@ export async function applyHCR() { const changed = response.changedClasses.length; vscode.window.setStatusBarMessage( - `$(check) Class${changed > 1 ? "es" : ""} successfully reloaded`, + `$(check) ${changed} Class${changed > 1 ? "es" : ""} reloaded`, 5 * 1000 ); } - -const hotReplaceIsOn = () => - vscode.workspace.getConfiguration("metals").get("debug.hotCodeReplace") ?? - false;