@@ -107,10 +107,16 @@ export interface EvaluatedVariable {
107
107
range : SourceRange ;
108
108
}
109
109
110
+ export enum DefinitionKind {
111
+ Target ,
112
+ Variable ,
113
+ }
114
+
110
115
export interface VariableDefinition {
111
116
id : number ;
112
117
range : SourceRange ;
113
118
name : string ;
119
+ kind : DefinitionKind ;
114
120
}
115
121
116
122
export interface VariableReference {
@@ -769,13 +775,14 @@ class ScopeStack {
769
775
return this . stack [ this . stack . length - 1 ] ;
770
776
}
771
777
772
- createVariableDefinition ( range : SourceRange , name : string ) : VariableDefinition {
778
+ createVariableDefinition ( range : SourceRange , name : string , kind : DefinitionKind ) : VariableDefinition {
773
779
const id = this . nextVariableDefinitionId ;
774
780
this . nextVariableDefinitionId += 1 ;
775
781
return {
776
782
id,
777
783
range,
778
784
name,
785
+ kind,
779
786
} ;
780
787
}
781
788
}
@@ -810,26 +817,30 @@ interface EvaluationContext {
810
817
function createDefaultScopeStack ( rootFbuildDirUri : vscodeUri . URI ) : ScopeStack {
811
818
const scopeStack = new ScopeStack ( ) ;
812
819
813
- const dummyVariableDefinition : VariableDefinition = {
814
- id : - 1 ,
815
- range : {
816
- uri : '' ,
817
- start : {
818
- line : - 1 ,
819
- character : - 1
820
+ const createNoLocationVariableDefinition = ( name : string ) => {
821
+ const definition : VariableDefinition = {
822
+ id : - 1 ,
823
+ range : {
824
+ uri : '' ,
825
+ start : {
826
+ line : - 1 ,
827
+ character : - 1
828
+ } ,
829
+ end : {
830
+ line : - 1 ,
831
+ character : - 1
832
+ }
820
833
} ,
821
- end : {
822
- line : - 1 ,
823
- character : - 1
824
- }
825
- } ,
826
- name : '' ,
834
+ name,
835
+ kind : DefinitionKind . Variable ,
836
+ } ;
837
+ return definition ;
827
838
} ;
828
839
829
- scopeStack . setVariableInCurrentScope ( '_WORKING_DIR_' , rootFbuildDirUri . fsPath , dummyVariableDefinition ) ;
830
- scopeStack . setVariableInCurrentScope ( '_CURRENT_BFF_DIR_' , '' , dummyVariableDefinition ) ;
831
- scopeStack . setVariableInCurrentScope ( '_FASTBUILD_VERSION_STRING_' , 'vPlaceholderFastBuildVersionString' , dummyVariableDefinition ) ;
832
- scopeStack . setVariableInCurrentScope ( '_FASTBUILD_VERSION_' , - 1 , dummyVariableDefinition ) ;
840
+ scopeStack . setVariableInCurrentScope ( '_WORKING_DIR_' , rootFbuildDirUri . fsPath , createNoLocationVariableDefinition ( '_WORKING_DIR_' ) ) ;
841
+ scopeStack . setVariableInCurrentScope ( '_CURRENT_BFF_DIR_' , '' , createNoLocationVariableDefinition ( '_CURRENT_BFF_DIR_' ) ) ;
842
+ scopeStack . setVariableInCurrentScope ( '_FASTBUILD_VERSION_STRING_' , 'vPlaceholderFastBuildVersionString' , createNoLocationVariableDefinition ( '_FASTBUILD_VERSION_STRING_' ) ) ;
843
+ scopeStack . setVariableInCurrentScope ( '_FASTBUILD_VERSION_' , - 1 , createNoLocationVariableDefinition ( '_FASTBUILD_VERSION_' ) ) ;
833
844
834
845
return scopeStack ;
835
846
}
@@ -897,7 +908,7 @@ function evaluateStatements(statements: Statement[], context: EvaluationContext)
897
908
existingValue = existingVariable . value ;
898
909
}
899
910
900
- const definition = context . scopeStack . createVariableDefinition ( lhsRange , evaluatedLhsName . value ) ;
911
+ const definition = context . scopeStack . createVariableDefinition ( lhsRange , evaluatedLhsName . value , DefinitionKind . Variable ) ;
901
912
variable = context . scopeStack . setVariableInCurrentScope ( evaluatedLhsName . value , value , definition ) ;
902
913
903
914
if ( existingVariable === null ) {
@@ -969,7 +980,7 @@ function evaluateStatements(statements: Statement[], context: EvaluationContext)
969
980
&& ( maybeExistingVariableStartingFromParentScope = context . scopeStack . getVariableStartingFromCurrentScope ( evaluatedLhsName . value ) ) !== null )
970
981
{
971
982
previousValue = maybeExistingVariableStartingFromParentScope . value ;
972
- const definition = context . scopeStack . createVariableDefinition ( lhsRange , evaluatedLhsName . value ) ;
983
+ const definition = context . scopeStack . createVariableDefinition ( lhsRange , evaluatedLhsName . value , DefinitionKind . Variable ) ;
973
984
result . variableDefinitions . push ( definition ) ;
974
985
lhsVariable = context . scopeStack . setVariableInCurrentScope ( evaluatedLhsName . value , previousValue , definition ) ;
975
986
} else {
@@ -1101,7 +1112,7 @@ function evaluateStatements(statements: Statement[], context: EvaluationContext)
1101
1112
existingVariable . value = structMember . value ;
1102
1113
variableDefinition = existingVariable . definition ;
1103
1114
} else {
1104
- variableDefinition = context . scopeStack . createVariableDefinition ( statementRange , structMemberName ) ;
1115
+ variableDefinition = context . scopeStack . createVariableDefinition ( statementRange , structMemberName , DefinitionKind . Variable ) ;
1105
1116
context . scopeStack . setVariableInCurrentScope ( structMemberName , structMember . value , variableDefinition ) ;
1106
1117
result . variableDefinitions . push ( variableDefinition ) ;
1107
1118
}
@@ -1173,7 +1184,7 @@ function evaluateStatements(statements: Statement[], context: EvaluationContext)
1173
1184
}
1174
1185
const evaluatedLoopVarNameValue : string = evaluatedLoopVarName . value ;
1175
1186
1176
- const loopVarDefinition = context . scopeStack . createVariableDefinition ( loopVarRange , evaluatedLoopVarNameValue ) ;
1187
+ const loopVarDefinition = context . scopeStack . createVariableDefinition ( loopVarRange , evaluatedLoopVarNameValue , DefinitionKind . Variable ) ;
1177
1188
1178
1189
iterators . push ( {
1179
1190
arrayItems,
@@ -1231,7 +1242,7 @@ function evaluateStatements(statements: Statement[], context: EvaluationContext)
1231
1242
}
1232
1243
1233
1244
// Create a definition and reference for the target name.
1234
- const targetNameDefinition = context . scopeStack . createVariableDefinition ( evaluatedTargetNameRange , evaluatedTargetName . value ) ;
1245
+ const targetNameDefinition = context . scopeStack . createVariableDefinition ( evaluatedTargetNameRange , evaluatedTargetName . value , DefinitionKind . Target ) ;
1235
1246
const targetNameReference : VariableReference = {
1236
1247
definition : targetNameDefinition ,
1237
1248
range : evaluatedTargetNameRange ,
@@ -1442,7 +1453,7 @@ function evaluateStatements(statements: Statement[], context: EvaluationContext)
1442
1453
const symbol = statement . symbol . value ;
1443
1454
const value = `placeholder-${ symbol } -value` ;
1444
1455
const statementRange = new SourceRange ( context . thisFbuildUri , statement . range ) ;
1445
- const definition = context . scopeStack . createVariableDefinition ( statementRange , symbol ) ;
1456
+ const definition = context . scopeStack . createVariableDefinition ( statementRange , symbol , DefinitionKind . Variable ) ;
1446
1457
context . scopeStack . setVariableInCurrentScope ( symbol , value , definition ) ;
1447
1458
} else {
1448
1459
const dummyRange = SourceRange . create ( context . thisFbuildUri , 0 , 0 , 0 , 0 ) ;
@@ -1627,6 +1638,7 @@ function evaluateEvaluatedVariable(parsedEvaluatedVariable: ParsedEvaluatedVaria
1627
1638
id : 0 ,
1628
1639
range : SourceRange . create ( '' , 0 , 0 , 0 , 0 ) ,
1629
1640
name : '' ,
1641
+ kind : DefinitionKind . Variable ,
1630
1642
} ,
1631
1643
} ;
1632
1644
@@ -2129,7 +2141,7 @@ function evaluateUserFunctionDeclaration(
2129
2141
context : EvaluationContext
2130
2142
) : DataAndMaybeError < EvaluatedData > {
2131
2143
const nameSourceRange = new SourceRange ( context . thisFbuildUri , userFunction . nameRange ) ;
2132
- const functionNameDefinition = context . scopeStack . createVariableDefinition ( nameSourceRange , userFunction . name ) ;
2144
+ const functionNameDefinition = context . scopeStack . createVariableDefinition ( nameSourceRange , userFunction . name , DefinitionKind . Variable ) ;
2133
2145
const functionNameReference = {
2134
2146
definition : functionNameDefinition ,
2135
2147
range : nameSourceRange ,
@@ -2167,7 +2179,7 @@ function evaluateUserFunctionDeclaration(
2167
2179
}
2168
2180
usedParameterNames . push ( parameter . name ) ;
2169
2181
2170
- const definition = context . scopeStack . createVariableDefinition ( paramSourceRange , parameter . name ) ;
2182
+ const definition = context . scopeStack . createVariableDefinition ( paramSourceRange , parameter . name , DefinitionKind . Variable ) ;
2171
2183
parameter . definition = definition ;
2172
2184
2173
2185
result . variableDefinitions . push ( definition ) ;
0 commit comments