-
Notifications
You must be signed in to change notification settings - Fork 228
Remote queries: Open query file/text from webview #1041
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e93f7d9
b0df9b1
7e21be0
4d97015
dd7a59c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ import { | |
| window as Window, | ||
| ViewColumn, | ||
| Uri, | ||
| workspace, | ||
| } from 'vscode'; | ||
| import * as path from 'path'; | ||
|
|
||
|
|
@@ -19,6 +20,9 @@ import { AnalysisResult, RemoteQueryResult } from './remote-query-result'; | |
| import { RemoteQuery } from './remote-query'; | ||
| import { RemoteQueryResult as RemoteQueryResultViewModel } from './shared/remote-query-result'; | ||
| import { AnalysisResult as AnalysisResultViewModel } from './shared/remote-query-result'; | ||
| import { showAndLogWarningMessage } from '../helpers'; | ||
| import { URLSearchParams } from 'url'; | ||
| import { SHOW_QUERY_TEXT_MSG } from '../query-history'; | ||
|
|
||
| export class RemoteQueriesInterfaceManager { | ||
| private panel: WebviewPanel | undefined; | ||
|
|
@@ -53,15 +57,17 @@ export class RemoteQueriesInterfaceManager { | |
| * @returns A fully created view model. | ||
| */ | ||
| private buildViewModel(query: RemoteQuery, queryResult: RemoteQueryResult): RemoteQueryResultViewModel { | ||
| const queryFile = path.basename(query.queryFilePath); | ||
| const queryFileName = path.basename(query.queryFilePath); | ||
| const totalResultCount = queryResult.analysisResults.reduce((acc, cur) => acc + cur.resultCount, 0); | ||
| const executionDuration = this.getDuration(queryResult.executionEndTime, query.executionStartTime); | ||
| const analysisResults = this.buildAnalysisResults(queryResult.analysisResults); | ||
| const affectedRepositories = queryResult.analysisResults.filter(r => r.resultCount > 0); | ||
|
|
||
| return { | ||
| queryTitle: query.queryName, | ||
| queryFile: queryFile, | ||
| queryFileName: queryFileName, | ||
| queryFilePath: query.queryFilePath, | ||
| queryText: query.queryText, | ||
| totalRepositoryCount: query.repositories.length, | ||
| affectedRepositoryCount: affectedRepositories.length, | ||
| totalResultCount: totalResultCount, | ||
|
|
@@ -129,6 +135,31 @@ export class RemoteQueriesInterfaceManager { | |
| }); | ||
| } | ||
|
|
||
| private async openFile(filePath: string) { | ||
| try { | ||
| const textDocument = await workspace.openTextDocument(filePath); | ||
| await Window.showTextDocument(textDocument, ViewColumn.One); | ||
| } catch (error) { | ||
| void showAndLogWarningMessage(`Could not open file: ${filePath}`); | ||
| } | ||
| } | ||
|
|
||
| private async openVirtualFile(text: string) { | ||
| try { | ||
| const params = new URLSearchParams({ | ||
| queryText: encodeURIComponent(SHOW_QUERY_TEXT_MSG + text) | ||
| }); | ||
| const uri = Uri.parse( | ||
| `remote-query:query-text.ql?${params.toString()}`, | ||
| true | ||
| ); | ||
| const doc = await workspace.openTextDocument(uri); | ||
| await Window.showTextDocument(doc, { preview: false }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this read-only? It's possible to make happen, but I forget how.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, it's read-only! That's what the |
||
| } catch (error) { | ||
| void showAndLogWarningMessage('Could not open query text'); | ||
| } | ||
| } | ||
|
|
||
| private async handleMsgFromView( | ||
| msg: FromRemoteQueriesMessage | ||
| ): Promise<void> { | ||
|
|
@@ -143,6 +174,12 @@ export class RemoteQueriesInterfaceManager { | |
| `Remote query error: ${msg.error}` | ||
| ); | ||
| break; | ||
| case 'openFile': | ||
| await this.openFile(msg.filePath); | ||
| break; | ||
| case 'openVirtualFile': | ||
| await this.openVirtualFile(msg.queryText); | ||
| break; | ||
| default: | ||
| assertNever(msg); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eventually, it would be nice to do something like #1037, but that can happen later. Once #1037 gets in, we can work on extracting the behaviour so it is used wherever we are opening editors.