1515import org .rumbledb .expressions .Expression ;
1616import org .rumbledb .expressions .Node ;
1717import org .rumbledb .expressions .module .MainModule ;
18+ import org .rumbledb .expressions .postfix .ObjectLookupExpression ;
1819
1920public final class TypeAtPosition implements RequestHandler {
2021 public static final String REQUEST_TYPE = "type-at-position" ;
@@ -78,6 +79,11 @@ public Result findType(String query, URI documentUri, Position position) {
7879 }
7980
8081 private static Expression findExpression (Node root , Position position ) {
82+ Candidate objectLookupKeyCandidate = findBestObjectLookupKeyCandidate (root , position , null );
83+ if (objectLookupKeyCandidate != null ) {
84+ return objectLookupKeyCandidate .expression ();
85+ }
86+
8187 Candidate bestEnding = findBestCandidate (root , position , true , null );
8288 if (bestEnding != null ) {
8389 return bestEnding .expression ();
@@ -87,6 +93,30 @@ private static Expression findExpression(Node root, Position position) {
8793 return bestContaining == null ? null : bestContaining .expression ();
8894 }
8995
96+ private static Candidate findBestObjectLookupKeyCandidate (Node node , Position position , Candidate best ) {
97+ if (node == null ) {
98+ return best ;
99+ }
100+
101+ if (node instanceof ObjectLookupExpression objectLookupExpression ) {
102+ Expression lookupExpression = objectLookupExpression .getLookupExpression ();
103+ Candidate lookupCandidate = lookupExpression == null ? null : Candidate .create (lookupExpression );
104+ Candidate objectLookupCandidate = Candidate .create (objectLookupExpression );
105+ boolean positionIsInsideLookupKey = lookupCandidate != null
106+ && objectLookupCandidate != null
107+ && lookupCandidate .matches (position , false );
108+
109+ if (positionIsInsideLookupKey ) {
110+ best = Candidate .prefer (best , objectLookupCandidate , false );
111+ }
112+ }
113+
114+ for (Node child : node .getChildren ()) {
115+ best = findBestObjectLookupKeyCandidate (child , position , best );
116+ }
117+ return best ;
118+ }
119+
90120 private static Candidate findBestCandidate (
91121 Node node ,
92122 Position position ,
0 commit comments