diff --git a/src/utils/editor.ts b/src/utils/editor.ts index 73ffbf4..d984d3e 100644 --- a/src/utils/editor.ts +++ b/src/utils/editor.ts @@ -50,6 +50,16 @@ export class Editor { return this.editor.document.getText(); } + static getFilePath(assessmentName: string, questionId: number): string { + const workspaceFolder = canonicaliseLocation(config.workspaceFolder); + const filePath = path.join( + workspaceFolder, + `${assessmentName}_${questionId}.js`, + ); + + return filePath; + } + // TODO: This method is too loaded, it's not obvious it also shows the editor static async create( workspaceLocation: VscWorkspaceLocation, diff --git a/src/utils/messageHandler.tsx b/src/utils/messageHandler.tsx index 57b8834..91bf63e 100644 --- a/src/utils/messageHandler.tsx +++ b/src/utils/messageHandler.tsx @@ -167,6 +167,24 @@ export class MessageHandler { context.globalState.update("courseId", courseId); treeDataProvider.refresh(); break; + case MessageTypeNames.ChangeChapter: { + const info = context.globalState.get("info") ?? {}; + const uri = vscode.Uri.file( + Editor.getFilePath(message.assessmentName, message.questionId), + ).toString(); + + _.set(info, `["${uri}"].chapter`, message.chapter ?? 1); + context.globalState.update("info", info); + client.sendRequest("source/publishInfo", info); + + if (message.variant !== "default") { + vscode.window + .showInformationMessage(`The Language Server does not support any variants, the + Language Server will use Source ยง${message.chapter}, but it is not guaranteed to be accurate.`); + } + + break; + } case MessageTypeNames.ResetEditor: if (this.activeEditor) { this.activeEditor.replace(message.initialCode); diff --git a/src/utils/messages.ts b/src/utils/messages.ts index eb6f912..9dd34d1 100644 --- a/src/utils/messages.ts +++ b/src/utils/messages.ts @@ -48,6 +48,17 @@ const Messages = createMessages({ EvalEditor: (workspaceLocation: VscWorkspaceLocation) => ({ workspaceLocation: workspaceLocation, }), + ChangeChapter: ( + assessmentName: string, + questionId: number, + chapter: number, + variant: string, + ) => ({ + assessmentName, + questionId, + chapter, + variant, + }), ResetEditor: ( workspaceLocation: VscWorkspaceLocation, initialCode: string,