Skip to content

Commit 789bb24

Browse files
Fix evalExpression
Prompt doesn't go anywhere since 0.7.1
1 parent 7e4d3f4 commit 789bb24

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"description": "Full code support (formatting, highlighting, navigation, debugging etc) for Jsonnet",
66
"license": "Apache License Version 2.0",
77
"publisher": "Grafana",
8-
"version": "0.7.1",
8+
"version": "0.7.2",
99
"repository": {
1010
"type": "git",
1111
"url": "https://github.com/grafana/vscode-jsonnet"

src/extension.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,22 @@ export async function activate(context: ExtensionContext): Promise<void> {
9595
}),
9696
commands.registerCommand('jsonnet.evalFile', evalCommand(false)),
9797
commands.registerCommand('jsonnet.evalFileYaml', evalCommand(true)),
98-
commands.registerCommand('jsonnet.evalExpression', evalExpressionCommand(false)),
99-
commands.registerCommand('jsonnet.evalExpressionYaml', evalExpressionCommand(true))
98+
commands.registerCommand('jsonnet.evalExpression', evalCommand(false, true)),
99+
commands.registerCommand('jsonnet.evalExpressionYaml', evalCommand(true, true))
100100
);
101101
}
102102

103-
function evalCommand(yaml: boolean, expr = '') {
103+
function evalCommand(yaml: boolean, promptExpr = false) {
104104
return async () => {
105+
let expr = '';
106+
if (promptExpr) {
107+
expr = await window.showInputBox({ prompt: 'Expression to evaluate' });
108+
if (expr === undefined || expr === '') {
109+
window.showErrorMessage('No expression provided');
110+
return;
111+
}
112+
}
113+
105114
const currentFilePath = evalFilePath(window.activeTextEditor);
106115
const params: ExecuteCommandParams = {
107116
command: expr === '' ? `jsonnet.evalFile` : `jsonnet.evalExpression`,
@@ -151,18 +160,6 @@ function evalCommand(yaml: boolean, expr = '') {
151160
};
152161
}
153162

154-
function evalExpressionCommand(yaml: boolean) {
155-
return async () => {
156-
window.showInputBox({ prompt: 'Expression to evaluate' }).then(async (expr) => {
157-
if (expr) {
158-
evalCommand(yaml, expr);
159-
} else {
160-
window.showErrorMessage('No expression provided');
161-
}
162-
});
163-
};
164-
}
165-
166163
function createTmpFile(yaml): string {
167164
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'jsonnet-eval'));
168165
const fileEnding = yaml ? 'yaml' : 'json';

0 commit comments

Comments
 (0)