Skip to content

Commit a03e2c8

Browse files
committed
Address comments.
1 parent 52d32a5 commit a03e2c8

5 files changed

Lines changed: 14 additions & 13 deletions

File tree

extensions/ql-vscode/src/common/commands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ export type AllExtensionCommands = BaseCommands &
367367
QueryEditorCommands &
368368
ResultsViewCommands &
369369
QueryHistoryCommands &
370+
LanguageSelectionCommands &
370371
LocalDatabasesCommands &
371372
DebuggerCommands &
372373
VariantAnalysisCommands &

extensions/ql-vscode/src/language-context-store.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,15 @@ export class LanguageContextStore extends DisposableObject {
4343
);
4444
}
4545

46+
// shouldInclude should return true if the given language should be included.
47+
// That means that either the given language is selected or the "All" option is selected.
4648
public shouldInclude(language: QueryLanguage | undefined): boolean {
4749
return this.languageFilter === "All" || this.languageFilter === language;
4850
}
4951

50-
public selectedLanguage(language: QueryLanguage | undefined): boolean {
52+
// isSelectedLanguage returns true if the given language is selected. If no language
53+
// is given then it returns true if the "All" option is selected.
54+
public isSelectedLanguage(language: QueryLanguage | undefined): boolean {
5155
return (
5256
(this.languageFilter === "All" && language === undefined) ||
5357
this.languageFilter === language

extensions/ql-vscode/src/language-selection-panel/language-selection-data-provider.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ export class LanguageSelectionTreeDataProvider
5151
public constructor(private readonly languageContext: LanguageContextStore) {
5252
super();
5353

54-
this.treeItems = this.createTree(languageContext);
54+
this.treeItems = this.createTree();
5555

5656
// If the language context changes, we need to update the tree.
5757
this.push(
5858
this.languageContext.onLanguageContextChanged(() => {
59-
this.treeItems = this.createTree(languageContext);
59+
this.treeItems = this.createTree();
6060
this.onDidChangeTreeDataEmitter.fire();
6161
}),
6262
);
@@ -80,13 +80,11 @@ export class LanguageSelectionTreeDataProvider
8080
}
8181
}
8282

83-
private createTree(
84-
languageContext: LanguageContextStore,
85-
): LanguageSelectionTreeViewItem[] {
83+
private createTree(): LanguageSelectionTreeViewItem[] {
8684
return ALL_LANGUAGE_SELECTION_OPTIONS.map((language) => {
8785
return new LanguageSelectionTreeViewItem(
8886
language,
89-
languageContext.selectedLanguage(language),
87+
this.languageContext.isSelectedLanguage(language),
9088
);
9189
});
9290
}

extensions/ql-vscode/src/language-selection-panel/language-selection-panel.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export class LanguageSelectionPanel extends DisposableObject {
1414
super();
1515

1616
const dataProvider = new LanguageSelectionTreeDataProvider(languageContext);
17+
this.push(dataProvider);
1718

1819
const treeView = window.createTreeView("codeQLLanguageSelection", {
1920
treeDataProvider: dataProvider,

extensions/ql-vscode/test/vscode-tests/no-workspace/language-selection-panel/language-selection-data-provider.test.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,13 @@ describe("LanguageSelectionTreeDataProvider", () => {
4040
return getLanguageDisplayName(language);
4141
}),
4242
];
43-
// Note that the internal order of C# and C / C++ is different from what is shown in the UI.
44-
[expectedLanguageNames[1], expectedLanguageNames[2]] = [
45-
expectedLanguageNames[2],
46-
expectedLanguageNames[1],
47-
];
4843
const actualLanguagesNames = dataProvider.getChildren().map((item) => {
4944
return item.label;
5045
});
5146

52-
expect(actualLanguagesNames).toEqual(expectedLanguageNames);
47+
// Note that the internal order of C# and C / C++ is different from what is shown in the UI.
48+
// So we sort to make sure we can compare the two lists.
49+
expect(actualLanguagesNames.sort()).toEqual(expectedLanguageNames.sort());
5350
});
5451

5552
it("default selection is All languages", async () => {

0 commit comments

Comments
 (0)