Skip to content

Commit 1322270

Browse files
Merge branch 'main' into treeSitterSearchRange
2 parents de7a324 + 785a750 commit 1322270

File tree

3 files changed

+43
-10
lines changed

3 files changed

+43
-10
lines changed

cursorless-everywhere-talon/cursorless_everywhere_talon_browser.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
from talon import Context, Module, actions
22

3-
from .cursorless_everywhere_types import EditorEdit, EditorState, SelectionOffsets
3+
from .cursorless_everywhere_types import (
4+
EditorChange,
5+
EditorEdit,
6+
EditorState,
7+
SelectionOffsets,
8+
)
49

510
mod = Module()
611

@@ -43,8 +48,9 @@ def cursorless_everywhere_edit_text(
4348
edit: EditorEdit, # pyright: ignore [reportGeneralTypeIssues]
4449
):
4550
command = {
46-
"id": "setText",
51+
"id": "editText",
4752
"text": edit["text"],
53+
"changes": get_serializable_editor_changes(edit["changes"]),
4854
}
4955
res = rpc_get(command)
5056
if use_fallback(res):
@@ -71,3 +77,17 @@ def get_serializable_selections(selections: list[SelectionOffsets]):
7177
}
7278
)
7379
return result
80+
81+
82+
def get_serializable_editor_changes(changes: list[EditorChange]):
83+
result: list[EditorChange] = []
84+
for i in range(changes.length): # pyright: ignore [reportAttributeAccessIssue]
85+
change = changes[i]
86+
result.append(
87+
{
88+
"text": change["text"],
89+
"rangeOffset": change["rangeOffset"],
90+
"rangeLength": change["rangeLength"],
91+
}
92+
)
93+
return result

packages/cursorless-engine/src/languages/TreeSitterQuery/treeSitterQueryCache.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import type { Position, TextDocument } from "@cursorless/common";
22
import type { QueryMatch } from "./QueryCapture";
33

44
export class Cache {
5-
private documentUri: string = "";
65
private documentVersion: number = -1;
6+
private documentUri: string = "";
77
private documentLanguageId: string = "";
88
private startPosition: Position | undefined;
99
private endPosition: Position | undefined;
@@ -24,11 +24,11 @@ export class Cache {
2424
endPosition: Position | undefined,
2525
) {
2626
return (
27-
this.documentUri === document.uri.toString() &&
2827
this.documentVersion === document.version &&
28+
this.documentUri === document.uri.toString() &&
2929
this.documentLanguageId === document.languageId &&
30-
this.startPosition === startPosition &&
31-
this.endPosition === endPosition
30+
positionsEqual(this.startPosition, startPosition) &&
31+
positionsEqual(this.endPosition, endPosition)
3232
);
3333
}
3434

@@ -38,8 +38,8 @@ export class Cache {
3838
endPosition: Position | undefined,
3939
matches: QueryMatch[],
4040
) {
41-
this.documentUri = document.uri.toString();
4241
this.documentVersion = document.version;
42+
this.documentUri = document.uri.toString();
4343
this.documentLanguageId = document.languageId;
4444
this.startPosition = startPosition;
4545
this.endPosition = endPosition;
@@ -51,4 +51,11 @@ export class Cache {
5151
}
5252
}
5353

54+
function positionsEqual(a: Position | undefined, b: Position | undefined) {
55+
if (a == null || b == null) {
56+
return a === b;
57+
}
58+
return a.isEqual(b);
59+
}
60+
5461
export const treeSitterQueryCache = new Cache();

packages/cursorless-vscode-e2e/src/suite/scopeProvider/runBasicScopeInfoTest.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,14 @@ function helloWorld() {
5454
}
5555
`;
5656

57-
function getExpectedScope(scopeSupport: ScopeSupport): ScopeSupportInfo {
57+
function getExpectedScope(
58+
scopeSupport: ScopeSupport,
59+
iterationScopeSupport?: ScopeSupport,
60+
): ScopeSupportInfo {
5861
return {
5962
humanReadableName: "named function",
6063
isLanguageSpecific: true,
61-
iterationScopeSupport: scopeSupport,
64+
iterationScopeSupport: iterationScopeSupport ?? scopeSupport,
6265
scopeType: {
6366
type: "namedFunction",
6467
},
@@ -71,5 +74,8 @@ function getExpectedScope(scopeSupport: ScopeSupport): ScopeSupportInfo {
7174
}
7275

7376
const unsupported = getExpectedScope(ScopeSupport.unsupported);
74-
const supported = getExpectedScope(ScopeSupport.supportedButNotPresentInEditor);
77+
const supported = getExpectedScope(
78+
ScopeSupport.supportedButNotPresentInEditor,
79+
ScopeSupport.supportedAndPresentInEditor,
80+
);
7581
const present = getExpectedScope(ScopeSupport.supportedAndPresentInEditor);

0 commit comments

Comments
 (0)