Skip to content

Commit eb80d3a

Browse files
committed
prepend
1 parent ec1c1a3 commit eb80d3a

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

language-configuration.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
{ "open": "'", "close": "'" },
2424
{ "open": "\"", "close": "\"" }
2525
],
26+
"folding": {
27+
"markers": {
28+
"start": "// PREPEND -- DO NOT EDIT",
29+
"end": "// END PREPEND"
30+
}
31+
},
2632
"wordPattern": "[_$a-zA-Z][_$a-zA-Z0-9]*",
2733
"indentationRules": {
2834
"increaseIndentPattern": "^((?!\\/\\/).)*(\\{[^}\"'`]*|\\([^)\"'`]*|\\[[^\\]\"'`]*)$",

src/commands/showPanel.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ async function handleMessage(
4747
message.workspaceLocation,
4848
message.assessmentName,
4949
message.questionId,
50+
message.prepend,
5051
message.initialCode,
5152
);
5253
activeEditor.uri;
@@ -55,7 +56,8 @@ async function handleMessage(
5556
// TODO: Write our own wrapper to set nested keys easily, removing lodash
5657
// @ts-ignore
5758
_.set(info, `["${activeEditor.uri}"].chapter`, message.chapter);
58-
_.set(info, `["${activeEditor.uri}"].prepend`, message.prepend);
59+
const nPrependLines = message.prepend.split("\n").length;
60+
_.set(info, `["${activeEditor.uri}"].prepend`, nPrependLines);
5961
context.globalState.update("info", info);
6062
client.sendNotification("source/publishInfo", info);
6163
}

src/utils/editor.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export class Editor {
4242
workspaceLocation: VscWorkspaceLocation,
4343
assessmentName: string,
4444
questionId: number,
45+
prepend: string = "",
4546
initialCode: string = "",
4647
): Promise<Editor> {
4748
const self = new Editor(workspaceLocation, assessmentName, questionId);
@@ -64,13 +65,20 @@ export class Editor {
6465
const uri = vscode.Uri.file(filePath);
6566
self.uri = uri.toString();
6667

68+
const contents = [
69+
"// PREPEND -- DO NOT EDIT",
70+
prepend,
71+
"// END PREPEND",
72+
initialCode,
73+
].join("\n");
74+
6775
await vscode.workspace.fs.readFile(vscode.Uri.file(filePath)).then(
6876
() => null,
6977
async () => {
7078
self.log(`Opening file failed, creating at ${filePath}`);
7179
await vscode.workspace.fs.writeFile(
7280
uri,
73-
new TextEncoder().encode(initialCode),
81+
new TextEncoder().encode(contents),
7482
);
7583
},
7684
);
@@ -79,6 +87,11 @@ export class Editor {
7987
preview: true,
8088
viewColumn: vscode.ViewColumn.One,
8189
});
90+
editor.selection = new vscode.Selection(
91+
editor.document.positionAt(0),
92+
editor.document.positionAt(1),
93+
);
94+
vscode.commands.executeCommand("editor.fold");
8295

8396
self.editor = editor;
8497
vscode.workspace.onDidChangeTextDocument(() => {

0 commit comments

Comments
 (0)