Skip to content

Commit 58cf413

Browse files
committed
make
1 parent d61a117 commit 58cf413

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

src/commands/showPanel.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { setWebviewContent } from "../utils/webview";
1212
import config from "../utils/config";
1313
import { Editor } from "../utils/editor";
1414
import { FRONTEND_ELEMENT_ID } from "../constants";
15+
import { client } from "../extension";
1516

1617
let panel: vscode.WebviewPanel | null = null;
1718
// This needs to be a reference to active
@@ -21,6 +22,8 @@ export let activeEditor: Editor | null = null;
2122
const messageQueue: MessageType[] = [];
2223
let handling = false;
2324

25+
// TODO: Remove panel and handling message logic out of the commands/ directory
26+
2427
async function handleMessage(
2528
context: vscode.ExtensionContext,
2629
message: MessageType,
@@ -60,6 +63,15 @@ async function handleMessage(
6063
message.assessmentName,
6164
message.questionId,
6265
);
66+
activeEditor.uri;
67+
const info = context.globalState.get("info") ?? {};
68+
if (activeEditor.uri) {
69+
// @ts-ignore
70+
info[activeEditor.uri] = { chapter: message.chapter };
71+
context.globalState.update("info", info);
72+
client.sendNotification("source/publishInfo", info);
73+
}
74+
6375
panel?.reveal(vscode.ViewColumn.Two);
6476
console.log(
6577
`EXTENSION: NewEditor: activeEditor set to ${activeEditor.assessmentName}_${activeEditor.questionId}`,

src/extension.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import { setupTreeView } from "./view/test";
66
import { setupStatusBar } from "./statusbar/status";
77
import { registerAllCommands } from "./commands";
88
import { activateLspClient, deactivateLspClient } from "./lsp/client";
9+
import { LanguageClient } from "vscode-languageclient/node";
10+
11+
// TODO: Don't expose this object directly, create an interface via a wrapper class
12+
export let client: LanguageClient;
913

1014
// This method is called when your extension is activated
1115
// Your extension is activated the very first time the command is executed
@@ -16,7 +20,14 @@ export function activate(context: vscode.ExtensionContext) {
1620

1721
context.subscriptions.push(setupStatusBar(context));
1822

19-
activateLspClient(context);
23+
client = activateLspClient(context);
24+
25+
// const info = {
26+
// "file:///home/heyzec/.sourceacademy/playground_1.js": { chapter: 4 },
27+
// };
28+
const info = context.globalState.get("info") ?? {};
29+
30+
client.sendNotification("source/publishInfo", info);
2031

2132
// TODO: Split this handler into subhandlers, and them its own folder in src/uriHandlers
2233
vscode.window.registerUriHandler({

src/utils/editor.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export class Editor {
1212
questionId: number;
1313
onChangeCallback?: (editor: Editor) => void;
1414
code: string | null = null;
15+
uri: string | null = null;
1516

1617
// For debugging purposes
1718
replaceTime: number = 0;
@@ -36,6 +37,7 @@ export class Editor {
3637
return this.editor?.document.getText();
3738
}
3839

40+
// TODO: This method is too loaded, it's not obvious it also shows the editor
3941
static async create(
4042
workspaceLocation: VscWorkspaceLocation,
4143
assessmentName: string,
@@ -57,26 +59,26 @@ export class Editor {
5759
workspaceFolder,
5860
`${assessmentName}_${questionId}.js`,
5961
);
62+
63+
const uri = vscode.Uri.file(filePath);
64+
self.uri = uri.toString();
65+
6066
await vscode.workspace.fs.readFile(vscode.Uri.file(filePath)).then(
6167
() => null,
6268
async () => {
6369
self.log(`Opening file failed, creating at ${filePath}`);
64-
await vscode.workspace.fs.writeFile(
65-
vscode.Uri.file(filePath),
66-
new TextEncoder().encode(""),
67-
);
70+
await vscode.workspace.fs.writeFile(uri, new TextEncoder().encode(""));
6871
},
6972
);
7073

71-
const editor = await vscode.window.showTextDocument(
72-
vscode.Uri.file(filePath),
73-
{
74-
preview: true,
75-
viewColumn: vscode.ViewColumn.One,
76-
},
77-
);
74+
// TODO: editor conflicts with the class Editor
75+
const editor = await vscode.window.showTextDocument(uri, {
76+
preview: true,
77+
viewColumn: vscode.ViewColumn.One,
78+
});
7879

7980
self.editor = editor;
81+
editor.document.uri.toString();
8082
// TODO: Restructure Editor-related code so that only active editor has listener
8183
vscode.workspace.onDidChangeTextDocument(() => {
8284
if (!self.onChangeCallback) {

0 commit comments

Comments
 (0)