Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -144,54 +144,69 @@ public void notebookConfigsChangeListener(JsonObject settings) {
return;
}

JsonElement classPathConfig = settings.get(CONFIG_CLASSPATH);
JsonElement classPathConfig = getConfig(settings, CONFIG_CLASSPATH);
if (classPathConfig != null && classPathConfig.isJsonArray()) {
classPath = String.join(File.pathSeparator, classPathConfig.getAsJsonArray().asList().stream().map((elem) -> elem.getAsString()).toList());
} else {
classPath = null;
}

JsonElement modulePathConfig = settings.get(CONFIG_MODULEPATH);
JsonElement modulePathConfig = getConfig(settings, CONFIG_MODULEPATH);
if (modulePathConfig != null && modulePathConfig.isJsonArray()) {
modulePath = String.join(File.pathSeparator, modulePathConfig.getAsJsonArray().asList().stream().map((elem) -> elem.getAsString()).toList());
} else {
modulePath = null;
}

JsonElement addModulesConfig = settings.get(CONFIG_ADDMODULES);
JsonElement addModulesConfig = getConfig(settings, CONFIG_ADDMODULES);
if (addModulesConfig != null && addModulesConfig.isJsonArray()) {
addModules = String.join(",", addModulesConfig.getAsJsonArray().asList().stream().map((elem) -> elem.getAsString()).toList());
} else {
addModules = null;
}

JsonElement enablePreviewConfig = settings.get(CONFIG_ENABLE_PREVIEW);
JsonElement enablePreviewConfig = getConfig(settings, CONFIG_ENABLE_PREVIEW);
if (enablePreviewConfig != null && enablePreviewConfig.isJsonPrimitive()) {
JsonPrimitive primitive = enablePreviewConfig.getAsJsonPrimitive();
enablePreview = primitive.isBoolean() && primitive.getAsBoolean();
} else {
enablePreview = false;
}

JsonElement implicitImportsConfig = settings.get(CONFIG_IMPLICIT_IMPORTS);
JsonElement implicitImportsConfig = getConfig(settings, CONFIG_IMPLICIT_IMPORTS);
if (implicitImportsConfig != null && implicitImportsConfig.isJsonArray()) {
implicitImports = implicitImportsConfig.getAsJsonArray().asList().stream().map((elem) -> elem.getAsString()).toList();
} else {
implicitImports = null;
}

JsonElement notebookProjectMappingConfig = settings.get(CONFIG_PROJECTS_MAPPING);
JsonElement notebookProjectMappingConfig = getConfig(settings, CONFIG_PROJECTS_MAPPING);
if (notebookProjectMappingConfig != null && notebookProjectMappingConfig.isJsonObject()) {
notebookProjectMapping = notebookProjectMappingConfig.getAsJsonObject();
} else {
notebookProjectMapping = new JsonObject();
}

JsonElement notebookVmOptionsConfig = settings.get(CONFIG_VM_OPTIONS);
JsonElement notebookVmOptionsConfig = getConfig(settings, CONFIG_VM_OPTIONS);
if (notebookVmOptionsConfig != null && notebookVmOptionsConfig.isJsonArray()) {
notebookVmOptions = notebookVmOptionsConfig.getAsJsonArray().asList().stream().map(el -> el.getAsString()).toList();
} else {
notebookVmOptions = Collections.emptyList();
}
}

private static JsonElement getConfig(JsonObject settings, String key) {
if (!key.contains(".")) {
return settings.get(key);
}

JsonElement current = settings;
for (String part : key.split("\\.")) {
if (current == null || !current.isJsonObject()) {
return null;
}
current = current.getAsJsonObject().get(part);
}
return current;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private static CompletableFuture<List<Project>> selectFromMultipleProjects(Proje
items.add(item);
}
String placeholder = defaultPrjSelected != null ? Bundle.LBL_CurrentProjectContext(defaultPrjSelected.getName())
: items.isEmpty() ? Bundle.MSG_NoProjectFound() : Bundle.MSG_NoProjectFound();
: items.isEmpty() ? Bundle.MSG_NoProjectFound() : Bundle.MSG_NoProjectContextFound();

ShowQuickPickParams params = new ShowQuickPickParams(title, placeholder, false, items);
return client.showQuickPick(params).thenApply(selected -> {
Expand Down
3 changes: 2 additions & 1 deletion vscode/l10n/bundle.l10n.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,6 @@
"jdk.notebook.validation.failed.error_msg": "Notebook JSON validation failed",
"jdk.notebook.validation.notebook_version.failed.error_msg": "Notebook version is not supported. Please upgrade to version {majorVersion}.{minorVersion} or later.",
"jdk.notebook.mime_type.not.found.cell.output": "Mime Type: {mimeType}, Content Length: {contentLength}",
"jdk.notebook.cell.language.not.found": "Doesn't support {languageId} execution"
"jdk.notebook.cell.language.not.found": "Doesn't support {languageId} execution",
"jdk.notebook.project.context.changed.restart.kernel.msg.consent": "Project context changed. Do you want to restart the notebook kernel?"
}
3 changes: 2 additions & 1 deletion vscode/l10n/bundle.l10n.ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,6 @@
"jdk.notebook.validation.failed.error_msg": "ノートブックJSON検証に失敗しました",
"jdk.notebook.validation.notebook_version.failed.error_msg": "Notebook version is not supported. Please upgrade to version {majorVersion}.{minorVersion} or later.",
"jdk.notebook.mime_type.not.found.cell.output": "MIMEタイプ: {mimeType}、コンテンツの長さ: {contentLength}",
"jdk.notebook.cell.language.not.found": "{languageId}の実行はサポートされていません"
"jdk.notebook.cell.language.not.found": "{languageId}の実行はサポートされていません",
"jdk.notebook.project.context.changed.restart.kernel.msg.consent": "プロジェクトのコンテキストが変更されました。ノートブックのカーネルを再起動しますか?"
}
3 changes: 2 additions & 1 deletion vscode/l10n/bundle.l10n.zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,6 @@
"jdk.notebook.validation.failed.error_msg": "记事本 JSON 验证失败",
"jdk.notebook.validation.notebook_version.failed.error_msg": "Notebook version is not supported. Please upgrade to version {majorVersion}.{minorVersion} or later.",
"jdk.notebook.mime_type.not.found.cell.output": "Mime 类型:{mimeType},内容长度:{contentLength}",
"jdk.notebook.cell.language.not.found": "不支持 {languageId} 执行"
"jdk.notebook.cell.language.not.found": "不支持 {languageId} 执行",
"jdk.notebook.project.context.changed.restart.kernel.msg.consent": "项目上下文已更改。您想要重启 Notebook 内核吗"
}
23 changes: 17 additions & 6 deletions vscode/src/commands/notebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,21 @@ const notebookChangeProjectContextHandler = async (ctx: INotebookToolbar) => {
if (!res) {
return;
}
const oldValue = getConfigurationValue(configKeys.notebookProjectMapping, {});
updateConfigurationValue(configKeys.notebookProjectMapping,
{ ...oldValue, [uri.fsPath]: res },
ConfigurationTarget.Workspace);
const oldValue = getConfigurationValue<Record<string, string>>(configKeys.notebookProjectMapping, {});
const newValue = { ...oldValue, [uri.fsPath]: res };

if (oldValue[uri.fsPath] !== newValue[uri.fsPath]) {
updateConfigurationValue(configKeys.notebookProjectMapping, newValue, ConfigurationTarget.Workspace);

const yes = l10n.value("jdk.extension.cache.label.confirmation.yes")
const cancel = l10n.value("jdk.extension.cache.label.confirmation.cancel")
const confirmation = await window.showWarningMessage(l10n.value("jdk.notebook.project.context.changed.restart.kernel.msg.consent"),
yes, cancel);

if (confirmation === yes) {
await restartKernel(ctx, true);
}
}
} else {
throw l10n.value("jdk.extension.error_msg.doesntSupportNotebookCellExecution", { client: client?.name });
}
Expand All @@ -168,13 +179,13 @@ const notebookChangeProjectContextHandler = async (ctx: INotebookToolbar) => {
}
}

const restartKernel = async (ctx: INotebookToolbar) => {
const restartKernel = async (ctx: INotebookToolbar, skipConfirmation = false) => {
try {
const uri: Uri = ctx.notebookEditor.notebookUri;

const yes = l10n.value("jdk.extension.cache.label.confirmation.yes")
const cancel = l10n.value("jdk.extension.cache.label.confirmation.cancel")
const confirmation = await window.showWarningMessage(l10n.value("jdk.notebook.restart.kernel.msg.consent"),
const confirmation = skipConfirmation ? yes : await window.showWarningMessage(l10n.value("jdk.notebook.restart.kernel.msg.consent"),
yes, cancel);

if (confirmation === yes) {
Expand Down