Skip to content

Commit c8fbad1

Browse files
authored
Merge branch 'main' into mcq-ui
2 parents 24f4865 + e1c746e commit c8fbad1

File tree

5 files changed

+38
-8
lines changed

5 files changed

+38
-8
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
"type": "string",
3838
"default": "https://frontend.cloud.heyzec.dedyn.io",
3939
"description": "URL to the Source Academy frontend"
40+
},
41+
"source-academy.workspaceFolder": {
42+
"type": "string",
43+
"default": ".sourceacademy",
44+
"description": "Location to store code locally. If not absolute, it will be relative to the home directory."
4045
}
4146
}
4247
},

src/extension.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { setupStatusBar } from "./statusbar/status";
66
import { registerAllCommands } from "./commands";
77
import { activateLspClient, deactivateLspClient } from "./lsp/client";
88
import { LanguageClient } from "vscode-languageclient/node";
9+
import { canonicaliseLocation } from "./utils/misc";
10+
import config from "./utils/config";
911

1012
// TODO: Don't expose this object directly, create an interface via a wrapper class
1113
export let client: LanguageClient;
@@ -34,6 +36,21 @@ export function activate(context: vscode.ExtensionContext) {
3436
"assets",
3537
"icon.svg",
3638
);
39+
40+
// TODO: Prompt the user to make this folder the default, and then set back to the config store.
41+
42+
// Update user's workspace settings to associate .js to Source
43+
const workspaceFolder = canonicaliseLocation(config.workspaceFolder);
44+
if (
45+
vscode.workspace.workspaceFolders
46+
?.map((wf) => wf.uri.fsPath)
47+
.includes(workspaceFolder)
48+
) {
49+
const workspaceConfig = vscode.workspace.getConfiguration();
50+
workspaceConfig.update("files.associations", {
51+
"*.js": "source",
52+
});
53+
}
3754
}
3855

3956
// This method is called when your extension is deactivated

src/utils/config/schema.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ export default {
55
type: "string",
66
default: "https://frontend.cloud.heyzec.dedyn.io",
77
},
8-
workspaceFolder: { type: "string", default: "" },
8+
workspaceFolder: {
9+
type: "string",
10+
default: ".sourceacademy",
11+
},
912
} satisfies Record<string, ConfigSchemaUnion>;

src/utils/editor.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as os from "os";
44
import config from "../utils/config";
55
import { VscWorkspaceLocation } from "./messages";
66
import path from "path";
7+
import { canonicaliseLocation } from "./misc";
78

89
export class Editor {
910
editor?: vscode.TextEditor;
@@ -51,13 +52,7 @@ export class Editor {
5152
self.assessmentName = assessmentName;
5253
self.questionId = questionId;
5354

54-
let workspaceFolder = config.workspaceFolder;
55-
if (!workspaceFolder) {
56-
workspaceFolder = path.join(os.homedir(), ".sourceacademy");
57-
// TODO: Prompt the user to make this folder the default, and then set back to the config store.
58-
} else if (!path.isAbsolute(workspaceFolder)) {
59-
workspaceFolder = path.join(os.homedir(), workspaceFolder);
60-
}
55+
const workspaceFolder = canonicaliseLocation(config.workspaceFolder);
6156

6257
const filePath = path.join(
6358
workspaceFolder,
@@ -92,6 +87,7 @@ export class Editor {
9287
preview: false,
9388
viewColumn: vscode.ViewColumn.One,
9489
});
90+
vscode.languages.setTextDocumentLanguage(editor.document, "source");
9591
editor.selection = new vscode.Selection(
9692
editor.document.positionAt(0),
9793
editor.document.positionAt(1),

src/utils/misc.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import path from "path";
2+
import * as os from "os";
3+
4+
export function canonicaliseLocation(location: string) {
5+
if (path.isAbsolute(location)) {
6+
return location;
7+
}
8+
return path.join(os.homedir(), location);
9+
}

0 commit comments

Comments
 (0)