Merge pull request #266 from aeisenberg/timeout

Display timeout warning and display canceled queries
This commit is contained in:
Andrew Eisenberg 2020-03-09 10:22:50 -07:00 коммит произвёл GitHub
Родитель dfab5900a6 c2e0f251e8
Коммит 059a75c5a4
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
8 изменённых файлов: 64 добавлений и 36 удалений

Просмотреть файл

@ -1,5 +1,5 @@
import { commands, Disposable, ExtensionContext, extensions, ProgressLocation, ProgressOptions, window as Window, Uri } from 'vscode'; import { commands, Disposable, ExtensionContext, extensions, ProgressLocation, ProgressOptions, window as Window, Uri } from 'vscode';
import { ErrorCodes, LanguageClient, ResponseError } from 'vscode-languageclient'; import { LanguageClient } from 'vscode-languageclient';
import * as archiveFilesystemProvider from './archive-filesystem-provider'; import * as archiveFilesystemProvider from './archive-filesystem-provider';
import { DistributionConfigListener, QueryServerConfigListener, QueryHistoryConfigListener } from './config'; import { DistributionConfigListener, QueryServerConfigListener, QueryHistoryConfigListener } from './config';
import { DatabaseManager } from './databases'; import { DatabaseManager } from './databases';
@ -278,18 +278,14 @@ async function activateWithInstalledDistribution(ctx: ExtensionContext, distribu
const info = await compileAndRunQueryAgainstDatabase(cliServer, qs, dbItem, quickEval, selectedQuery); const info = await compileAndRunQueryAgainstDatabase(cliServer, qs, dbItem, quickEval, selectedQuery);
const item = qhm.addQuery(info); const item = qhm.addQuery(info);
await showResultsForCompletedQuery(item, WebviewReveal.NotForced); await showResultsForCompletedQuery(item, WebviewReveal.NotForced);
} } catch (e) {
catch (e) {
if (e instanceof UserCancellationException) { if (e instanceof UserCancellationException) {
logger.log(e.message); helpers.showAndLogWarningMessage(e.message);
} } else if (e instanceof Error) {
else if (e instanceof ResponseError && e.code == ErrorCodes.RequestCancelled) {
logger.log(e.message);
}
else if (e instanceof Error)
helpers.showAndLogErrorMessage(e.message); helpers.showAndLogErrorMessage(e.message);
else } else {
throw e; throw e;
}
} }
} }
} }

Просмотреть файл

@ -68,7 +68,7 @@ export class CompletedQuery implements QueryWithResults {
return `timed out after ${this.result.evaluationTime / 1000} seconds`; return `timed out after ${this.result.evaluationTime / 1000} seconds`;
case messages.QueryResultType.OTHER_ERROR: case messages.QueryResultType.OTHER_ERROR:
default: default:
return `failed`; return this.result.message ? `failed: ${this.result.message}` : 'failed';
} }
} }

Просмотреть файл

@ -4,6 +4,8 @@ import * as path from 'path';
import * as tmp from 'tmp'; import * as tmp from 'tmp';
import { promisify } from 'util'; import { promisify } from 'util';
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import { ErrorCodes, ResponseError } from 'vscode-languageclient';
import * as cli from './cli'; import * as cli from './cli';
import { DatabaseItem, getUpgradesDirectories } from './databases'; import { DatabaseItem, getUpgradesDirectories } from './databases';
import * as helpers from './helpers'; import * as helpers from './helpers';
@ -103,13 +105,19 @@ export class QueryInfo {
} finally { } finally {
qs.unRegisterCallback(callbackId); qs.unRegisterCallback(callbackId);
} }
return result || { evaluationTime: 0, message: "No result from server", queryId: -1, runId: callbackId, resultType: messages.QueryResultType.OTHER_ERROR }; return result || {
evaluationTime: 0,
message: "No result from server",
queryId: -1,
runId: callbackId,
resultType: messages.QueryResultType.OTHER_ERROR
};
} }
async compile( async compile(
qs: qsClient.QueryServerClient, qs: qsClient.QueryServerClient,
): Promise<messages.CompilationMessage[]> { ): Promise<messages.CompilationMessage[]> {
let compiled: messages.CheckQueryResult; let compiled: messages.CheckQueryResult | undefined;
try { try {
const params: messages.CompileQueryParams = { const params: messages.CompileQueryParams = {
compilationOptions: { compilationOptions: {
@ -140,8 +148,7 @@ export class QueryInfo {
} finally { } finally {
qs.logger.log(" - - - COMPILATION DONE - - - "); qs.logger.log(" - - - COMPILATION DONE - - - ");
} }
return (compiled?.messages || []).filter(msg => msg.severity === messages.Severity.ERROR);
return (compiled.messages || []).filter(msg => msg.severity == 0);
} }
/** /**
@ -411,10 +418,24 @@ export async function compileAndRunQueryAgainstDatabase(
const query = new QueryInfo(qlProgram, db, packConfig.dbscheme, quickEvalPosition, metadata); const query = new QueryInfo(qlProgram, db, packConfig.dbscheme, quickEvalPosition, metadata);
await checkDbschemeCompatibility(cliServer, qs, query); await checkDbschemeCompatibility(cliServer, qs, query);
const errors = await query.compile(qs); let errors;
try {
errors = await query.compile(qs);
} catch (e) {
if (e instanceof ResponseError && e.code == ErrorCodes.RequestCancelled) {
return createSyntheticResult(query, db, historyItemOptions, 'Query cancelled', messages.QueryResultType.CANCELLATION);
} else {
throw e;
}
}
if (errors.length == 0) { if (errors.length == 0) {
const result = await query.run(qs); const result = await query.run(qs);
if (result.resultType !== messages.QueryResultType.SUCCESS) {
const message = result.message || 'Failed to run query';
logger.log(message);
helpers.showAndLogErrorMessage(message);
}
return { return {
query, query,
result, result,
@ -448,20 +469,31 @@ export async function compileAndRunQueryAgainstDatabase(
" and choose CodeQL Query Server from the dropdown."); " and choose CodeQL Query Server from the dropdown.");
} }
return { return createSyntheticResult(query, db, historyItemOptions, 'Query had compilation errors', messages.QueryResultType.OTHER_ERROR);
query,
result: {
evaluationTime: 0,
resultType: messages.QueryResultType.OTHER_ERROR,
queryId: -1,
runId: -1,
message: "Query had compilation errors"
},
database: {
name: db.name,
databaseUri: db.databaseUri.toString(true)
},
options: historyItemOptions,
};
} }
} }
function createSyntheticResult(
query: QueryInfo,
db: DatabaseItem,
historyItemOptions: QueryHistoryItemOptions,
message: string,
resultType: number
) {
return {
query,
result: {
evaluationTime: 0,
resultType: resultType,
queryId: -1,
runId: -1,
message
},
database: {
name: db.name,
databaseUri: db.databaseUri.toString(true)
},
options: historyItemOptions,
};
}

Просмотреть файл

@ -58,4 +58,4 @@ export function runTestsInDirectory(testsRoot: string): Promise<void> {
} }
}); });
}); });
} }

Просмотреть файл

@ -23,4 +23,4 @@ describe('launching with a minimal workspace', async () => {
assert(ext!.isActive); assert(ext!.isActive);
}, 1000); }, 1000);
}); });
}); });

Просмотреть файл

@ -1,4 +1,4 @@
import { runTestsInDirectory } from '../index-template'; import { runTestsInDirectory } from '../index-template';
export function run(): Promise<void> { export function run(): Promise<void> {
return runTestsInDirectory(__dirname); return runTestsInDirectory(__dirname);
} }

Просмотреть файл

@ -10,4 +10,4 @@ describe('launching with no specified workspace', () => {
it('should not activate the extension at first', () => { it('should not activate the extension at first', () => {
assert(ext!.isActive === false); assert(ext!.isActive === false);
}); });
}); });

Просмотреть файл

@ -1,4 +1,4 @@
import { runTestsInDirectory } from '../index-template'; import { runTestsInDirectory } from '../index-template';
export function run(): Promise<void> { export function run(): Promise<void> {
return runTestsInDirectory(__dirname); return runTestsInDirectory(__dirname);
} }