diff --git a/src/utils/editor.ts b/src/utils/editor.ts index 62a05d0..655efac 100644 --- a/src/utils/editor.ts +++ b/src/utils/editor.ts @@ -42,6 +42,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, @@ -54,13 +64,7 @@ export class Editor { self.assessmentName = assessmentName; self.questionId = questionId; - const workspaceFolder = canonicaliseLocation(config.workspaceFolder); - - const filePath = path.join( - workspaceFolder, - `${assessmentName}_${questionId}.js`, - ); - + const filePath = this.getFilePath(assessmentName, questionId); const uri = vscode.Uri.file(filePath); self.uri = uri.toString(); diff --git a/src/utils/messageHandler.tsx b/src/utils/messageHandler.tsx index c17415d..77abdb2 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; + } } console.log(`${Date.now()} Finish handleMessage: ${message.type}`); } diff --git a/src/utils/messages.ts b/src/utils/messages.ts index b35c498..003dcb2 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, + }), NotifyAssessmentsOverview: ( assessmentOverviews: VscAssessmentOverview[], courseId: number,