diff --git a/src/api/client.ts b/src/api/client.ts index d1b3185..1eb638b 100644 --- a/src/api/client.ts +++ b/src/api/client.ts @@ -128,21 +128,22 @@ export default async function execute( ? INVALID_TOKEN_MSG(environment) : MISSING_TOKEN_MSG(environment); - // Get the user's action. - const selectedButton = await window.showErrorMessage( + // Get the user's action. We cannot use async/await here since this + // will block processing. + window.showErrorMessage( `${msg} To correctly set up your token in Visual Studio Code, click the Instructions button below.`, VIEW_INSTRUCTIONS_ACTION, OPEN_SETTINGS_ACTION, - ); - - // Handle the action. - if (selectedButton === VIEW_INSTRUCTIONS_ACTION) { - // Open the instructions in the user's web browser. - env.openExternal(TOKEN_INSTUCTIONS_URL); - } else if (selectedButton === OPEN_SETTINGS_ACTION) { - // Open the token settings. - commands.executeCommand("dodona.settings.token"); - } + ).then(action => { + // Handle the action. + if (action === VIEW_INSTRUCTIONS_ACTION) { + // Open the instructions in the user's web browser. + env.openExternal(TOKEN_INSTUCTIONS_URL); + } else if (action === OPEN_SETTINGS_ACTION) { + // Open the token settings. + commands.executeCommand("dodona.settings.token"); + } + }); } // Empty response. diff --git a/src/extension.ts b/src/extension.ts index f193d58..4ed82e1 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,7 +1,7 @@ import { commands, ExtensionContext, window, workspace } from "vscode"; import RootDataProvider from "./treeView/dataProvider"; import { createNewExercise } from "./commands/createNewExercise"; -import { getApiEnvironment } from "./configuration"; +import { CONFIG_KEY, getApiEnvironment } from "./configuration"; import { openCourse } from "./commands/openCourse"; import { openSeries } from "./commands/openSeries"; import { submitSolution } from "./commands/submitSolution"; @@ -99,11 +99,12 @@ export function activate(context: ExtensionContext) { // Register and create the activity tree view for the plugin. window.registerTreeDataProvider("dodona-activities", treeDataProvider); - window.createTreeView("dodona-activities", { treeDataProvider }); // Refresh the treeview when the API domain is changed. - workspace.onDidChangeConfiguration(() => { - treeDataProvider.refresh(); + workspace.onDidChangeConfiguration(e => { + if (e.affectsConfiguration(CONFIG_KEY)) { + treeDataProvider.refresh(); + } }); notificationsInterval(); diff --git a/src/treeView/dataProvider.ts b/src/treeView/dataProvider.ts index 450272f..2d0ea63 100644 --- a/src/treeView/dataProvider.ts +++ b/src/treeView/dataProvider.ts @@ -9,9 +9,9 @@ import { AbstractTreeItem } from "./items/abstractTreeItem"; import execute from "../api/client"; import { YearTreeItem } from "./items/yearTreeItem"; import { + getCourseFilter, getSortOption, getYearFilter, - getCourseFilter, } from "../configuration"; import { Course } from "../api/resources/course"; @@ -23,9 +23,7 @@ import { Course } from "../api/resources/course"; export default class RootDataProvider implements TreeDataProvider { - private _onDidChangeTreeData: EventEmitter< - AbstractTreeItem | undefined - > = new EventEmitter(); + private _onDidChangeTreeData: EventEmitter = new EventEmitter(); readonly onDidChangeTreeData: Event = this ._onDidChangeTreeData.event; @@ -38,19 +36,19 @@ export default class RootDataProvider } // Get the courses the user is subscribed to. - return ( - execute(dodona => dodona.courses.subscribed) - // Sort courses & apply filters - .then(cs => - RootDataProvider.sortCourses(this.filterCourses(cs || [])), - ) - // Convert them to tree items. - .then(cs => - this.getYears(cs).map( - y => new YearTreeItem(y, this.getCoursesForYear(y, cs)), - ), - ) - ); + return execute(dodona => dodona.courses.subscribed) + // Sort courses & apply filters + .then(cs => + RootDataProvider.sortCourses(this.filterCourses(cs || [])), + ) + // Convert them to tree items. + .then(cs => + this.getYears(cs).map( + y => new YearTreeItem(y, this.getCoursesForYear(y, cs)), + ), + ) + // Error handling. + .catch(() => []); } /** @@ -90,12 +88,12 @@ export default class RootDataProvider a.year < b.year ? 1 : a.year > b.year - ? -1 - : a.name < b.name - ? priority - : a.name > b.name - ? -priority - : 0, + ? -1 + : a.name < b.name + ? priority + : a.name > b.name + ? -priority + : 0, ); }