@@ -3,7 +3,6 @@ import type {
3
3
ScopeType ,
4
4
SimpleScopeType ,
5
5
SimpleScopeTypeType ,
6
- StringRecord ,
7
6
TreeSitter ,
8
7
} from "@cursorless/common" ;
9
8
import {
@@ -13,7 +12,6 @@ import {
13
12
type TextDocument ,
14
13
} from "@cursorless/common" ;
15
14
import { TreeSitterScopeHandler } from "../processTargets/modifiers/scopeHandlers" ;
16
- import { LanguageDefinitionCache } from "./LanguageDefinitionCache" ;
17
15
import { TreeSitterQuery } from "./TreeSitterQuery" ;
18
16
import type { QueryCapture } from "./TreeSitterQuery/QueryCapture" ;
19
17
import { validateQueryCaptures } from "./TreeSitterQuery/validateQueryCaptures" ;
@@ -23,18 +21,14 @@ import { validateQueryCaptures } from "./TreeSitterQuery/validateQueryCaptures";
23
21
* tree-sitter query used to extract scopes for the given language
24
22
*/
25
23
export class LanguageDefinition {
26
- private cache : LanguageDefinitionCache ;
27
-
28
24
private constructor (
29
25
/**
30
26
* The tree-sitter query used to extract scopes for the given language.
31
27
* Note that this query contains patterns for all scope types that the
32
28
* language supports using new-style tree-sitter queries
33
29
*/
34
30
private query : TreeSitterQuery ,
35
- ) {
36
- this . cache = new LanguageDefinitionCache ( ) ;
37
- }
31
+ ) { }
38
32
39
33
/**
40
34
* Construct a language definition for the given language id, if the language
@@ -88,41 +82,24 @@ export class LanguageDefinition {
88
82
}
89
83
90
84
/**
91
- * This is a low-level function that just returns a list of captures of the given
92
- * capture name in the document. We use this in our surrounding pair code.
85
+ * This is a low-level function that just returns a map of all captures in the
86
+ * document. We use this in our surrounding pair code.
93
87
*
94
88
* @param document The document to search
95
89
* @param captureName The name of a capture to search for
96
- * @returns A list of captures of the given capture name in the document
97
- */
98
- getCaptures (
99
- document : TextDocument ,
100
- captureName : SimpleScopeTypeType ,
101
- ) : QueryCapture [ ] {
102
- if ( ! this . cache . isValid ( document ) ) {
103
- this . cache . update ( document , this . getCapturesMap ( document ) ) ;
104
- }
105
-
106
- return this . cache . get ( captureName ) ;
107
- }
108
-
109
- clearCache ( ) : void {
110
- this . cache = new LanguageDefinitionCache ( ) ;
111
- }
112
-
113
- /**
114
- * This is a low level function that returns a map of all captures in the document.
90
+ * @returns A map of captures in the document
115
91
*/
116
- private getCapturesMap ( document : TextDocument ) : StringRecord < QueryCapture [ ] > {
92
+ getCapturesMap ( document : TextDocument ) {
117
93
const matches = this . query . matches ( document ) ;
118
- const result : StringRecord < QueryCapture [ ] > = { } ;
94
+ const result : Partial < Record < SimpleScopeTypeType , QueryCapture [ ] > > = { } ;
119
95
120
96
for ( const match of matches ) {
121
97
for ( const capture of match . captures ) {
122
- if ( result [ capture . name ] == null ) {
123
- result [ capture . name ] = [ ] ;
98
+ const name = capture . name as SimpleScopeTypeType ;
99
+ if ( result [ name ] == null ) {
100
+ result [ name ] = [ ] ;
124
101
}
125
- result [ capture . name ] ! . push ( capture ) ;
102
+ result [ name ] ! . push ( capture ) ;
126
103
}
127
104
}
128
105
0 commit comments