|
1 |
| -import { |
2 |
| - Direction, |
3 |
| - Position, |
4 |
| - TextDocument, |
5 |
| - TextEditor, |
6 |
| - showError, |
7 |
| -} from "@cursorless/common"; |
| 1 | +import { Direction, Position, TextEditor, showError } from "@cursorless/common"; |
8 | 2 | import { uniqWith } from "lodash";
|
9 | 3 | import { TreeSitterQuery } from "../../../../languages/TreeSitterQuery";
|
10 | 4 | import { QueryMatch } from "../../../../languages/TreeSitterQuery/QueryCapture";
|
11 | 5 | import BaseScopeHandler from "../BaseScopeHandler";
|
12 | 6 | import { compareTargetScopes } from "../compareTargetScopes";
|
13 | 7 | import { TargetScope } from "../scope.types";
|
14 |
| -import { |
15 |
| - ContainmentPolicy, |
16 |
| - ScopeIteratorRequirements, |
17 |
| -} from "../scopeHandler.types"; |
| 8 | +import { ScopeIteratorRequirements } from "../scopeHandler.types"; |
18 | 9 | import { mergeAdjacentBy } from "./mergeAdjacentBy";
|
19 | 10 | import { ide } from "../../../../singletons/ide.singleton";
|
20 | 11 |
|
@@ -105,87 +96,3 @@ export abstract class BaseTreeSitterScopeHandler extends BaseScopeHandler {
|
105 | 96 | export interface ExtendedTargetScope extends TargetScope {
|
106 | 97 | allowMultiple: boolean;
|
107 | 98 | }
|
108 |
| - |
109 |
| -/** |
110 |
| - * Constructs a range to pass to {@link Query.matches} to find scopes. Note |
111 |
| - * that {@link Query.matches} will only return scopes that have non-empty |
112 |
| - * intersection with this range. Also note that the base |
113 |
| - * {@link BaseScopeHandler.generateScopes} will filter out any extra scopes |
114 |
| - * that we yield, so we don't need to be totally precise. |
115 |
| - * |
116 |
| - * @returns Range to pass to {@link Query.matches} |
117 |
| - */ |
118 |
| -function getQuerySearchRange( |
119 |
| - document: TextDocument, |
120 |
| - position: Position, |
121 |
| - direction: Direction, |
122 |
| - { |
123 |
| - containment, |
124 |
| - distalPosition, |
125 |
| - allowAdjacentScopes, |
126 |
| - }: ScopeIteratorRequirements, |
127 |
| -) { |
128 |
| - const { start, end } = getQuerySearchRangeCore( |
129 |
| - document.offsetAt(position), |
130 |
| - document.offsetAt(distalPosition), |
131 |
| - direction, |
132 |
| - containment, |
133 |
| - allowAdjacentScopes, |
134 |
| - ); |
135 |
| - |
136 |
| - return { |
137 |
| - start: document.positionAt(start), |
138 |
| - end: document.positionAt(end), |
139 |
| - }; |
140 |
| -} |
141 |
| - |
142 |
| -/** Helper function for {@link getQuerySearchRange} */ |
143 |
| -function getQuerySearchRangeCore( |
144 |
| - offset: number, |
145 |
| - distalOffset: number, |
146 |
| - direction: Direction, |
147 |
| - containment: ContainmentPolicy | null, |
148 |
| - allowAdjacentScopes: boolean, |
149 |
| -) { |
150 |
| - /** |
151 |
| - * If we allow adjacent scopes, we need to shift some of our offsets by one |
152 |
| - * character |
153 |
| - */ |
154 |
| - const adjacentShift = allowAdjacentScopes ? 1 : 0; |
155 |
| - |
156 |
| - if (containment === "required") { |
157 |
| - // If containment is required, we smear the position left and right by one |
158 |
| - // character so that we have a non-empty intersection with any scope that |
159 |
| - // touches position. Note that we can skip shifting the initial position |
160 |
| - // if we disallow adjacent scopes. |
161 |
| - return direction === "forward" |
162 |
| - ? { |
163 |
| - start: offset - adjacentShift, |
164 |
| - end: offset + 1, |
165 |
| - } |
166 |
| - : { |
167 |
| - start: offset - 1, |
168 |
| - end: offset + adjacentShift, |
169 |
| - }; |
170 |
| - } |
171 |
| - |
172 |
| - // If containment is disallowed, we can shift the position forward by a |
173 |
| - // character to avoid matching scopes that touch position. Otherwise, we |
174 |
| - // shift the position backward by a character to ensure we get scopes that |
175 |
| - // touch position, if we allow adjacent scopes. |
176 |
| - const proximalShift = containment === "disallowed" ? 1 : -adjacentShift; |
177 |
| - |
178 |
| - // FIXME: Don't go all the way to end of document when there is no |
179 |
| - // distalPosition? Seems wasteful to query all the way to end of document for |
180 |
| - // something like "next funk" Might be better to start smaller and |
181 |
| - // exponentially grow |
182 |
| - return direction === "forward" |
183 |
| - ? { |
184 |
| - start: offset + proximalShift, |
185 |
| - end: distalOffset + adjacentShift, |
186 |
| - } |
187 |
| - : { |
188 |
| - start: distalOffset - adjacentShift, |
189 |
| - end: offset - proximalShift, |
190 |
| - }; |
191 |
| -} |
0 commit comments