@@ -95,13 +95,22 @@ export async function activate(context: ExtensionContext): Promise<void> {
95
95
} ) ,
96
96
commands . registerCommand ( 'jsonnet.evalFile' , evalCommand ( false ) ) ,
97
97
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 ) )
100
100
) ;
101
101
}
102
102
103
- function evalCommand ( yaml : boolean , expr = '' ) {
103
+ function evalCommand ( yaml : boolean , promptExpr = false ) {
104
104
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
+
105
114
const currentFilePath = evalFilePath ( window . activeTextEditor ) ;
106
115
const params : ExecuteCommandParams = {
107
116
command : expr === '' ? `jsonnet.evalFile` : `jsonnet.evalExpression` ,
@@ -151,18 +160,6 @@ function evalCommand(yaml: boolean, expr = '') {
151
160
} ;
152
161
}
153
162
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
-
166
163
function createTmpFile ( yaml ) : string {
167
164
const tempDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'jsonnet-eval' ) ) ;
168
165
const fileEnding = yaml ? 'yaml' : 'json' ;
0 commit comments