diff --git a/vscode/l10n/bundle.l10n.en.json b/vscode/l10n/bundle.l10n.en.json index ae00e1c..4d8a984 100644 --- a/vscode/l10n/bundle.l10n.en.json +++ b/vscode/l10n/bundle.l10n.en.json @@ -52,7 +52,9 @@ "jdk.extension.cache.label.confirmation.cancel":"Cancel", "jdk.extension.cache.message.cacheCleared":"Cache cleared successfully for this workspace", "jdk.extension.cache.label.reloadWindow":"Reload window", - "jdk.extension.cache.message.noUserDir":"Cannot find userdir path", + "jdk.extension.cache.label.openLSUserDir": "Open cache directory", + "jdk.extension.cache.message.reloadWindow.afterUserDirDeletion": "Please reload the window after deleting cache directory", + "jdk.extension.cache.message.noUserDir":"Cannot find cachedir path", "jdk.extension.command.progress.compilingWorkSpace": "Compiling workspace...", "jdk.extension.command.progress.compilingProject": "Compiling...", "jdk.extension.command.progress.cleaningWorkSpace": "Cleaning workspace...", @@ -91,7 +93,8 @@ "jdk.extension.error_msg.doesntSupportNotebookCellExecution":"Language Server for {client} doesn't support notebook cell execution", "jdk.extension.error_msg.doesntSupportJShellExecution":"Language Server for {client} doesn't support JShell execution", "jdk.extension.error_msg.noSuperImpl":"No super implementation found", - "jdk.extension.error_msg.cacheDeletionError":"Error deleting the cache", + "jdk.extension.error_msg.cacheDeletionError":"Error deleting the cache. Please try deleting this directory manually.", + "jdk.extension.error_msg.cacheDeletion.notOpenUserDir":"Error opening cache directory in explorer. Please try opening and deleting this {userDir} directory manually. Reload the window after deletion.", "jdk.extension.message.cacheDeleted":"Cache deleted successfully", "jdk.extension.cache.error_msg.cannotFindWrkSpacePath":"Cannot find workspace path", "jdk.extension.debugger.error_msg.debugAdapterNotInitialized":"Oracle Java extension Debug Server Adapter not yet initialized. Please wait for a while and try again.", diff --git a/vscode/l10n/bundle.l10n.ja.json b/vscode/l10n/bundle.l10n.ja.json index 490002a..ccde5eb 100755 --- a/vscode/l10n/bundle.l10n.ja.json +++ b/vscode/l10n/bundle.l10n.ja.json @@ -52,7 +52,9 @@ "jdk.extension.cache.label.confirmation.cancel":"取消", "jdk.extension.cache.message.cacheCleared":"このワークスペースのキャッシュは正常に消去されました", "jdk.extension.cache.label.reloadWindow":"ウィンドウのリロード", - "jdk.extension.cache.message.noUserDir":"userdirパスが見つかりません", + "jdk.extension.cache.label.openLSUserDir": "Open cache directory", + "jdk.extension.cache.message.reloadWindow.afterUserDirDeletion": "Please reload the window after deleting cache directory", + "jdk.extension.cache.message.noUserDir":"cachedirパスが見つかりません", "jdk.extension.command.progress.compilingWorkSpace": "ワークスペースのコンパイル中...", "jdk.extension.command.progress.compilingProject": "コンパイル中...", "jdk.extension.command.progress.cleaningWorkSpace": "ワークスペースのクリーニング...", @@ -91,7 +93,8 @@ "jdk.extension.error_msg.doesntSupportNotebookCellExecution":"{client}の言語サーバーではノートブック・セルの実行はサポートされていません", "jdk.extension.error_msg.doesntSupportJShellExecution":"{client}の言語サーバーではJShellの実行はサポートされていません", "jdk.extension.error_msg.noSuperImpl":"スーパークラスの実装が見つかりません", - "jdk.extension.error_msg.cacheDeletionError":"キャッシュの削除中にエラーが発生しました", + "jdk.extension.error_msg.cacheDeletionError":"Error deleting the cache. Please try deleting this directory manually.", + "jdk.extension.error_msg.cacheDeletion.notOpenUserDir":"Error opening cache directory in explorer. Please try opening and deleting this {userDir} directory manually. Reload the window after deletion.", "jdk.extension.message.cacheDeleted":"キャッシュが正常に削除されました", "jdk.extension.cache.error_msg.cannotFindWrkSpacePath":"ワークスペース・パスが見つかりません", "jdk.extension.debugger.error_msg.debugAdapterNotInitialized":"Oracle Java拡張のデバッグ・サーバー・アダプタが、まだ初期化されていません。しばらく待ってから再試行してください。", diff --git a/vscode/l10n/bundle.l10n.zh-cn.json b/vscode/l10n/bundle.l10n.zh-cn.json index 590939e..5235dc8 100755 --- a/vscode/l10n/bundle.l10n.zh-cn.json +++ b/vscode/l10n/bundle.l10n.zh-cn.json @@ -52,7 +52,9 @@ "jdk.extension.cache.label.confirmation.cancel":"取消", "jdk.extension.cache.message.cacheCleared":"已成功清除此工作区的高速缓存", "jdk.extension.cache.label.reloadWindow":"重新加载窗口", - "jdk.extension.cache.message.noUserDir":"找不到 userdir 路径", + "jdk.extension.cache.label.openLSUserDir": "Open cache directory", + "jdk.extension.cache.message.reloadWindow.afterUserDirDeletion":"Please reload the window after deleting cache directory", + "jdk.extension.cache.message.noUserDir":"找不到 cachedir 路径", "jdk.extension.command.progress.compilingWorkSpace": "正在编译工作区...", "jdk.extension.command.progress.compilingProject": "正在编译...", "jdk.extension.command.progress.cleaningWorkSpace": "正在清除工作区...", @@ -91,7 +93,8 @@ "jdk.extension.error_msg.noSuperImpl":"未找到超类实现", "jdk.extension.error_msg.doesntSupportNotebookCellExecution":"{client} 的语言服务器不支持记事本单元格执行", "jdk.extension.error_msg.doesntSupportJShellExecution":"{client} 的语言服务器不支持 JShell 执行", - "jdk.extension.error_msg.cacheDeletionError":"删除高速缓存时出错", + "jdk.extension.error_msg.cacheDeletionError":"Error deleting the cache. Please try deleting this directory manually.", + "jdk.extension.error_msg.cacheDeletion.notOpenUserDir":"Error opening cache directory in explorer. Please try opening and deleting this {userDir} directory manually. Reload the window after deletion.", "jdk.extension.message.cacheDeleted":"已成功删除高速缓存", "jdk.extension.cache.error_msg.cannotFindWrkSpacePath":"找不到工作区路径", "jdk.extension.debugger.error_msg.debugAdapterNotInitialized":"Oracle Java扩展调试服务器适配器尚未初始化。请稍候,然后重试。", diff --git a/vscode/package.json b/vscode/package.json index 2d6a9ed..140599c 100644 --- a/vscode/package.json +++ b/vscode/package.json @@ -605,6 +605,10 @@ "command": "jdk.delete.cache", "title": "%jdk.delete.cache%" }, + { + "command": "jdk.open.userDir", + "title": "%jdk.open.userDir%" + }, { "command": "jdk.notebook.new", "title": "%jdk.notebook.new%", diff --git a/vscode/package.nls.ja.json b/vscode/package.nls.ja.json index ee16272..6e5008c 100755 --- a/vscode/package.nls.ja.json +++ b/vscode/package.nls.ja.json @@ -28,6 +28,7 @@ "jdk.download.jdk": "JDKのダウンロード、インストールおよび使用", "jdk.open.test": "テスト/テスト済のクラスへ移動...", "jdk.delete.cache": "このワークスペースのOracle Java拡張キャッシュの削除", + "jdk.open.userDir": "Open Oracle Java extension cache directory for this workspace", "jdk.configuration.specifyJdk.description": "Oracle Visual Studio Code拡張機能のJDKを指定します", "jdk.configuration.specifyProjectJdk.description": "ユーザーのプロジェクトが実行されるJDKを指定します。値はデフォルトでjdk.jdkhomeに設定されます", "jdk.configuration.verbose.description": "Oracle Visual Studio Code拡張機能からの詳細メッセージを有効化します", diff --git a/vscode/package.nls.json b/vscode/package.nls.json index f9f4239..89934f7 100644 --- a/vscode/package.nls.json +++ b/vscode/package.nls.json @@ -28,6 +28,7 @@ "jdk.download.jdk": "Download, install and use JDK", "jdk.open.test": "Go To Test/Tested class...", "jdk.delete.cache": "Delete Oracle Java extension cache for this workspace", + "jdk.open.userDir": "Open Oracle Java extension cache directory for this workspace", "jdk.configuration.specifyJdk.description": "Specifies JDK for the Oracle Visual Studio Code Extension", "jdk.configuration.specifyProjectJdk.description": "Specifies the JDK on which user's project will be run. Defaults to the value of jdk.jdkhome", "jdk.configuration.verbose.description": "Enables verbose messages from the Oracle Visual Studio Code Extension", diff --git a/vscode/package.nls.zh-cn.json b/vscode/package.nls.zh-cn.json index 5745fa9..c7deb85 100755 --- a/vscode/package.nls.zh-cn.json +++ b/vscode/package.nls.zh-cn.json @@ -28,6 +28,7 @@ "jdk.download.jdk": "下载、安装和使用 JDK", "jdk.open.test": "转至测试/被测试的类...", "jdk.delete.cache": "删除此工作区的 Oracle Java 扩展高速缓存", + "jdk.open.userDir": "Open Oracle Java extension cache directory for this workspace", "jdk.configuration.specifyJdk.description": "指定适用于 Oracle Visual Studio Code 扩展的 JDK", "jdk.configuration.specifyProjectJdk.description": "指定将在其上运行用户项目的 JDK。默认值为 jdk.jdkhome", "jdk.configuration.verbose.description": "启用来自 Oracle Visual Studio Code 扩展的详细消息", diff --git a/vscode/src/commands/cache.ts b/vscode/src/commands/cache.ts index afb5ad7..54aded9 100644 --- a/vscode/src/commands/cache.ts +++ b/vscode/src/commands/cache.ts @@ -1,5 +1,5 @@ /* - Copyright (c) 2023-2024, Oracle and/or its affiliates. + Copyright (c) 2023-2025, Oracle and/or its affiliates. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -13,23 +13,29 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { commands, window } from "vscode"; +import { commands, window, env } from "vscode"; import { builtInCommands, extCommands } from "./commands"; import { ICommand } from "./types"; import { l10n } from "../localiser"; import * as fs from 'fs'; import * as path from 'path'; import { globalState } from "../globalState"; +import { getConfigurationValue } from "../configurations/handlers"; +import { configKeys } from "../configurations/configuration"; +import { LOGGER } from "../logger"; +import { FileUtils, isError } from "../utils"; +const getLanguageServerUserDir = () => { + const userdirScope = process.env['nbcode_userdir'] || getConfigurationValue(configKeys.userdir, "local"); + const workspaceStoragePath = globalState.getExtensionContextInfo().getWorkspaceStorage()?.fsPath; + const userdirParentDir = userdirScope === "local" && workspaceStoragePath + ? workspaceStoragePath + : globalState.getExtensionContextInfo().getGlobalStorage().fsPath; + const userDir = path.join(userdirParentDir, "userdir"); + return userDir; +} const deleteCache = async () => { - // TODO: Change workspace path to userdir path - const storagePath = globalState.getExtensionContextInfo().getWorkspaceStorage()?.fsPath; - if (!storagePath) { - window.showErrorMessage(l10n.value("jdk.extension.cache.error_msg.cannotFindWrkSpacePath")); - return; - } - - const userDir = path.join(storagePath, "userdir"); + const userDir = getLanguageServerUserDir(); if (userDir && fs.existsSync(userDir)) { const yes = l10n.value("jdk.extension.cache.label.confirmation.yes") const cancel = l10n.value("jdk.extension.cache.label.confirmation.cancel") @@ -44,7 +50,16 @@ const deleteCache = async () => { await fs.promises.rm(userDir, { recursive: true }); await window.showInformationMessage(l10n.value("jdk.extension.message.cacheDeleted"), reloadWindowActionLabel); } catch (err) { - await window.showErrorMessage(l10n.value("jdk.extension.error_msg.cacheDeletionError"), reloadWindowActionLabel); + LOGGER.error(`Error while deleting the cache : ${isError(err) ? err.message : err}`); + const openLSUserDirLabel = l10n.value("jdk.extension.cache.label.openLSUserDir"); + const selectedAction = await window.showErrorMessage(l10n.value("jdk.extension.error_msg.cacheDeletionError"), openLSUserDirLabel); + if (selectedAction === openLSUserDirLabel) { + const opened = await openLanguageServerUserDir(); + if (opened) + await window.showInformationMessage(l10n.value("jdk.extension.cache.message.reloadWindow.afterUserDirDeletion"), reloadWindowActionLabel); + else + await window.showErrorMessage(l10n.value("jdk.extension.error_msg.cacheDeletion.notOpenUserDir", { userDir }), reloadWindowActionLabel); + } } finally { commands.executeCommand(builtInCommands.reloadWindow); } @@ -53,8 +68,22 @@ const deleteCache = async () => { window.showErrorMessage(l10n.value("jdk.extension.cache.message.noUserDir")); } } +const openLanguageServerUserDir = async () => { + const userDir = getLanguageServerUserDir(); + if (userDir && fs.existsSync(userDir)) { + return env.openExternal(FileUtils.toUri(userDir)); + } else { + window.showErrorMessage(l10n.value("jdk.extension.cache.message.noUserDir")); + return false; + } +} -export const registerCacheCommands: ICommand[] = [{ - command: extCommands.deleteCache, - handler: deleteCache -}]; \ No newline at end of file +export const registerCacheCommands: ICommand[] = [ + { + command: extCommands.deleteCache, + handler: deleteCache + }, { + command: extCommands.openLanguageServerUserDir, + handler: openLanguageServerUserDir + }, +]; \ No newline at end of file diff --git a/vscode/src/commands/commands.ts b/vscode/src/commands/commands.ts index df05a36..141ed41 100644 --- a/vscode/src/commands/commands.ts +++ b/vscode/src/commands/commands.ts @@ -22,6 +22,7 @@ export const extCommands = { newProject: appendPrefixToCommand('workspace.newproject'), openTest: appendPrefixToCommand('open.test'), deleteCache: appendPrefixToCommand('delete.cache'), + openLanguageServerUserDir: appendPrefixToCommand('open.userDir'), downloadJdk: appendPrefixToCommand('download.jdk'), compileWorkspace: appendPrefixToCommand('workspace.compile'), cleanWorkspace: appendPrefixToCommand('workspace.clean'),