Skip to content

Commit

Permalink
Changed Query Display to Split Pane, query box now remembers last com…
Browse files Browse the repository at this point in the history
…mand
  • Loading branch information
Avin M committed May 27, 2018
1 parent 3b2247f commit f060da0
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@
"mac": "cmd+shift+j",
"when": "editorTextFocus && editorLangId == 'json'"
}],
"menus": {
"commandPalette": [
{
"command": "jmespath.query",
"when": "editorLangId == json"
}
]
},
"configuration": {
"title": "",
"properties": {
Expand Down
4 changes: 3 additions & 1 deletion src/command/jmespathQueryCommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default class JMESPathQueryCommandHandler {

private extensionContext: vscode.ExtensionContext;
private queryInputUi: QueryInput;
private defaultExpression: string = "*";
private queryService: JMESPathQueryService;
private resultViewer: ResultViewer;
private timeoutId: number;
Expand Down Expand Up @@ -39,7 +40,8 @@ export default class JMESPathQueryCommandHandler {
}

try {
let expression = await this.queryInputUi.presentInputBox(Strings.UI_QUERY_PROMPT, Strings.UI_QUERY_PROMPT_PLACEHOLDER);
let expression = await this.queryInputUi.presentInputBox(Strings.UI_QUERY_PROMPT, Strings.UI_QUERY_PROMPT_PLACEHOLDER, this.defaultExpression);
this.defaultExpression = expression;
if (expression === undefined) {
return Promise.resolve();
}
Expand Down
35 changes: 28 additions & 7 deletions src/ui/outputChannelResultViewer.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,46 @@
"use strict";

import * as vscode from "vscode";
import { Uri, ViewColumn, Selection, Position } from "vscode";
import * as fs from "fs";
import * as os from "os";
import * as path from "path";
import { ResultViewer } from "./resultViewer";
import JMESPathQueryCommandHandler from "./../command/jmespathQueryCommandHandler";

export default class OutputChannelResultViewer implements ResultViewer {
private outputChannel: vscode.OutputChannel;
private indentString: string;
private resultsFilePath: string;
private resultsDoc: vscode.TextDocument;

constructor(channelName: string, indent: string = " ") {
this.outputChannel = vscode.window.createOutputChannel(channelName);
this.indentString = indent;
this.outputChannel.show();
this.resultsFilePath = path.join(os.tmpdir(), "Query Results.json");
}

public viewResult(queryResult: any) {
this.outputChannel.clear();
this.outputChannel.appendLine(JSON.stringify(queryResult, null, this.indentString));
this.outputChannel.show();
fs.writeFileSync(this.resultsFilePath, "");
const resultsFileUri = Uri.file(this.resultsFilePath);
const resultsFileUri2 = Uri.file(path.join(os.tmpdir(), "Query Results2.json"));
if (this.resultsDoc)
this.resultsDoc.save();
fs.writeFileSync(this.resultsFilePath, JSON.stringify(queryResult, null, this.indentString));
vscode.workspace.openTextDocument(resultsFileUri).then(doc => {
this.resultsDoc = doc;
vscode.window.showTextDocument(doc, getViewColumn(), true);
}
);
}

public dispose() {
this.outputChannel.dispose();
fs.unlink(this.resultsFilePath);
}
}

function getViewColumn(): ViewColumn {
const activeEditor = vscode.window.activeTextEditor;
if (!activeEditor) {
return ViewColumn.One;
}
return activeEditor.viewColumn + 1;
}
3 changes: 2 additions & 1 deletion src/ui/queryInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ export default class QueryInput {
* @param placeholder An optional string to show as place holder in the input box to guide the user what to type.
* @return A string representing the user-entered expression
*/
public async presentInputBox(prompt: string, placeholder?: string): Promise<string> {
public async presentInputBox(prompt: string, placeholder?: string, defaultVal?: string): Promise<string> {
return vscode.window.showInputBox({
prompt: prompt,
placeHolder: placeholder,
value: defaultVal,
validateInput: (expr) => { return this.validateExpression(expr); }
});
}
Expand Down

0 comments on commit f060da0

Please sign in to comment.