Skip to content

Feat: Treeview additions #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
},
{
"command": "source-academy.show-panel",
"title": "Source Academy: Show the Source Academy panel"
"title": "Source Academy: Show the Source Academy panel",
"icon": "$(rocket)"
},
{
"command": "source-academy.eval-editor",
Expand Down Expand Up @@ -74,11 +75,20 @@
"key": "shift+enter"
}
],
"menus": {
"view/title": [
{
"command": "source-academy.show-panel",
"when": "view == assessments",
"group": "navigation"
}
]
},
"views": {
"source-academy": [
{
"id": "assessments",
"name": "Assessments",
"name": "",
"icon": "assets/icon.svg",
"contextualTitle": "Source Academy"
}
Expand Down
28 changes: 25 additions & 3 deletions src/treeview/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export class AssessmentsSidebarProvider
}

getChildren(element?: BaseTreeItem): Thenable<BaseTreeItem[]> {
// Synthetic root item that launches the Source Academy panel.
const launchItem = new PlaygroundItem();

// @ts-ignore
const assessmentOverviews: VscAssessmentOverview[] =
this.context.globalState.get("assessmentOverviews");
Expand All @@ -44,14 +47,18 @@ export class AssessmentsSidebarProvider
const assessmentTypes = [
...new Set(assessmentOverviews.map((ao) => ao.type)),
];
return Promise.resolve(
assessmentTypes.map((at) => new AssessmentFolder(at)),
);
const folders = assessmentTypes.map((at) => new AssessmentFolder(at));

return Promise.resolve([launchItem, ...folders]);
}

if (element && element.type === "AssessmentFolder") {
const elem = element as AssessmentFolder;

if (!assessmentOverviews) {
return Promise.resolve([]);
}

return Promise.resolve(
assessmentOverviews
.filter((ao) => ao.type == elem.assessmentType)
Expand Down Expand Up @@ -84,6 +91,21 @@ class BaseTreeItem extends vscode.TreeItem {
};
}

/**
* Synthetic tree item that always appears at the top-level of the view.
*/
class PlaygroundItem extends BaseTreeItem {
constructor() {
super("Playground", vscode.TreeItemCollapsibleState.None);
this.type = "LaunchItem";
this.command = {
title: "Playground",
command: "source-academy.navigate",
arguments: ["/playground"],
};
}
}

class AssessmentFolder extends BaseTreeItem {
constructor(public readonly assessmentType: string) {
super(assessmentType, vscode.TreeItemCollapsibleState.Collapsed);
Expand Down