@@ -35,7 +35,6 @@ export interface StmtContext {
3535 readonly parentStmt : StmtContext | null ;
3636 readonly isContainCaret ?: boolean ;
3737 readonly scopeDepth : number ;
38- readonly _ctx : ParserRuleContext ;
3938 readonly text : string ;
4039}
4140
@@ -58,7 +57,6 @@ export function toStmtContext(
5857 isContainCaret,
5958 text : stmtText ,
6059 scopeDepth : type === StmtContextType . COMMON_STMT ? 0 : ( parentStmt ?. scopeDepth ?? 0 ) + 1 ,
61- _ctx : ctx ,
6260 } ;
6361}
6462
@@ -106,8 +104,6 @@ export interface BaseEntityContext {
106104 isAccessible : boolean ;
107105 /** Entities related to this entity */
108106 relatedEntities : EntityContext [ ] | null ;
109- /** The parser rule context for this entity, it will be deleted after the entity is collected because of json serialization */
110- _ctx ?: ParserRuleContext ;
111107 /** Comment attribute for this entity */
112108 [ AttrName . comment ] : WordRange | null ;
113109 /** Alias attribute for this entity */
@@ -225,7 +221,6 @@ export function toEntityContext(
225221 position,
226222 belongStmt,
227223 declareType : metaInfo ?. declareType ,
228- _ctx : ctx ,
229224 [ AttrName . comment ] : null ,
230225 } ;
231226 switch ( entityInfo . entityContextType ) {
@@ -328,10 +323,10 @@ function findAttributeChildren(
328323 * @returns true if entity is contained within rangeEntity's range
329324 */
330325function isEntityInScope ( entity : EntityContext , rangeEntity : EntityContext ) : boolean {
331- const entityStart = entity . _ctx ?. start ?. tokenIndex ;
332- const entityStop = entity . _ctx ?. stop ?. tokenIndex ;
333- const rangeStart = rangeEntity . _ctx ?. start ?. tokenIndex ;
334- const rangeStop = rangeEntity . _ctx ?. stop ?. tokenIndex ;
326+ const entityStart = entity . position . startTokenIndex ;
327+ const entityStop = entity . position . endTokenIndex ;
328+ const rangeStart = rangeEntity . position . startTokenIndex ;
329+ const rangeStop = rangeEntity . position . endTokenIndex ;
335330
336331 return (
337332 entityStart != null &&
@@ -408,55 +403,12 @@ export abstract class EntityCollector {
408403
409404 exitProgram ( ) {
410405 const entities = Array . from ( this . _entitiesSet ) ;
411- this . removeCtxAttr ( ) ;
412406 if ( this . _caretTokenIndex !== - 1 ) {
413407 this . attachAccessibleToEntities ( entities ) ;
414408 }
415409 this . _entityStack . clear ( ) ;
416410 }
417411
418- /**
419- * Remove _ctx property to avoid circular references during JSON serialization
420- */
421- private removeCtxAttr ( ) {
422- const entities = Array . from ( this . _entitiesSet ) ;
423- // Use WeakSet to track processed objects and avoid infinite recursion from circular references
424- const processed = new WeakSet ( ) ;
425-
426- const removeCtx = ( obj : any ) => {
427- if ( ! obj || typeof obj !== 'object' || processed . has ( obj ) ) {
428- return ;
429- }
430- processed . add ( obj ) ;
431-
432- if ( '_ctx' in obj ) {
433- obj . _ctx = undefined ;
434- }
435-
436- if ( obj . belongStmt ) {
437- removeCtx ( obj . belongStmt ) ;
438- }
439-
440- if ( obj . rootStmt ) {
441- removeCtx ( obj . rootStmt ) ;
442- }
443-
444- if ( obj . parentStmt ) {
445- removeCtx ( obj . parentStmt ) ;
446- }
447-
448- if ( obj . relatedEntities && Array . isArray ( obj . relatedEntities ) ) {
449- obj . relatedEntities . forEach ( removeCtx ) ;
450- }
451-
452- if ( obj . columns && Array . isArray ( obj . columns ) ) {
453- obj . columns . forEach ( removeCtx ) ;
454- }
455- } ;
456-
457- entities . forEach ( removeCtx ) ;
458- }
459-
460412 /**
461413 * Determines if the caret is inside a derived table subquery
462414 * For example, in: SELECT id FROM t1, (SELECT name from t2) as t3
0 commit comments