@@ -59,24 +59,45 @@ export class TreeSitterScopeHandler extends BaseScopeHandler {
59
59
}
60
60
61
61
private matchToScope ( editor : TextEditor , match : QueryMatch ) : TargetScope {
62
+ const scopeTypeType = this . scopeType . type ;
63
+
62
64
const contentRange = getNodeRange (
63
- match . captures . find ( ( capture ) => capture . name === this . scopeType . type ) !
64
- . node ,
65
+ match . captures . find ( ( capture ) => capture . name === scopeTypeType ) ! . node ,
66
+ ) ;
67
+
68
+ const domain =
69
+ getRelatedRange ( match , scopeTypeType , "domain" ) ?? contentRange ;
70
+
71
+ const removalRange = getRelatedRange ( match , scopeTypeType , "removal" ) ;
72
+
73
+ const leadingDelimiterRange = getRelatedRange (
74
+ match ,
75
+ scopeTypeType ,
76
+ "leading" ,
77
+ ) ;
78
+
79
+ const trailingDelimiterRange = getRelatedRange (
80
+ match ,
81
+ scopeTypeType ,
82
+ "trailing" ,
65
83
) ;
66
84
85
+ const interiorRange = getRelatedRange ( match , scopeTypeType , "interior" ) ;
86
+
67
87
return {
68
88
editor,
69
- // FIXME: Actually get domain
70
- domain : contentRange ,
89
+ domain,
71
90
getTarget : ( isReversed ) =>
72
91
new ScopeTypeTarget ( {
73
- scopeTypeType : this . scopeType . type ,
92
+ scopeTypeType,
74
93
editor,
75
94
isReversed,
76
95
contentRange,
77
- // FIXME: Actually get removalRange
78
- removalRange : contentRange ,
79
- // FIXME: Other fields here
96
+ removalRange,
97
+ leadingDelimiterRange,
98
+ trailingDelimiterRange,
99
+ interiorRange,
100
+ // FIXME: Add delimiter text
80
101
} ) ,
81
102
} ;
82
103
}
@@ -136,6 +157,29 @@ function getQueryRange(
136
157
} ;
137
158
}
138
159
160
+ /**
161
+ * Gets the range of a node that is related to the scope. For example, if the
162
+ * scope is "class name", the `domain` node would be the containing class.
163
+ *
164
+ * @param match The match to get the range from
165
+ * @param scopeTypeType The type of the scope
166
+ * @param relationship The relationship to get the range for, eg "domain", or "removal"
167
+ * @returns A range or undefined if no range was found
168
+ */
169
+ function getRelatedRange (
170
+ match : QueryMatch ,
171
+ scopeTypeType : string ,
172
+ relationship : string ,
173
+ ) {
174
+ const relatedNode = match . captures . find (
175
+ ( capture ) =>
176
+ capture . name === `${ scopeTypeType } .${ relationship } ` ||
177
+ capture . name === relationship ,
178
+ ) ?. node ;
179
+
180
+ return relatedNode == null ? undefined : getNodeRange ( relatedNode ) ;
181
+ }
182
+
139
183
function positionToPoint ( start : Position ) : Point | undefined {
140
184
return { row : start . line , column : start . character } ;
141
185
}
0 commit comments