Address comments.

This commit is contained in:
Anders Starcke Henriksen
2023-10-13 10:02:14 +02:00
parent 52d32a5051
commit a03e2c85f1
5 changed files with 14 additions and 13 deletions

View File

@@ -367,6 +367,7 @@ export type AllExtensionCommands = BaseCommands &
QueryEditorCommands &
ResultsViewCommands &
QueryHistoryCommands &
LanguageSelectionCommands &
LocalDatabasesCommands &
DebuggerCommands &
VariantAnalysisCommands &

View File

@@ -43,11 +43,15 @@ export class LanguageContextStore extends DisposableObject {
);
}
// shouldInclude should return true if the given language should be included.
// That means that either the given language is selected or the "All" option is selected.
public shouldInclude(language: QueryLanguage | undefined): boolean {
return this.languageFilter === "All" || this.languageFilter === language;
}
public selectedLanguage(language: QueryLanguage | undefined): boolean {
// isSelectedLanguage returns true if the given language is selected. If no language
// is given then it returns true if the "All" option is selected.
public isSelectedLanguage(language: QueryLanguage | undefined): boolean {
return (
(this.languageFilter === "All" && language === undefined) ||
this.languageFilter === language

View File

@@ -51,12 +51,12 @@ export class LanguageSelectionTreeDataProvider
public constructor(private readonly languageContext: LanguageContextStore) {
super();
this.treeItems = this.createTree(languageContext);
this.treeItems = this.createTree();
// If the language context changes, we need to update the tree.
this.push(
this.languageContext.onLanguageContextChanged(() => {
this.treeItems = this.createTree(languageContext);
this.treeItems = this.createTree();
this.onDidChangeTreeDataEmitter.fire();
}),
);
@@ -80,13 +80,11 @@ export class LanguageSelectionTreeDataProvider
}
}
private createTree(
languageContext: LanguageContextStore,
): LanguageSelectionTreeViewItem[] {
private createTree(): LanguageSelectionTreeViewItem[] {
return ALL_LANGUAGE_SELECTION_OPTIONS.map((language) => {
return new LanguageSelectionTreeViewItem(
language,
languageContext.selectedLanguage(language),
this.languageContext.isSelectedLanguage(language),
);
});
}

View File

@@ -14,6 +14,7 @@ export class LanguageSelectionPanel extends DisposableObject {
super();
const dataProvider = new LanguageSelectionTreeDataProvider(languageContext);
this.push(dataProvider);
const treeView = window.createTreeView("codeQLLanguageSelection", {
treeDataProvider: dataProvider,

View File

@@ -40,16 +40,13 @@ describe("LanguageSelectionTreeDataProvider", () => {
return getLanguageDisplayName(language);
}),
];
// Note that the internal order of C# and C / C++ is different from what is shown in the UI.
[expectedLanguageNames[1], expectedLanguageNames[2]] = [
expectedLanguageNames[2],
expectedLanguageNames[1],
];
const actualLanguagesNames = dataProvider.getChildren().map((item) => {
return item.label;
});
expect(actualLanguagesNames).toEqual(expectedLanguageNames);
// Note that the internal order of C# and C / C++ is different from what is shown in the UI.
// So we sort to make sure we can compare the two lists.
expect(actualLanguagesNames.sort()).toEqual(expectedLanguageNames.sort());
});
it("default selection is All languages", async () => {