Skip to content

Commit

Permalink
Remote queries: Open query file/text from webview
Browse files Browse the repository at this point in the history
  • Loading branch information
shati-patel committed Dec 8, 2021
1 parent 4364f11 commit f581df3
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 3 deletions.
3 changes: 2 additions & 1 deletion extensions/ql-vscode/src/pure/interface-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ export interface ParsedResultSets {

export type FromRemoteQueriesMessage =
| RemoteQueryLoadedMessage
| RemoteQueryErrorMessage;
| RemoteQueryErrorMessage
| OpenFileMsg;

export type ToRemoteQueriesMessage =
| SetRemoteQueryResultMessage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
window as Window,
ViewColumn,
Uri,
workspace,
} from 'vscode';
import * as path from 'path';

Expand Down Expand Up @@ -62,6 +63,8 @@ export class RemoteQueriesInterfaceManager {
return {
queryTitle: query.queryName,
queryFile: queryFile,
queryPath: query.queryFilePath,
queryTextTmpFile: query.queryTextTmpFile,
totalRepositoryCount: query.repositories.length,
affectedRepositoryCount: affectedRepositories.length,
totalResultCount: totalResultCount,
Expand Down Expand Up @@ -129,6 +132,11 @@ export class RemoteQueriesInterfaceManager {
});
}

public async openFile(filePath: string) {
const textDocument = await workspace.openTextDocument(filePath);
await Window.showTextDocument(textDocument, ViewColumn.One);
}

private async handleMsgFromView(
msg: FromRemoteQueriesMessage
): Promise<void> {
Expand All @@ -143,6 +151,9 @@ export class RemoteQueriesInterfaceManager {
`Remote query error: ${msg.error}`
);
break;
case 'openFile':
await this.openFile(msg.filePath);
break;
default:
assertNever(msg);
}
Expand Down
1 change: 1 addition & 0 deletions extensions/ql-vscode/src/remote-queries/remote-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Repository } from './repository';
export interface RemoteQuery {
queryName: string;
queryFilePath: string;
queryTextTmpFile: string;
controllerRepository: Repository;
repositories: Repository[];
executionStartTime: Date;
Expand Down
4 changes: 4 additions & 0 deletions extensions/ql-vscode/src/remote-queries/run-remote-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,9 +583,13 @@ function buildRemoteQueryEntity(
return { owner: owner, name: repo };
});

// TODO: Get query text from query file and save it in a temporary .ql file.
const queryTextTmpFile = '';

return {
queryName,
queryFilePath,
queryTextTmpFile,
controllerRepository: {
owner: controllerRepoOwner,
name: controllerRepoName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export interface RemoteQueryResult {
queryTitle: string;
queryFile: string;
queryPath: string;
queryTextTmpFile: string;
totalRepositoryCount: number;
affectedRepositoryCount: number;
totalResultCount: number;
Expand Down
29 changes: 27 additions & 2 deletions extensions/ql-vscode/src/remote-queries/view/RemoteQueries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { vscode } from '../../view/vscode-api';
const emptyQueryResult: RemoteQueryResult = {
queryTitle: '',
queryFile: '',
queryPath: '',
queryTextTmpFile: '',
totalRepositoryCount: 0,
affectedRepositoryCount: 0,
totalResultCount: 0,
Expand All @@ -36,6 +38,13 @@ const AnalysisResultItem = (props: AnalysisResult) => (
</span>
);

function openFile(filePath: string): void {
vscode.postMessage({
t: 'openFile',
filePath
});
}

export function RemoteQueries(): JSX.Element {
const [queryResult, setQueryResult] = useState<RemoteQueryResult>(emptyQueryResult);

Expand All @@ -59,6 +68,14 @@ export function RemoteQueries(): JSX.Element {
}

try {
const openQueryFile = () => {
openFile(queryResult.queryPath);
};

const openQueryTextTmpFile = () => {
openFile(queryResult.queryTextTmpFile);
};

return <div className="vscode-codeql__remote-queries-view">
<h1 className="vscode-codeql__query-title">{queryResult.queryTitle}</h1>

Expand All @@ -67,8 +84,16 @@ export function RemoteQueries(): JSX.Element {
({queryResult.executionDuration}), {queryResult.executionTimestamp}
</p>
<p className="vscode-codeql__paragraph">
<span className="vscode-codeql__query-file">{octicons.file} <span>{queryResult.queryFile}</span></span>
<span>{octicons.codeSquare} <span>query</span></span>
<span className="vscode-codeql__query-file">{octicons.file}
<a className="vscode-codeql__query-file-link" href="#" onClick={openQueryFile}>
{queryResult.queryFile}
</a>
</span>
<span>{octicons.codeSquare}
<a className="vscode-codeql__query-file-link" href="#" onClick={openQueryTextTmpFile}>
query
</a>
</span>
</p>

<div className="vscode-codeql__query-summary-container">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
padding-right: 1em;
}

.vscode-codeql__query-file-link {
text-decoration: none;
padding-left: 0.3em;
}

.vscode-codeql__query-summary-container {
padding-top: 1.5em;
}
Expand Down

0 comments on commit f581df3

Please sign in to comment.