Change to use QueryLanguage | undefined.

This commit is contained in:
Anders Starcke Henriksen
2023-09-28 16:43:33 +02:00
parent 6accba66fe
commit dc632d5c3d
3 changed files with 11 additions and 7 deletions

View File

@@ -62,3 +62,9 @@ export const dbSchemeToLanguage: Record<string, QueryLanguage> = {
export function isQueryLanguage(language: string): language is QueryLanguage {
return Object.values(QueryLanguage).includes(language as QueryLanguage);
}
export function tryGetQueryLanguage(
language: string,
): QueryLanguage | undefined {
return isQueryLanguage(language) ? language : undefined;
}

View File

@@ -51,7 +51,7 @@ import {
createMultiSelectionCommand,
createSingleSelectionCommand,
} from "../common/vscode/selection-commands";
import { QueryLanguage } from "../common/query-language";
import { QueryLanguage, tryGetQueryLanguage } from "../common/query-language";
import { LanguageContextStore } from "../language-context-store";
enum SortOrder {
@@ -143,7 +143,9 @@ class DatabaseTreeDataProvider
if (element === undefined) {
// Filter items by language
const displayItems = this.databaseManager.databaseItems.filter((item) => {
return this.languageContext.shouldInclude(item.language);
return this.languageContext.shouldInclude(
tryGetQueryLanguage(item.language),
);
});
// Sort items

View File

@@ -43,11 +43,7 @@ export class LanguageContextStore extends DisposableObject {
);
}
// This method takes a string to allow it to be used in cases
// where the language is not always a known one.
// The semantics of such an unknown langauge is that it is
// only included if the current language context is "All".
public shouldInclude(language: string): boolean {
public shouldInclude(language: QueryLanguage | undefined): boolean {
return this.languageFilter === "All" || this.languageFilter === language;
}
}