Skip to content

Commit 7a898c2

Browse files
committed
Install dependencies
1 parent daa3012 commit 7a898c2

File tree

2 files changed

+72
-36
lines changed

2 files changed

+72
-36
lines changed

src/extension.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import {
2-
commands,
3-
ExtensionContext,
4-
OutputChannel,
5-
window,
6-
} from "vscode";
1+
import { commands, ExtensionContext, OutputChannel, window } from "vscode";
72
import { installTslab } from "./installer";
8-
import { optIntoNativeNotebooks, registerWithJupyter } from "./jupyterExtension";
3+
import {
4+
configureEditor,
5+
optIntoNativeNotebooks,
6+
registerWithJupyter,
7+
} from "./jupyterExtension";
98
import { installKernelSpec } from "./kernel";
109
import { logError, setOutputWindow, showLog } from "./logger";
1110
import { noop } from "./utils";
@@ -15,11 +14,13 @@ export async function activate(context: ExtensionContext) {
1514
setOutputWindow(outputChannel);
1615
// Install kernel (silently) as soon as extension activates.
1716
Promise.all([
18-
installTslab(outputChannel),
19-
installKernelSpec(),
20-
registerWithJupyter(),
21-
optIntoNativeNotebooks(),
22-
installKernelSpec()]).catch(noop);
17+
installTslab(outputChannel),
18+
installKernelSpec(),
19+
registerWithJupyter(),
20+
optIntoNativeNotebooks(),
21+
configureEditor(),
22+
installKernelSpec(),
23+
]).catch(noop);
2324
registerCommands(context, outputChannel);
2425
}
2526

src/jupyterExtension.ts

Lines changed: 59 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,65 @@ import { logMessage } from "./logger";
33
import { IJupyterExtensionApi } from "./types";
44

55
export async function registerWithJupyter() {
6-
const jupyter = extensions.getExtension<IJupyterExtensionApi>(
7-
"ms-toolsai.jupyter"
8-
);
9-
if (!jupyter) {
10-
return;
11-
}
12-
if (!jupyter.isActive) {
13-
await jupyter.activate();
14-
}
15-
if (jupyter.exports.registerNewNotebookContent) {
16-
jupyter.exports.registerNewNotebookContent({
17-
defaultCellLanguage: "typescript",
18-
});
19-
}
6+
const jupyter = extensions.getExtension<IJupyterExtensionApi>(
7+
"ms-toolsai.jupyter"
8+
);
9+
if (!jupyter) {
10+
return;
2011
}
12+
if (!jupyter.isActive) {
13+
await jupyter.activate();
14+
}
15+
if (jupyter.exports.registerNewNotebookContent) {
16+
jupyter.exports.registerNewNotebookContent({
17+
defaultCellLanguage: "typescript",
18+
});
19+
}
20+
}
21+
22+
export async function optIntoNativeNotebooks() {
23+
const settings = workspace.getConfiguration("jupyter", undefined);
24+
const optInto = settings.get<string[]>("experiments.optInto");
25+
if (
26+
!Array.isArray(optInto) ||
27+
optInto.includes("All") ||
28+
optInto.includes("__NativeNotebookEditor__")
29+
) {
30+
logMessage("Native Notebook already setup");
31+
return;
32+
}
33+
optInto.push("__NativeNotebookEditor__");
34+
logMessage("Setting up Native Notebooks");
35+
await settings.update(
36+
"experiments.optInto",
37+
optInto,
38+
ConfigurationTarget.Global
39+
);
40+
}
2141

22-
export async function optIntoNativeNotebooks(){
23-
const settings = workspace.getConfiguration('jupyter', undefined);
24-
const optInto = settings.get<string[]>('experiments.optInto');
25-
if (!Array.isArray(optInto) || optInto.includes('All') || optInto.includes('__NativeNotebookEditor__')){
26-
logMessage('Native Notebook already setup');
27-
return;
28-
}
29-
optInto.push('__NativeNotebookEditor__');
30-
logMessage('Setting up Native Notebooks');
31-
await settings.update('experiments.optInto', optInto, ConfigurationTarget.Global);
42+
type EditorAssociation = {
43+
viewType: string;
44+
filenamePattern: string;
45+
};
46+
47+
export async function configureEditor() {
48+
const settings = workspace.getConfiguration("workbench", undefined);
49+
const associations = settings.get<EditorAssociation[]>("editorAssociations");
50+
if (
51+
!Array.isArray(associations) ||
52+
associations.find((item) => item.viewType === "jupyter-notebook")
53+
) {
54+
logMessage("Native Notebook Editor already setup");
55+
return;
56+
}
57+
associations.push({
58+
viewType: "jupyter-notebook",
59+
filenamePattern: "*.ipynb",
60+
});
61+
logMessage("Setting up Native Notebook Editor");
62+
await settings.update(
63+
"editorAssociations",
64+
associations,
65+
ConfigurationTarget.Global
66+
);
3267
}

0 commit comments

Comments
 (0)