Add support for filename pattern in history view
This commit is contained in:
committed by
Edoardo Pirovano
parent
3d647f68e1
commit
06ef67f22d
@@ -206,7 +206,7 @@
|
||||
"codeQL.queryHistory.format": {
|
||||
"type": "string",
|
||||
"default": "%q on %d - %s, %r result count [%t]",
|
||||
"description": "Default string for how to label query history items. %t is the time of the query, %q is the query name, %d is the database name, %r is the number of results, and %s is a status string."
|
||||
"markdownDescription": "Default string for how to label query history items.\n* %t is the time of the query\n* %q is the human-readable query name\n*%f is the query file name\n* %d is the database name\n* %r is the number of results\n* %s is a status string"
|
||||
},
|
||||
"codeQL.runningTests.additionalTestArguments": {
|
||||
"scope": "window",
|
||||
|
||||
@@ -62,6 +62,9 @@ export class CompletedQuery implements QueryWithResults {
|
||||
get queryName(): string {
|
||||
return getQueryName(this.query);
|
||||
}
|
||||
get queryFileName(): string {
|
||||
return getQueryFileName(this.query);
|
||||
}
|
||||
|
||||
get statusString(): string {
|
||||
switch (this.result.resultType) {
|
||||
@@ -88,13 +91,14 @@ export class CompletedQuery implements QueryWithResults {
|
||||
}
|
||||
|
||||
interpolate(template: string): string {
|
||||
const { databaseName, queryName, time, resultCount, statusString } = this;
|
||||
const { databaseName, queryName, time, resultCount, statusString, queryFileName } = this;
|
||||
const replacements: { [k: string]: string } = {
|
||||
t: time,
|
||||
q: queryName,
|
||||
d: databaseName,
|
||||
r: resultCount.toString(),
|
||||
s: statusString,
|
||||
f: queryFileName,
|
||||
'%': '%',
|
||||
};
|
||||
return template.replace(/%(.)/g, (match, key) => {
|
||||
@@ -152,17 +156,28 @@ export class CompletedQuery implements QueryWithResults {
|
||||
* Uses metadata if it exists, and defaults to the query file name.
|
||||
*/
|
||||
export function getQueryName(query: QueryInfo) {
|
||||
if (query.quickEvalPosition !== undefined) {
|
||||
return 'Quick evaluation of ' + getQueryFileName(query);
|
||||
} else if (query.metadata?.name) {
|
||||
return query.metadata.name;
|
||||
} else {
|
||||
return getQueryFileName(query);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the file name for an evaluated query.
|
||||
* Defaults to the query file name and may contain position information for quick eval queries.
|
||||
*/
|
||||
export function getQueryFileName(query: QueryInfo) {
|
||||
// Queries run through quick evaluation are not usually the entire query file.
|
||||
// Label them differently and include the line numbers.
|
||||
if (query.quickEvalPosition !== undefined) {
|
||||
const { line, endLine, fileName } = query.quickEvalPosition;
|
||||
const lineInfo = line === endLine ? `${line}` : `${line}-${endLine}`;
|
||||
return `Quick evaluation of ${path.basename(fileName)}:${lineInfo}`;
|
||||
} else if (query.metadata?.name) {
|
||||
return query.metadata.name;
|
||||
} else {
|
||||
return path.basename(query.program.queryPath);
|
||||
return `${path.basename(fileName)}:${lineInfo}`;
|
||||
}
|
||||
return path.basename(query.program.queryPath);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -54,6 +54,23 @@ describe('CompletedQuery', () => {
|
||||
expect(completedQuery.queryName).to.eq('Quick evaluation of yz:1');
|
||||
});
|
||||
|
||||
it('should get the query file name', () => {
|
||||
const completedQuery = mockCompletedQuery();
|
||||
|
||||
// from the query path
|
||||
expect(completedQuery.queryFileName).to.eq('stu');
|
||||
|
||||
// from quick eval position
|
||||
(completedQuery.query as any).quickEvalPosition = {
|
||||
line: 1,
|
||||
endLine: 2,
|
||||
fileName: '/home/users/yz'
|
||||
};
|
||||
expect(completedQuery.queryFileName).to.eq('yz:1-2');
|
||||
(completedQuery.query as any).quickEvalPosition.endLine = 1;
|
||||
expect(completedQuery.queryFileName).to.eq('yz:1');
|
||||
});
|
||||
|
||||
it('should get the label', () => {
|
||||
const completedQuery = mockCompletedQuery();
|
||||
expect(completedQuery.getLabel()).to.eq('ghi');
|
||||
|
||||
Reference in New Issue
Block a user