Skip to content

Commit 4257555

Browse files
committed
Remote queries: Open query file/text from webview
1 parent 33b1465 commit 4257555

7 files changed

Lines changed: 52 additions & 3 deletions

File tree

extensions/ql-vscode/src/pure/interface-types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,8 @@ export interface ParsedResultSets {
368368

369369
export type FromRemoteQueriesMessage =
370370
| RemoteQueryLoadedMessage
371-
| RemoteQueryErrorMessage;
371+
| RemoteQueryErrorMessage
372+
| OpenFileMsg;
372373

373374
export type ToRemoteQueriesMessage =
374375
| SetRemoteQueryResultMessage;

extensions/ql-vscode/src/remote-queries/remote-queries-interface.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
window as Window,
55
ViewColumn,
66
Uri,
7+
workspace,
78
} from 'vscode';
89
import * as path from 'path';
910

@@ -62,6 +63,8 @@ export class RemoteQueriesInterfaceManager {
6263
return {
6364
queryTitle: query.queryName,
6465
queryFile: queryFile,
66+
queryPath: query.queryFilePath,
67+
queryTextTmpFile: query.queryTextTmpFile,
6568
totalRepositoryCount: query.repositories.length,
6669
affectedRepositoryCount: affectedRepositories.length,
6770
totalResultCount: totalResultCount,
@@ -129,6 +132,11 @@ export class RemoteQueriesInterfaceManager {
129132
});
130133
}
131134

135+
public async openFile(filePath: string) {
136+
const textDocument = await workspace.openTextDocument(filePath);
137+
await Window.showTextDocument(textDocument, ViewColumn.One);
138+
}
139+
132140
private async handleMsgFromView(
133141
msg: FromRemoteQueriesMessage
134142
): Promise<void> {
@@ -143,6 +151,9 @@ export class RemoteQueriesInterfaceManager {
143151
`Remote query error: ${msg.error}`
144152
);
145153
break;
154+
case 'openFile':
155+
await this.openFile(msg.filePath);
156+
break;
146157
default:
147158
assertNever(msg);
148159
}

extensions/ql-vscode/src/remote-queries/remote-query.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Repository } from './repository';
33
export interface RemoteQuery {
44
queryName: string;
55
queryFilePath: string;
6+
queryTextTmpFile: string;
67
controllerRepository: Repository;
78
repositories: Repository[];
89
executionStartTime: Date;

extensions/ql-vscode/src/remote-queries/run-remote-query.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,9 +467,13 @@ function buildRemoteQueryEntity(
467467
return { owner: owner, name: repo };
468468
});
469469

470+
// TODO: Get query text from query file and save it in a temporary .ql file.
471+
const queryTextTmpFile = '';
472+
470473
return {
471474
queryName,
472475
queryFilePath,
476+
queryTextTmpFile,
473477
controllerRepository: {
474478
owner: controllerRepoOwner,
475479
name: controllerRepoName,

extensions/ql-vscode/src/remote-queries/shared/remote-query-result.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
export interface RemoteQueryResult {
22
queryTitle: string;
33
queryFile: string;
4+
queryPath: string;
5+
queryTextTmpFile: string;
46
totalRepositoryCount: number;
57
affectedRepositoryCount: number;
68
totalResultCount: number;

extensions/ql-vscode/src/remote-queries/view/RemoteQueries.tsx

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const numOfReposInContractedMode = 10;
1212
const emptyQueryResult: RemoteQueryResult = {
1313
queryTitle: '',
1414
queryFile: '',
15+
queryPath: '',
16+
queryTextTmpFile: '',
1517
totalRepositoryCount: 0,
1618
affectedRepositoryCount: 0,
1719
totalResultCount: 0,
@@ -38,6 +40,13 @@ const AnalysisResultItem = (props: AnalysisResult) => (
3840
</span>
3941
);
4042

43+
function openFile(filePath: string): void {
44+
vscode.postMessage({
45+
t: 'openFile',
46+
filePath
47+
});
48+
}
49+
4150
export function RemoteQueries(): JSX.Element {
4251
const [queryResult, setQueryResult] = useState<RemoteQueryResult>(emptyQueryResult);
4352

@@ -64,6 +73,14 @@ export function RemoteQueries(): JSX.Element {
6473
const numOfReposToShow = repoListExpanded ? queryResult.results.length : numOfReposInContractedMode;
6574

6675
try {
76+
const openQueryFile = () => {
77+
openFile(queryResult.queryPath);
78+
};
79+
80+
const openQueryTextTmpFile = () => {
81+
openFile(queryResult.queryTextTmpFile);
82+
};
83+
6784
return <div className="vscode-codeql__remote-queries-view">
6885
<h1 className="vscode-codeql__query-title">{queryResult.queryTitle}</h1>
6986

@@ -72,8 +89,16 @@ export function RemoteQueries(): JSX.Element {
7289
({queryResult.executionDuration}), {queryResult.executionTimestamp}
7390
</p>
7491
<p className="vscode-codeql__paragraph">
75-
<span className="vscode-codeql__query-file">{octicons.file} <span>{queryResult.queryFile}</span></span>
76-
<span>{octicons.codeSquare} <span>query</span></span>
92+
<span className="vscode-codeql__query-file">{octicons.file}
93+
<a className="vscode-codeql__query-file-link" href="#" onClick={openQueryFile}>
94+
{queryResult.queryFile}
95+
</a>
96+
</span>
97+
<span>{octicons.codeSquare}
98+
<a className="vscode-codeql__query-file-link" href="#" onClick={openQueryTextTmpFile}>
99+
query
100+
</a>
101+
</span>
77102
</p>
78103

79104
<div className="vscode-codeql__query-summary-container">

extensions/ql-vscode/src/remote-queries/view/remoteQueries.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939
padding-right: 1em;
4040
}
4141

42+
.vscode-codeql__query-file-link {
43+
text-decoration: none;
44+
padding-left: 0.3em;
45+
}
46+
4247
.vscode-codeql__query-summary-container {
4348
padding-top: 1.5em;
4449
}

0 commit comments

Comments
 (0)