From c43d0fa805dcd2eadc7271583f873f6a92d3d70e Mon Sep 17 00:00:00 2001 From: Anders Starcke Henriksen Date: Fri, 29 Sep 2023 11:54:45 +0200 Subject: [PATCH 1/4] Add language to local queries. --- .../ql-vscode/src/common/interface-types.ts | 2 ++ .../src/local-queries/local-queries.ts | 2 ++ .../store/query-history-domain-mapper.ts | 28 +++++++++++++++++- .../store/query-history-dto-mapper.ts | 29 ++++++++++++++++++- .../query-history/store/query-history-dto.ts | 11 +++++++ ...query-history-local-query-domain-mapper.ts | 5 ++++ .../query-history-local-query-dto-mapper.ts | 5 ++++ .../store/query-history-local-query-dto.ts | 3 ++ ...-history-variant-analysis-domain-mapper.ts | 26 +---------------- ...ery-history-variant-analysis-dto-mapper.ts | 28 +----------------- .../query-history-variant-analysis-dto.ts | 13 ++------- 11 files changed, 87 insertions(+), 65 deletions(-) diff --git a/extensions/ql-vscode/src/common/interface-types.ts b/extensions/ql-vscode/src/common/interface-types.ts index 9306fde51c1..18dcf12b8c5 100644 --- a/extensions/ql-vscode/src/common/interface-types.ts +++ b/extensions/ql-vscode/src/common/interface-types.ts @@ -21,6 +21,7 @@ import { Method, Usage } from "../model-editor/method"; import { ModeledMethod } from "../model-editor/modeled-method"; import { ModelEditorViewState } from "../model-editor/shared/view-state"; import { Mode } from "../model-editor/shared/mode"; +import { QueryLanguage } from "./query-language"; /** * This module contains types and code that are shared between @@ -51,6 +52,7 @@ export const RAW_RESULTS_LIMIT = 10000; export interface DatabaseInfo { name: string; databaseUri: string; + language?: QueryLanguage; } /** Arbitrary query metadata */ diff --git a/extensions/ql-vscode/src/local-queries/local-queries.ts b/extensions/ql-vscode/src/local-queries/local-queries.ts index 86e316ab6b2..735ff93abc0 100644 --- a/extensions/ql-vscode/src/local-queries/local-queries.ts +++ b/extensions/ql-vscode/src/local-queries/local-queries.ts @@ -49,6 +49,7 @@ import { LocalQueryRun } from "./local-query-run"; import { createMultiSelectionCommand } from "../common/vscode/selection-commands"; import { findLanguage } from "../codeql-cli/query-language"; import type { QueryTreeViewItem } from "../queries-panel/query-tree-view-item"; +import { tryGetQueryLanguage } from "../common/query-language"; interface DatabaseQuickPickItem extends QuickPickItem { databaseItem: DatabaseItem; @@ -364,6 +365,7 @@ export class LocalQueries extends DisposableObject { const initialInfo = await createInitialQueryInfo(selectedQuery, { databaseUri: dbItem.databaseUri.toString(), name: dbItem.name, + language: tryGetQueryLanguage(dbItem.language), }); // When cancellation is requested from the query history view, we just stop the debug session. diff --git a/extensions/ql-vscode/src/query-history/store/query-history-domain-mapper.ts b/extensions/ql-vscode/src/query-history/store/query-history-domain-mapper.ts index 1335cc99bb4..9fd06549f3a 100644 --- a/extensions/ql-vscode/src/query-history/store/query-history-domain-mapper.ts +++ b/extensions/ql-vscode/src/query-history/store/query-history-domain-mapper.ts @@ -1,8 +1,9 @@ import { assertNever } from "../../common/helpers-pure"; import { QueryHistoryInfo } from "../query-history-info"; import { mapLocalQueryInfoToDto } from "./query-history-local-query-domain-mapper"; -import { QueryHistoryItemDto } from "./query-history-dto"; +import { QueryHistoryItemDto, QueryLanguageDto } from "./query-history-dto"; import { mapQueryHistoryVariantAnalysisToDto } from "./query-history-variant-analysis-domain-mapper"; +import { QueryLanguage } from "../../common/query-language"; export function mapQueryHistoryToDto( queries: QueryHistoryInfo[], @@ -17,3 +18,28 @@ export function mapQueryHistoryToDto( } }); } + +export function mapQueryLanguageToDto( + language: QueryLanguage, +): QueryLanguageDto { + switch (language) { + case QueryLanguage.CSharp: + return QueryLanguageDto.CSharp; + case QueryLanguage.Cpp: + return QueryLanguageDto.Cpp; + case QueryLanguage.Go: + return QueryLanguageDto.Go; + case QueryLanguage.Java: + return QueryLanguageDto.Java; + case QueryLanguage.Javascript: + return QueryLanguageDto.Javascript; + case QueryLanguage.Python: + return QueryLanguageDto.Python; + case QueryLanguage.Ruby: + return QueryLanguageDto.Ruby; + case QueryLanguage.Swift: + return QueryLanguageDto.Swift; + default: + assertNever(language); + } +} diff --git a/extensions/ql-vscode/src/query-history/store/query-history-dto-mapper.ts b/extensions/ql-vscode/src/query-history/store/query-history-dto-mapper.ts index 282e5fe2aec..81b91d8dec2 100644 --- a/extensions/ql-vscode/src/query-history/store/query-history-dto-mapper.ts +++ b/extensions/ql-vscode/src/query-history/store/query-history-dto-mapper.ts @@ -1,7 +1,9 @@ import { QueryHistoryInfo } from "../query-history-info"; -import { QueryHistoryItemDto } from "./query-history-dto"; +import { QueryHistoryItemDto, QueryLanguageDto } from "./query-history-dto"; import { mapQueryHistoryVariantAnalysisToDomainModel } from "./query-history-variant-analysis-dto-mapper"; import { mapLocalQueryItemToDomainModel } from "./query-history-local-query-dto-mapper"; +import { QueryLanguage } from "../../common/query-language"; +import { assertNever } from "../../common/helpers-pure"; export function mapQueryHistoryToDomainModel( queries: QueryHistoryItemDto[], @@ -20,3 +22,28 @@ export function mapQueryHistoryToDomainModel( ); }); } + +export function mapQueryLanguageToDomainModel( + language: QueryLanguageDto, +): QueryLanguage { + switch (language) { + case QueryLanguageDto.CSharp: + return QueryLanguage.CSharp; + case QueryLanguageDto.Cpp: + return QueryLanguage.Cpp; + case QueryLanguageDto.Go: + return QueryLanguage.Go; + case QueryLanguageDto.Java: + return QueryLanguage.Java; + case QueryLanguageDto.Javascript: + return QueryLanguage.Javascript; + case QueryLanguageDto.Python: + return QueryLanguage.Python; + case QueryLanguageDto.Ruby: + return QueryLanguage.Ruby; + case QueryLanguageDto.Swift: + return QueryLanguage.Swift; + default: + assertNever(language); + } +} diff --git a/extensions/ql-vscode/src/query-history/store/query-history-dto.ts b/extensions/ql-vscode/src/query-history/store/query-history-dto.ts index 9272112bcea..fafa39f4baf 100644 --- a/extensions/ql-vscode/src/query-history/store/query-history-dto.ts +++ b/extensions/ql-vscode/src/query-history/store/query-history-dto.ts @@ -12,3 +12,14 @@ export interface QueryHistoryDto { export type QueryHistoryItemDto = | QueryHistoryLocalQueryDto | QueryHistoryVariantAnalysisDto; + +export enum QueryLanguageDto { + CSharp = "csharp", + Cpp = "cpp", + Go = "go", + Java = "java", + Javascript = "javascript", + Python = "python", + Ruby = "ruby", + Swift = "swift", +} diff --git a/extensions/ql-vscode/src/query-history/store/query-history-local-query-domain-mapper.ts b/extensions/ql-vscode/src/query-history/store/query-history-local-query-domain-mapper.ts index 97e1ba12c8f..8ff79241c96 100644 --- a/extensions/ql-vscode/src/query-history/store/query-history-local-query-domain-mapper.ts +++ b/extensions/ql-vscode/src/query-history/store/query-history-local-query-domain-mapper.ts @@ -17,6 +17,7 @@ import { SortDirection, SortedResultSetInfo, } from "../../common/interface-types"; +import { mapQueryLanguageToDto } from "./query-history-domain-mapper"; export function mapLocalQueryInfoToDto( query: LocalQueryInfo, @@ -101,6 +102,10 @@ function mapInitialQueryInfoToDto( databaseInfo: { databaseUri: localQueryInitialInfo.databaseInfo.databaseUri, name: localQueryInitialInfo.databaseInfo.name, + language: + localQueryInitialInfo.databaseInfo.language === undefined + ? undefined + : mapQueryLanguageToDto(localQueryInitialInfo.databaseInfo.language), }, start: localQueryInitialInfo.start, id: localQueryInitialInfo.id, diff --git a/extensions/ql-vscode/src/query-history/store/query-history-local-query-dto-mapper.ts b/extensions/ql-vscode/src/query-history/store/query-history-local-query-dto-mapper.ts index 931cd063f38..072db2d2d55 100644 --- a/extensions/ql-vscode/src/query-history/store/query-history-local-query-dto-mapper.ts +++ b/extensions/ql-vscode/src/query-history/store/query-history-local-query-dto-mapper.ts @@ -20,6 +20,7 @@ import { SortDirection, SortedResultSetInfo, } from "../../common/interface-types"; +import { mapQueryLanguageToDomainModel } from "./query-history-dto-mapper"; export function mapLocalQueryItemToDomainModel( localQuery: QueryHistoryLocalQueryDto, @@ -82,6 +83,10 @@ function mapInitialQueryInfoToDomainModel( databaseInfo: { databaseUri: initialInfo.databaseInfo.databaseUri, name: initialInfo.databaseInfo.name, + language: + initialInfo.databaseInfo.language === undefined + ? undefined + : mapQueryLanguageToDomainModel(initialInfo.databaseInfo.language), }, start: new Date(initialInfo.start), id: initialInfo.id, diff --git a/extensions/ql-vscode/src/query-history/store/query-history-local-query-dto.ts b/extensions/ql-vscode/src/query-history/store/query-history-local-query-dto.ts index 80ef587cb9d..a72de2939f7 100644 --- a/extensions/ql-vscode/src/query-history/store/query-history-local-query-dto.ts +++ b/extensions/ql-vscode/src/query-history/store/query-history-local-query-dto.ts @@ -1,6 +1,8 @@ // Contains models and consts for the data we want to store in the query history store. // Changes to these models should be done carefully and account for backwards compatibility of data. +import { QueryLanguageDto } from "./query-history-dto"; + export interface QueryHistoryLocalQueryDto { initialInfo: InitialQueryInfoDto; t: "local"; @@ -27,6 +29,7 @@ export interface InitialQueryInfoDto { interface DatabaseInfoDto { name: string; databaseUri: string; + language?: QueryLanguageDto; } interface PositionDto { diff --git a/extensions/ql-vscode/src/query-history/store/query-history-variant-analysis-domain-mapper.ts b/extensions/ql-vscode/src/query-history/store/query-history-variant-analysis-domain-mapper.ts index 607d1199153..5304f781c81 100644 --- a/extensions/ql-vscode/src/query-history/store/query-history-variant-analysis-domain-mapper.ts +++ b/extensions/ql-vscode/src/query-history/store/query-history-variant-analysis-domain-mapper.ts @@ -1,6 +1,5 @@ import { QueryHistoryVariantAnalysisDto, - QueryLanguageDto, QueryStatusDto, VariantAnalysisDto, VariantAnalysisFailureReasonDto, @@ -22,9 +21,9 @@ import { VariantAnalysisStatus, } from "../../variant-analysis/shared/variant-analysis"; import { assertNever } from "../../common/helpers-pure"; -import { QueryLanguage } from "../../common/query-language"; import { QueryStatus } from "../query-status"; import { VariantAnalysisHistoryItem } from "../variant-analysis-history-item"; +import { mapQueryLanguageToDto } from "./query-history-domain-mapper"; export function mapQueryHistoryVariantAnalysisToDto( item: VariantAnalysisHistoryItem, @@ -199,29 +198,6 @@ function mapVariantAnalysisStatusToDto( } } -function mapQueryLanguageToDto(language: QueryLanguage): QueryLanguageDto { - switch (language) { - case QueryLanguage.CSharp: - return QueryLanguageDto.CSharp; - case QueryLanguage.Cpp: - return QueryLanguageDto.Cpp; - case QueryLanguage.Go: - return QueryLanguageDto.Go; - case QueryLanguage.Java: - return QueryLanguageDto.Java; - case QueryLanguage.Javascript: - return QueryLanguageDto.Javascript; - case QueryLanguage.Python: - return QueryLanguageDto.Python; - case QueryLanguage.Ruby: - return QueryLanguageDto.Ruby; - case QueryLanguage.Swift: - return QueryLanguageDto.Swift; - default: - assertNever(language); - } -} - function mapQueryStatusToDto(status: QueryStatus): QueryStatusDto { switch (status) { case QueryStatus.InProgress: diff --git a/extensions/ql-vscode/src/query-history/store/query-history-variant-analysis-dto-mapper.ts b/extensions/ql-vscode/src/query-history/store/query-history-variant-analysis-dto-mapper.ts index 1baeb919383..a40df411e06 100644 --- a/extensions/ql-vscode/src/query-history/store/query-history-variant-analysis-dto-mapper.ts +++ b/extensions/ql-vscode/src/query-history/store/query-history-variant-analysis-dto-mapper.ts @@ -1,6 +1,5 @@ import { QueryHistoryVariantAnalysisDto, - QueryLanguageDto, QueryStatusDto, VariantAnalysisDto, VariantAnalysisFailureReasonDto, @@ -22,9 +21,9 @@ import { VariantAnalysisStatus, } from "../../variant-analysis/shared/variant-analysis"; import { assertNever } from "../../common/helpers-pure"; -import { QueryLanguage } from "../../common/query-language"; import { QueryStatus } from "../query-status"; import { VariantAnalysisHistoryItem } from "../variant-analysis-history-item"; +import { mapQueryLanguageToDomainModel } from "./query-history-dto-mapper"; export function mapQueryHistoryVariantAnalysisToDomainModel( item: QueryHistoryVariantAnalysisDto, @@ -215,31 +214,6 @@ function mapVariantAnalysisStatusToDomainModel( } } -function mapQueryLanguageToDomainModel( - language: QueryLanguageDto, -): QueryLanguage { - switch (language) { - case QueryLanguageDto.CSharp: - return QueryLanguage.CSharp; - case QueryLanguageDto.Cpp: - return QueryLanguage.Cpp; - case QueryLanguageDto.Go: - return QueryLanguage.Go; - case QueryLanguageDto.Java: - return QueryLanguage.Java; - case QueryLanguageDto.Javascript: - return QueryLanguage.Javascript; - case QueryLanguageDto.Python: - return QueryLanguage.Python; - case QueryLanguageDto.Ruby: - return QueryLanguage.Ruby; - case QueryLanguageDto.Swift: - return QueryLanguage.Swift; - default: - assertNever(language); - } -} - function mapQueryStatusToDomainModel(status: QueryStatusDto): QueryStatus { switch (status) { case QueryStatusDto.InProgress: diff --git a/extensions/ql-vscode/src/query-history/store/query-history-variant-analysis-dto.ts b/extensions/ql-vscode/src/query-history/store/query-history-variant-analysis-dto.ts index f6ef48177fc..e1274c00297 100644 --- a/extensions/ql-vscode/src/query-history/store/query-history-variant-analysis-dto.ts +++ b/extensions/ql-vscode/src/query-history/store/query-history-variant-analysis-dto.ts @@ -1,6 +1,8 @@ // Contains models and consts for the data we want to store in the query history store. // Changes to these models should be done carefully and account for backwards compatibility of data. +import { QueryLanguageDto } from "./query-history-dto"; + export interface QueryHistoryVariantAnalysisDto { readonly t: "variant-analysis"; failureReason?: string; @@ -97,17 +99,6 @@ export enum VariantAnalysisStatusDto { Canceled = "canceled", } -export enum QueryLanguageDto { - CSharp = "csharp", - Cpp = "cpp", - Go = "go", - Java = "java", - Javascript = "javascript", - Python = "python", - Ruby = "ruby", - Swift = "swift", -} - export enum QueryStatusDto { InProgress = "InProgress", Completed = "Completed", From c4fe86882673f0edf2170ab0760f852e41149911 Mon Sep 17 00:00:00 2001 From: Anders Starcke Henriksen Date: Fri, 29 Sep 2023 12:15:55 +0200 Subject: [PATCH 2/4] Add a way to show language for qury history. --- .../src/query-history/history-item-label-provider.ts | 9 +++++++++ .../src/query-history/query-history-info.ts | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/extensions/ql-vscode/src/query-history/history-item-label-provider.ts b/extensions/ql-vscode/src/query-history/history-item-label-provider.ts index 52b2b8f1a04..95d43f6b483 100644 --- a/extensions/ql-vscode/src/query-history/history-item-label-provider.ts +++ b/extensions/ql-vscode/src/query-history/history-item-label-provider.ts @@ -4,6 +4,7 @@ import { QueryHistoryConfig } from "../config"; import { LocalQueryInfo } from "../query-results"; import { buildRepoLabel, + getLanguage, getRawQueryName, QueryHistoryInfo, } from "./query-history-info"; @@ -19,6 +20,7 @@ interface InterpolateReplacements { r: string; // Result count/Empty s: string; // Status f: string; // Query file name + l: string; // Query language "%": "%"; // Percent sign } @@ -84,6 +86,7 @@ export class HistoryItemLabelProvider { r: `(${resultCount} results)`, s: statusString, f: item.getQueryFileName(), + l: this.getLanguageLabel(item), "%": "%", }; } @@ -103,7 +106,13 @@ export class HistoryItemLabelProvider { r: resultCount, s: humanizeQueryStatus(item.status), f: basename(item.variantAnalysis.query.filePath), + l: this.getLanguageLabel(item), "%": "%", }; } + + private getLanguageLabel(item: QueryHistoryInfo): string { + const language = getLanguage(item); + return language === undefined ? "unknown" : `${language}`; + } } diff --git a/extensions/ql-vscode/src/query-history/query-history-info.ts b/extensions/ql-vscode/src/query-history/query-history-info.ts index 374ee1e32bc..6ba35f81b73 100644 --- a/extensions/ql-vscode/src/query-history/query-history-info.ts +++ b/extensions/ql-vscode/src/query-history/query-history-info.ts @@ -6,6 +6,7 @@ import { hasRepoScanCompleted, getActionsWorkflowRunUrl as getVariantAnalysisActionsWorkflowRunUrl, } from "../variant-analysis/shared/variant-analysis"; +import { QueryLanguage } from "../common/query-language"; export type QueryHistoryInfo = LocalQueryInfo | VariantAnalysisHistoryItem; @@ -49,6 +50,17 @@ export function getQueryText(item: QueryHistoryInfo): string { } } +export function getLanguage(item: QueryHistoryInfo): QueryLanguage | undefined { + switch (item.t) { + case "local": + return item.initialInfo.databaseInfo.language; + case "variant-analysis": + return item.variantAnalysis.query.language; + default: + assertNever(item); + } +} + export function buildRepoLabel(item: VariantAnalysisHistoryItem): string { const totalScannedRepositoryCount = item.variantAnalysis.scannedRepos?.length ?? 0; From b294e16c44bcbc2a2c2f7d0b01496dfc5ed5fafd Mon Sep 17 00:00:00 2001 From: Anders Starcke Henriksen Date: Tue, 3 Oct 2023 11:01:03 +0200 Subject: [PATCH 3/4] Add to changelog. --- extensions/ql-vscode/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/extensions/ql-vscode/CHANGELOG.md b/extensions/ql-vscode/CHANGELOG.md index 2fd6c12181c..7cf3078fc3d 100644 --- a/extensions/ql-vscode/CHANGELOG.md +++ b/extensions/ql-vscode/CHANGELOG.md @@ -2,6 +2,8 @@ ## [UNRELEASED] +- It is now possible to show the language of query history items using the `%l` specifier in the `codeQL.queryHistory.format` setting. Note that this only works queries run after this upgrade, and older items will show `unknown` as a language. [#2892](https://github.com/github/vscode-codeql/pull/2892) + ## 1.9.0 - 19 September 2023 - Release the [CodeQL model editor](https://codeql.github.com/docs/codeql/codeql-for-visual-studio-code/using-the-codeql-model-editor) to create CodeQL model packs for Java frameworks. Open the editor using the "CodeQL: Open CodeQL Model Editor (Beta)" command. [#2823](https://github.com/github/vscode-codeql/pull/2823) From 6d2859cee5d5cc068e923b6275ad6365dea6ff0e Mon Sep 17 00:00:00 2001 From: Anders Starcke Henriksen Date: Tue, 3 Oct 2023 11:23:32 +0200 Subject: [PATCH 4/4] Fix typo. --- extensions/ql-vscode/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/ql-vscode/CHANGELOG.md b/extensions/ql-vscode/CHANGELOG.md index e6e5ea2d012..253d0d99c03 100644 --- a/extensions/ql-vscode/CHANGELOG.md +++ b/extensions/ql-vscode/CHANGELOG.md @@ -2,7 +2,7 @@ ## [UNRELEASED] -- It is now possible to show the language of query history items using the `%l` specifier in the `codeQL.queryHistory.format` setting. Note that this only works queries run after this upgrade, and older items will show `unknown` as a language. [#2892](https://github.com/github/vscode-codeql/pull/2892) +- It is now possible to show the language of query history items using the `%l` specifier in the `codeQL.queryHistory.format` setting. Note that this only works for queries run after this upgrade, and older items will show `unknown` as a language. [#2892](https://github.com/github/vscode-codeql/pull/2892) - Increase the required version of VS Code to 1.82.0. [#2877](https://github.com/github/vscode-codeql/pull/2877) - Fix a bug where the query server was restarted twice after configuration changes. [#2884](https://github.com/github/vscode-codeql/pull/2884).