@@ -2,6 +2,7 @@ import type {
2
2
CursorlessCommandId ,
3
3
ScopeProvider ,
4
4
ScopeSupportInfo ,
5
+ ScopeType ,
5
6
ScopeTypeInfo ,
6
7
} from "@cursorless/common" ;
7
8
import {
@@ -12,13 +13,17 @@ import {
12
13
serializeScopeType ,
13
14
uriEncodeHashId ,
14
15
} from "@cursorless/common" ;
15
- import type { CustomSpokenFormGenerator } from "@cursorless/cursorless-engine" ;
16
- import type { VscodeApi } from "@cursorless/vscode-common" ;
16
+ import {
17
+ ide ,
18
+ type CustomSpokenFormGenerator ,
19
+ } from "@cursorless/cursorless-engine" ;
20
+ import { fromVscodeSelection , type VscodeApi } from "@cursorless/vscode-common" ;
17
21
import { isEqual } from "lodash-es" ;
18
22
import type {
19
23
Disposable ,
20
24
Event ,
21
25
ExtensionContext ,
26
+ TextEditorSelectionChangeEvent ,
22
27
TreeDataProvider ,
23
28
TreeItemLabel ,
24
29
TreeView ,
@@ -61,6 +66,8 @@ export class ScopeTreeProvider implements TreeDataProvider<MyTreeItem> {
61
66
private customSpokenFormGenerator : CustomSpokenFormGenerator ,
62
67
private hasCommandServer : boolean ,
63
68
) {
69
+ this . onChangeTextSelection = this . onChangeTextSelection . bind ( this ) ;
70
+
64
71
this . treeView = vscodeApi . window . createTreeView (
65
72
CURSORLESS_SCOPE_TREE_VIEW_ID ,
66
73
{
@@ -79,7 +86,7 @@ export class ScopeTreeProvider implements TreeDataProvider<MyTreeItem> {
79
86
}
80
87
}
81
88
82
- onDidChangeVisible ( e : TreeViewVisibilityChangeEvent ) {
89
+ private onDidChangeVisible ( e : TreeViewVisibilityChangeEvent ) {
83
90
if ( e . visible ) {
84
91
if ( this . visibleDisposable != null ) {
85
92
return ;
@@ -96,6 +103,46 @@ export class ScopeTreeProvider implements TreeDataProvider<MyTreeItem> {
96
103
}
97
104
}
98
105
106
+ private onChangeTextSelection ( e : TextEditorSelectionChangeEvent ) {
107
+ if ( e . selections . length !== 1 ) {
108
+ return ;
109
+ }
110
+
111
+ const editor = ide ( ) . activeTextEditor ;
112
+
113
+ if ( editor == null ) {
114
+ return ;
115
+ }
116
+
117
+ const selection = fromVscodeSelection ( e . selections [ 0 ] ) ;
118
+
119
+ console . log ( "selection" , selection . concise ( ) ) ;
120
+
121
+ for ( const supportLevel of this . supportLevels ) {
122
+ if ( supportLevel . support !== ScopeSupport . supportedAndPresentInEditor ) {
123
+ continue ;
124
+ }
125
+
126
+ const scopes = this . scopeProvider . provideScopeRangesForRange (
127
+ editor ,
128
+ supportLevel . scopeType ,
129
+ selection ,
130
+ ) ;
131
+
132
+ if ( scopes . length === 0 ) {
133
+ continue ;
134
+ }
135
+
136
+ console . log ( supportLevel . scopeType . type ) ;
137
+
138
+ for ( const scope of scopes ) {
139
+ for ( const target of scope . targets ) {
140
+ console . log ( target . contentRange . concise ( ) ) ;
141
+ }
142
+ }
143
+ }
144
+ }
145
+
99
146
private registerScopeSupportListener ( ) {
100
147
this . visibleDisposable = disposableFrom (
101
148
this . scopeProvider . onDidChangeScopeSupport ( ( supportLevels ) => {
@@ -105,6 +152,9 @@ export class ScopeTreeProvider implements TreeDataProvider<MyTreeItem> {
105
152
this . scopeVisualizer . onDidChangeScopeType ( ( ) => {
106
153
this . _onDidChangeTreeData . fire ( ) ;
107
154
} ) ,
155
+ this . vscodeApi . window . onDidChangeTextEditorSelection (
156
+ this . onChangeTextSelection ,
157
+ ) ,
108
158
) ;
109
159
}
110
160
0 commit comments