Use new type in dbSchemeToLanguage

This commit is contained in:
Elena Tanasoiu
2023-02-13 20:55:46 +00:00
parent 9508b629f5
commit abbc13033d
2 changed files with 13 additions and 6 deletions

View File

@@ -26,9 +26,9 @@ import { QueryMetadata, SortDirection } from "./pure/interface-types";
import { Logger, ProgressReporter } from "./common";
import { CompilationMessage } from "./pure/legacy-messages";
import { sarifParser } from "./sarif-parser";
import { dbSchemeToLanguage, walkDirectory } from "./helpers";
import { walkDirectory } from "./helpers";
import { App } from "./common/app";
import { QueryLanguage } from "./qlpack-generator";
import { QueryLanguage } from "./types/query-language";
/**
* The version of the SARIF format that we are using.
@@ -1179,9 +1179,11 @@ export class CodeQLCliServer implements Disposable {
*/
public async getSupportedLanguages(): Promise<string[]> {
if (!this._supportedLanguages) {
// Get the intersection of resolveLanguages with the list of hardcoded languages in dbSchemeToLanguage.
// Get the intersection of resolveLanguages with the list of languages in QueryLanguage.
const resolvedLanguages = Object.keys(await this.resolveLanguages());
const hardcodedLanguages = Object.values(dbSchemeToLanguage);
const hardcodedLanguages = Object.values(QueryLanguage).map((s) =>
s.toString(),
);
this._supportedLanguages = resolvedLanguages.filter((lang) =>
hardcodedLanguages.includes(lang),

View File

@@ -30,6 +30,7 @@ import {
walkDirectory,
} from "../../../src/helpers";
import { reportStreamProgress } from "../../../src/commandRunner";
import { QueryLanguage } from "../../../src/types/query-language";
describe("helpers", () => {
describe("Invocation rate limiter", () => {
@@ -146,10 +147,14 @@ describe("helpers", () => {
describe("codeql-database.yml tests", () => {
let dir: tmp.DirResult;
let language: QueryLanguage;
beforeEach(() => {
dir = tmp.dirSync();
language = QueryLanguage.Cpp;
const contents = dump({
primaryLanguage: "cpp",
primaryLanguage: language,
});
writeFileSync(join(dir.name, "codeql-database.yml"), contents, "utf8");
});
@@ -159,7 +164,7 @@ describe("helpers", () => {
});
it("should get initial query contents when language is known", () => {
expect(getInitialQueryContents("cpp", "hucairz")).toBe(
expect(getInitialQueryContents(language, "hucairz")).toBe(
'import cpp\n\nselect ""',
);
});