Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions extensions/ql-vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Fix a bug where the results view moved column even when it was already visible. [#1070](https://github.com/github/vscode-codeql/pull/1070)
- Add packaging-related commands. _CodeQL: Download Packs_ downloads query packs from the package registry that can be run locally, and _CodeQL: Install Pack Dependencies_ installs dependencies for packs in your workspace. [#1076](https://github.com/github/vscode-codeql/pull/1076)
- Add query history items as soon as a query is run, including new icons for each history item. [#1094](https://github.com/github/vscode-codeql/pull/1094)

## 1.5.9 - 17 December 2021

Expand Down
7 changes: 7 additions & 0 deletions extensions/ql-vscode/media/drive.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 23 additions & 27 deletions extensions/ql-vscode/src/compare/compare-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
import * as path from 'path';

import { tmpDir } from '../run-queries';
import { CompletedQuery } from '../query-results';
import {
FromCompareViewMessage,
ToCompareViewMessage,
Expand All @@ -21,10 +20,11 @@ import { DatabaseManager } from '../databases';
import { getHtmlForWebview, jumpToLocation } from '../interface-utils';
import { transformBqrsResultSet, RawResultSet, BQRSInfo } from '../pure/bqrs-cli-types';
import resultsDiff from './resultsDiff';
import { FullCompletedQueryInfo } from '../query-results';

interface ComparePair {
from: CompletedQuery;
to: CompletedQuery;
from: FullCompletedQueryInfo;
to: FullCompletedQueryInfo;
}

export class CompareInterfaceManager extends DisposableObject {
Expand All @@ -39,15 +39,15 @@ export class CompareInterfaceManager extends DisposableObject {
private cliServer: CodeQLCliServer,
private logger: Logger,
private showQueryResultsCallback: (
item: CompletedQuery
item: FullCompletedQueryInfo
) => Promise<void>
) {
super();
}

async showResults(
from: CompletedQuery,
to: CompletedQuery,
from: FullCompletedQueryInfo,
to: FullCompletedQueryInfo,
selectedResultSetName?: string
) {
this.comparePair = { from, to };
Expand Down Expand Up @@ -80,26 +80,22 @@ export class CompareInterfaceManager extends DisposableObject {
// since we split the description into several rows
// only run interpolation if the label is user-defined
// otherwise we will wind up with duplicated rows
name: from.options.label
? from.interpolate(from.getLabel())
: from.queryName,
status: from.statusString,
time: from.time,
name: from.getShortLabel(),
status: from.completedQuery.statusString,
time: from.startTime,
},
toQuery: {
name: to.options.label
? to.interpolate(to.getLabel())
: to.queryName,
status: to.statusString,
time: to.time,
name: to.getShortLabel(),
status: to.completedQuery.statusString,
time: to.startTime,
},
},
columns: fromResultSet.schema.columns,
commonResultSetNames,
currentResultSetName: currentResultSetName,
rows,
message,
datebaseUri: to.database.databaseUri,
datebaseUri: to.initialInfo.databaseInfo.databaseUri,
Comment thread
shati-patel marked this conversation as resolved.
Outdated
});
}
}
Expand All @@ -121,14 +117,14 @@ export class CompareInterfaceManager extends DisposableObject {
],
}
));
this.panel.onDidDispose(
this.push(this.panel.onDidDispose(
() => {
this.panel = undefined;
this.comparePair = undefined;
},
null,
ctx.subscriptions
);
));

const scriptPathOnDisk = Uri.file(
ctx.asAbsolutePath('out/compareView.js')
Expand All @@ -143,11 +139,11 @@ export class CompareInterfaceManager extends DisposableObject {
scriptPathOnDisk,
[stylesheetPathOnDisk]
);
panel.webview.onDidReceiveMessage(
this.push(panel.webview.onDidReceiveMessage(
async (e) => this.handleMsgFromView(e),
undefined,
ctx.subscriptions
);
));
}
return this.panel;
}
Expand Down Expand Up @@ -191,15 +187,15 @@ export class CompareInterfaceManager extends DisposableObject {
}

private async findCommonResultSetNames(
from: CompletedQuery,
to: CompletedQuery,
from: FullCompletedQueryInfo,
to: FullCompletedQueryInfo,
selectedResultSetName: string | undefined
): Promise<[string[], string, RawResultSet, RawResultSet]> {
const fromSchemas = await this.cliServer.bqrsInfo(
from.query.resultsPaths.resultsPath
from.completedQuery.query.resultsPaths.resultsPath
);
const toSchemas = await this.cliServer.bqrsInfo(
to.query.resultsPaths.resultsPath
to.completedQuery.query.resultsPaths.resultsPath
);
const fromSchemaNames = fromSchemas['result-sets'].map(
(schema) => schema.name
Expand All @@ -215,12 +211,12 @@ export class CompareInterfaceManager extends DisposableObject {
const fromResultSet = await this.getResultSet(
fromSchemas,
currentResultSetName,
from.query.resultsPaths.resultsPath
from.completedQuery.query.resultsPaths.resultsPath
);
const toResultSet = await this.getResultSet(
toSchemas,
currentResultSetName,
to.query.resultsPaths.resultsPath
to.completedQuery.query.resultsPaths.resultsPath
);
return [
commonResultSetNames,
Expand Down
25 changes: 16 additions & 9 deletions extensions/ql-vscode/src/contextual/locationFinder.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import * as vscode from 'vscode';

import { decodeSourceArchiveUri, encodeArchiveBasePath } from '../archive-filesystem-provider';
import { ColumnKindCode, EntityValue, getResultSetSchema, ResultSetSchema } from '../pure/bqrs-cli-types';
import { CodeQLCliServer } from '../cli';
import { DatabaseManager, DatabaseItem } from '../databases';
import fileRangeFromURI from './fileRangeFromURI';
import * as messages from '../pure/messages';
import { QueryServerClient } from '../queryserver-client';
import { QueryWithResults, compileAndRunQueryAgainstDatabase } from '../run-queries';
import { QueryWithResults, compileAndRunQueryAgainstDatabase, createInitialQueryInfo } from '../run-queries';
import { ProgressCallback } from '../commandRunner';
import { KeyType } from './keyType';
import { qlpackOfDatabase, resolveQueries } from './queryResolver';
import { CancellationToken, LocationLink, Uri } from 'vscode';

export const SELECT_QUERY_NAME = '#select';
export const TEMPLATE_NAME = 'selectedSourceFile';

export interface FullLocationLink extends vscode.LocationLink {
originUri: vscode.Uri;
export interface FullLocationLink extends LocationLink {
originUri: Uri;
}

/**
Expand All @@ -40,10 +39,10 @@ export async function getLocationsForUriString(
uriString: string,
keyType: KeyType,
progress: ProgressCallback,
token: vscode.CancellationToken,
token: CancellationToken,
filter: (src: string, dest: string) => boolean
): Promise<FullLocationLink[]> {
const uri = decodeSourceArchiveUri(vscode.Uri.parse(uriString, true));
const uri = decodeSourceArchiveUri(Uri.parse(uriString, true));
const sourceArchiveUri = encodeArchiveBasePath(uri.sourceArchiveZipPath);

const db = dbm.findDatabaseItemBySourceArchive(sourceArchiveUri);
Expand All @@ -56,12 +55,20 @@ export async function getLocationsForUriString(

const links: FullLocationLink[] = [];
for (const query of await resolveQueries(cli, qlpack, keyType)) {
const initialInfo = await createInitialQueryInfo(
Uri.file(query),
{
name: db.name,
databaseUri: db.databaseUri.toString(),
},
false
);

const results = await compileAndRunQueryAgainstDatabase(
cli,
qs,
db,
false,
vscode.Uri.file(query),
initialInfo,
progress,
token,
templates
Expand Down
46 changes: 31 additions & 15 deletions extensions/ql-vscode/src/contextual/templateProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { CachedOperation } from '../helpers';
import { ProgressCallback, withProgress } from '../commandRunner';
import * as messages from '../pure/messages';
import { QueryServerClient } from '../queryserver-client';
import { compileAndRunQueryAgainstDatabase, QueryWithResults } from '../run-queries';
import { compileAndRunQueryAgainstDatabase, createInitialQueryInfo, QueryWithResults } from '../run-queries';
import AstBuilder from './astBuilder';
import {
KeyType,
Expand Down Expand Up @@ -123,15 +123,20 @@ export class TemplateQueryReferenceProvider implements ReferenceProvider {
}
}

type QueryWithDb = {
query: QueryWithResults,
dbUri: Uri
};

export class TemplatePrintAstProvider {
private cache: CachedOperation<QueryWithResults>;
private cache: CachedOperation<QueryWithDb>;

constructor(
private cli: CodeQLCliServer,
private qs: QueryServerClient,
private dbm: DatabaseManager,
) {
this.cache = new CachedOperation<QueryWithResults>(this.getAst.bind(this));
this.cache = new CachedOperation<QueryWithDb>(this.getAst.bind(this));
}

async provideAst(
Expand All @@ -142,13 +147,13 @@ export class TemplatePrintAstProvider {
if (!document) {
throw new Error('Cannot view the AST. Please select a valid source file inside a CodeQL database.');
}
const queryResults = this.shouldCache()
const { query, dbUri } = this.shouldCache()
? await this.cache.get(document.uri.toString(), progress, token)
: await this.getAst(document.uri.toString(), progress, token);

return new AstBuilder(
queryResults, this.cli,
this.dbm.findDatabaseItem(Uri.parse(queryResults.database.databaseUri!, true))!,
query, this.cli,
this.dbm.findDatabaseItem(dbUri)!,
document.fileName
);
}
Expand All @@ -161,7 +166,7 @@ export class TemplatePrintAstProvider {
uriString: string,
progress: ProgressCallback,
token: CancellationToken
): Promise<QueryWithResults> {
): Promise<QueryWithDb> {
const uri = Uri.parse(uriString, true);
if (uri.scheme !== zipArchiveScheme) {
throw new Error('Cannot view the AST. Please select a valid source file inside a CodeQL database.');
Expand Down Expand Up @@ -195,15 +200,26 @@ export class TemplatePrintAstProvider {
}
};

return await compileAndRunQueryAgainstDatabase(
this.cli,
this.qs,
db,
false,
const initialInfo = await createInitialQueryInfo(
Uri.file(query),
progress,
token,
templates
{
name: db.name,
databaseUri: db.databaseUri.toString(),
},
false
);

return {
query: await compileAndRunQueryAgainstDatabase(
this.cli,
this.qs,
db,
initialInfo,
progress,
token,
templates
),
dbUri: db.databaseUri
};
}
}
Loading