Skip to content

Commit bfa2383

Browse files
committed
fix: remove isCaretInDerivedTableStmt and set default isAccessible to null
1 parent 1f451e9 commit bfa2383

File tree

1 file changed

+6
-31
lines changed

1 file changed

+6
-31
lines changed

src/parser/common/entityCollector.ts

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ export interface BaseEntityContext {
100100
readonly belongStmt: StmtContext;
101101
/** Reference to another entity or string */
102102
reference?: string | EntityContext;
103-
/** Whether the entity is accessible from the caret position */
104-
isAccessible: boolean;
103+
/** Whether the entity is accessible from the caret position, **ONLY** applicable to table entity */
104+
isAccessible: boolean | null;
105105
/** Entities related to this entity */
106106
relatedEntities: EntityContext[] | null;
107107
/** Comment attribute for this entity */
@@ -409,30 +409,6 @@ export abstract class EntityCollector {
409409
this._entityStack.clear();
410410
}
411411

412-
/**
413-
* Determines if the caret is inside a derived table subquery
414-
* For example, in: SELECT id FROM t1, (SELECT name from t2) as t3
415-
* Checks if the caret is inside the subquery (SELECT name from t2)
416-
* @returns Whether the caret is inside a derived table subquery
417-
*/
418-
protected isCaretInDerivedTableStmt(): boolean {
419-
if (!this._caretStmt) {
420-
return false;
421-
}
422-
423-
// Check all entities to find a derived table entity containing the subquery where the caret is located
424-
return this.getEntities().some(
425-
(entity) =>
426-
entity.entityContextType === EntityContextType.TABLE &&
427-
entity.belongStmt.isContainCaret &&
428-
entity.relatedEntities?.some(
429-
(relatedEntity) =>
430-
relatedEntity.entityContextType === EntityContextType.QUERY_RESULT &&
431-
relatedEntity.belongStmt === this._caretStmt
432-
)
433-
);
434-
}
435-
436412
/**
437413
* Adds accessibility markers to entities
438414
* @param entities The list of entities to process
@@ -449,13 +425,12 @@ export abstract class EntityCollector {
449425

450426
const entityScopeDepth = entity.belongStmt.scopeDepth ?? 0;
451427

452-
// First, the entity must be in a statement containing the caret to potentially be accessible
453-
entity.isAccessible = entity.belongStmt.isContainCaret ?? false;
454-
455-
// For table-type entities, we need to judge accessibility based on scope depth
456428
if (entity.entityContextType === EntityContextType.TABLE) {
457429
entity.isAccessible =
458-
entity.isAccessible && entityScopeDepth === this._caretStmtScopeDepth;
430+
!!entity.belongStmt.isContainCaret &&
431+
entityScopeDepth === this._caretStmtScopeDepth;
432+
} else {
433+
entity.isAccessible = null;
459434
}
460435

461436
// Recursively process related entities

0 commit comments

Comments
 (0)