@@ -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-
166163function createTmpFile ( yaml ) : string {
167164 const tempDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'jsonnet-eval' ) ) ;
168165 const fileEnding = yaml ? 'yaml' : 'json' ;
0 commit comments