Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add language to local query history items #2892

Merged
merged 5 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions extensions/ql-vscode/src/common/interface-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -51,6 +52,7 @@ export const RAW_RESULTS_LIMIT = 10000;
export interface DatabaseInfo {
name: string;
databaseUri: string;
language?: QueryLanguage;
}

/** Arbitrary query metadata */
Expand Down
2 changes: 2 additions & 0 deletions extensions/ql-vscode/src/local-queries/local-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { QueryHistoryConfig } from "../config";
import { LocalQueryInfo } from "../query-results";
import {
buildRepoLabel,
getLanguage,
getRawQueryName,
QueryHistoryInfo,
} from "./query-history-info";
Expand All @@ -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
}

Expand Down Expand Up @@ -84,6 +86,7 @@ export class HistoryItemLabelProvider {
r: `(${resultCount} results)`,
s: statusString,
f: item.getQueryFileName(),
l: this.getLanguageLabel(item),
"%": "%",
};
}
Expand All @@ -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}`;
}
}
12 changes: 12 additions & 0 deletions extensions/ql-vscode/src/query-history/query-history-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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[],
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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[],
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
SortDirection,
SortedResultSetInfo,
} from "../../common/interface-types";
import { mapQueryLanguageToDto } from "./query-history-domain-mapper";

export function mapLocalQueryInfoToDto(
query: LocalQueryInfo,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
SortDirection,
SortedResultSetInfo,
} from "../../common/interface-types";
import { mapQueryLanguageToDomainModel } from "./query-history-dto-mapper";

export function mapLocalQueryItemToDomainModel(
localQuery: QueryHistoryLocalQueryDto,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -27,6 +29,7 @@ export interface InitialQueryInfoDto {
interface DatabaseInfoDto {
name: string;
databaseUri: string;
language?: QueryLanguageDto;
}

interface PositionDto {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
QueryHistoryVariantAnalysisDto,
QueryLanguageDto,
QueryStatusDto,
VariantAnalysisDto,
VariantAnalysisFailureReasonDto,
Expand All @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
QueryHistoryVariantAnalysisDto,
QueryLanguageDto,
QueryStatusDto,
VariantAnalysisDto,
VariantAnalysisFailureReasonDto,
Expand All @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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",
Expand Down