@@ -3,8 +3,8 @@ import { Diagnostic, DiagnosticSeverity } from "vscode-languageserver";
33import * as list from '../utils/lists'
44import { Location } from "../utils/location" ;
55import { MapIniVisitor } from "../utils/antlr4ng/MapIniVisitor" ;
6- import { Armor_valueContext , Commandbutton_valueContext , CommandSet_valueContext , CommandSetClassPropertyContext , Cursorname_valueContext , DamageFX_valueContext , DrawModule_conditionBlockContext , DrawModule_conditionStateValueContext , DrawModule_transitionKeyPropertyContext , DrawModule_transitionStateBlockContext , EndContext , Fxlist_valueContext , Locomotor_valueContext , MapIniParser , Mappedimage_valueContext , Object_valueContext , ObjectClass_drawModulesContext , ObjectClass_propertiesContext , ObjectClass_setsContext , ObjectClass_soundsContext , ObjectClassContext , Particlesystem_valueContext , ParticleSystemClassContext , ProgramContext , Science_valueContext , Specialpower_valueContext , TransitionKey_valueContext , Upgrade_valueContext } from "../utils/antlr4ng/MapIniParser" ;
7- import { AbstractParseTreeVisitor } from "antlr4ng" ;
6+ import { Armor_valueContext , Commandbutton_valueContext , CommandSet_valueContext , CommandSetClassPropertyContext , Cursorname_valueContext , DamageFX_valueContext , DrawModule_conditionBlockContext , DrawModule_conditionStatePropertiesContext , DrawModule_conditionStateValueContext , DrawModule_defaultconditionBlockContext , DrawModule_transitionKeyPropertyContext , DrawModule_transitionStateBlockContext , EndContext , Fxlist_valueContext , Locomotor_valueContext , MapIniParser , Mappedimage_valueContext , Object_valueContext , ObjectClass_drawModulesContext , ObjectClass_propertiesContext , ObjectClass_setsContext , ObjectClass_soundsContext , ObjectClassContext , Particlesystem_valueContext , ParticleSystemClassContext , ProgramContext , Science_valueContext , Specialpower_valueContext , TransitionKey_valueContext , Upgrade_valueContext , W3dDebrisDrawModuleContext , W3dDefaultDrawModuleContext , W3dDependencyDrawModuleContext , W3dLaserDrawModuleContext , W3dModelDrawModuleContext , W3dOverlordTankDrawModuleContext , W3dProjectileStreamDrawModuleContext , W3dScienceModelDrawModuleContext , W3dSupplyDrawModuleContext , W3dTreeDrawModuleContext , W3dVehicleDrawModuleContext } from "../utils/antlr4ng/MapIniParser" ;
7+ import { AbstractParseTreeVisitor , ParserRuleContext } from "antlr4ng" ;
88import { ErrorListener } from "../errorListener" ;
99import { ClassVisitor } from './classVisitor' ;
1010
@@ -14,10 +14,12 @@ export class DiagnosticVisitor extends AbstractParseTreeVisitor<void> implements
1414 }
1515
1616 diagnostics : Diagnostic [ ]
17+ precompileTransitionKeys : boolean
1718
18- constructor ( diagnostics : Diagnostic [ ] ) {
19+ constructor ( diagnostics : Diagnostic [ ] , precompileTransitionKeys : boolean ) {
1920 super ( )
2021 this . diagnostics = diagnostics
22+ this . precompileTransitionKeys = precompileTransitionKeys
2123 }
2224
2325 visitProgram ( ctx : ProgramContext ) : void {
@@ -177,11 +179,52 @@ export class DiagnosticVisitor extends AbstractParseTreeVisitor<void> implements
177179 // }
178180
179181 visitObjectClass_drawModules ( ctx : ObjectClass_drawModulesContext ) : void {
180- console . log ( list . customConditionStates )
181182 list . customConditionStates . clear ( )
183+
184+
185+ if ( this . precompileTransitionKeys ) {
186+ for ( const child of ctx . children || [ ] ) {
187+ if ( child instanceof W3dModelDrawModuleContext ||
188+ child instanceof W3dVehicleDrawModuleContext ||
189+ child instanceof W3dOverlordTankDrawModuleContext
190+ ) {
191+ this . collectTransitionKeys ( child )
192+ }
193+ }
194+ }
195+
196+
182197 this . visitChildren ( ctx )
183198 }
184199
200+ private collectTransitionKeys ( ctx : ParserRuleContext ) : void {
201+ for ( const child of ctx . children || [ ] ) {
202+ if ( child instanceof DrawModule_conditionBlockContext ) {
203+ // Recursively check condition block for TransitionKey properties
204+ this . collectTransitionKeysFromBlock ( child )
205+ } else if ( child instanceof DrawModule_defaultconditionBlockContext ) {
206+ // Check default condition block
207+ this . collectTransitionKeysFromBlock ( child )
208+ }
209+ // Recursively check other children
210+ this . collectTransitionKeys ( child as ParserRuleContext )
211+ }
212+ }
213+
214+ private collectTransitionKeysFromBlock ( ctx : ParserRuleContext ) : void {
215+ for ( const child of ctx . children || [ ] ) {
216+ if ( child instanceof DrawModule_conditionStatePropertiesContext ) {
217+ const transitionKeyProp = child . drawModule_transitionKeyProperty ?.( )
218+ if ( transitionKeyProp ?. transitionKey_value ( ) ?. ID ( ) ) {
219+ const ID_text = transitionKeyProp . transitionKey_value ( ) . ID ( ) ! . getText ( )
220+ list . customConditionStates . remove ( ID_text )
221+ list . customConditionStates . insert ( ID_text )
222+ }
223+ }
224+ // Recursively check other children
225+ this . collectTransitionKeysFromBlock ( child as ParserRuleContext )
226+ }
227+ }
185228
186229 // =====================================
187230 // =========== CLASS VALUES ============
@@ -403,6 +446,7 @@ export class DiagnosticVisitor extends AbstractParseTreeVisitor<void> implements
403446 }
404447 }
405448 }
449+
406450 this . visitChildren ( ctx )
407451 }
408452
@@ -454,7 +498,7 @@ export class DiagnosticVisitor extends AbstractParseTreeVisitor<void> implements
454498 }
455499}
456500
457- export function computeDiagnostics ( parser : MapIniParser ) : Diagnostic [ ] {
501+ export function computeDiagnostics ( parser : MapIniParser , precompileTransitionKeys : boolean ) : Diagnostic [ ] {
458502
459503 let diagnostics : Diagnostic [ ] = [ ]
460504
@@ -464,7 +508,7 @@ export function computeDiagnostics(parser: MapIniParser): Diagnostic[] {
464508 const tree = parser . program ( )
465509 // console.log(`Tree: ${tree.getText()}`)
466510
467- const vistor = new DiagnosticVisitor ( diagnostics )
511+ const vistor = new DiagnosticVisitor ( diagnostics , precompileTransitionKeys )
468512 const classVisitor = new ClassVisitor ( )
469513
470514 classVisitor . visitProgram ( tree )
0 commit comments