@@ -10,29 +10,37 @@ import { SystemVariableProvider } from './httpVariableProviders/systemVariablePr
1010
1111export class VariableProcessor {
1212
13- private static readonly providers : HttpVariableProvider [ ] = [
14- SystemVariableProvider . Instance ,
15- RequestVariableProvider . Instance ,
16- FileVariableProvider . Instance ,
17- EnvironmentVariableProvider . Instance ,
13+ private static readonly providers : [ HttpVariableProvider , boolean ] [ ] = [
14+ [ SystemVariableProvider . Instance , false ] ,
15+ [ RequestVariableProvider . Instance , true ] ,
16+ [ FileVariableProvider . Instance , true ] ,
17+ [ EnvironmentVariableProvider . Instance , true ] ,
1818 ] ;
1919
2020 public static async processRawRequest ( request : string ) {
2121 const variableReferenceRegex = / \{ { 2 } ( .+ ?) \} { 2 } / g;
2222 let result = '' ;
2323 let match : RegExpExecArray ;
2424 let lastIndex = 0 ;
25+ const resolvedVariables = new Map < string , string > ( ) ;
2526 variable:
2627 while ( match = variableReferenceRegex . exec ( request ) ) {
2728 result += request . substring ( lastIndex , match . index ) ;
2829 lastIndex = variableReferenceRegex . lastIndex ;
2930 const name = match [ 1 ] . trim ( ) ;
3031 const document = window . activeTextEditor . document ;
3132 const context = { rawRequest : request , parsedRequest : result } ;
32- for ( const provider of VariableProcessor . providers ) {
33+ for ( const [ provider , cacheable ] of VariableProcessor . providers ) {
34+ if ( resolvedVariables . has ( name ) ) {
35+ result += resolvedVariables . get ( name ) ;
36+ continue variable;
37+ }
3338 if ( await provider . has ( document , name , context ) ) {
3439 const { value, error, warning } = await provider . get ( document , name , context ) ;
3540 if ( ! error && ! warning ) {
41+ if ( cacheable ) {
42+ resolvedVariables . set ( name , value as string ) ;
43+ }
3644 result += value ;
3745 continue variable;
3846 } else {
@@ -48,7 +56,7 @@ export class VariableProcessor {
4856 }
4957
5058 public static async getAllVariablesDefinitions ( document : TextDocument ) : Promise < Map < string , VariableType [ ] > > {
51- const [ , requestProvider , fileProvider , environmentProvider ] = VariableProcessor . providers ;
59+ const [ , [ requestProvider ] , [ fileProvider ] , [ environmentProvider ] ] = VariableProcessor . providers ;
5260 const requestVariables = await ( requestProvider as RequestVariableProvider ) . getAll ( document ) ;
5361 const fileVariables = await ( fileProvider as FileVariableProvider ) . getAll ( document ) ;
5462 const environmentVariables = await ( environmentProvider as EnvironmentVariableProvider ) . getAll ( document ) ;
0 commit comments