@@ -63,9 +63,22 @@ async def __get_document_type(self, document: TextDocument) -> DocumentType:
63
63
else :
64
64
return DocumentType .UNKNOWN
65
65
66
- async def get_tokens (self , document : TextDocument ) -> List [Token ]:
66
+ async def get_tokens (self , document : TextDocument , data_only : bool = False ) -> List [Token ]:
67
+ if data_only :
68
+ return await document .get_cache (self .__get_tokens_data_only )
67
69
return await document .get_cache (self .__get_tokens )
68
70
71
+ async def __get_tokens_data_only (self , document : TextDocument ) -> List [Token ]:
72
+ document_type = await self .get_document_type (document )
73
+ if document_type == DocumentType .INIT :
74
+ return await self .get_init_tokens (document , True )
75
+ elif document_type == DocumentType .GENERAL :
76
+ return await self .get_general_tokens (document , True )
77
+ elif document_type == DocumentType .RESOURCE :
78
+ return await self .get_resource_tokens (document , True )
79
+ else :
80
+ raise UnknownFileTypeError (str (document .uri ))
81
+
69
82
async def __get_tokens (self , document : TextDocument ) -> List [Token ]:
70
83
document_type = await self .get_document_type (document )
71
84
if document_type == DocumentType .INIT :
@@ -77,9 +90,20 @@ async def __get_tokens(self, document: TextDocument) -> List[Token]:
77
90
else :
78
91
raise UnknownFileTypeError (str (document .uri ))
79
92
80
- async def get_general_tokens (self , document : TextDocument ) -> List [Token ]:
93
+ async def get_general_tokens (self , document : TextDocument , data_only : bool = False ) -> List [Token ]:
94
+ if data_only :
95
+ return await document .get_cache (self .__get_general_tokens_data_only )
81
96
return await document .get_cache (self .__get_general_tokens )
82
97
98
+ async def __get_general_tokens_data_only (self , document : TextDocument ) -> List [Token ]:
99
+ import robot .api
100
+
101
+ def get (text : str ) -> List [Token ]:
102
+ with io .StringIO (text ) as content :
103
+ return [e for e in robot .api .get_tokens (content , True ) if check_canceled_sync ()]
104
+
105
+ return await self .__get_tokens_internal (document , get )
106
+
83
107
async def __get_general_tokens (self , document : TextDocument ) -> List [Token ]:
84
108
import robot .api
85
109
@@ -97,9 +121,21 @@ async def __get_tokens_internal(
97
121
98
122
return get (await document .text ())
99
123
100
- async def get_resource_tokens (self , document : TextDocument ) -> List [Token ]:
124
+ async def get_resource_tokens (self , document : TextDocument , data_only : bool = False ) -> List [Token ]:
125
+ if data_only :
126
+ return await document .get_cache (self .__get_resource_tokens_data_only )
127
+
101
128
return await document .get_cache (self .__get_resource_tokens )
102
129
130
+ async def __get_resource_tokens_data_only (self , document : TextDocument ) -> List [Token ]:
131
+ import robot .api
132
+
133
+ def get (text : str ) -> List [Token ]:
134
+ with io .StringIO (text ) as content :
135
+ return [e for e in robot .api .get_resource_tokens (content , True ) if check_canceled_sync ()]
136
+
137
+ return await self .__get_tokens_internal (document , get )
138
+
103
139
async def __get_resource_tokens (self , document : TextDocument ) -> List [Token ]:
104
140
import robot .api
105
141
@@ -109,9 +145,20 @@ def get(text: str) -> List[Token]:
109
145
110
146
return await self .__get_tokens_internal (document , get )
111
147
112
- async def get_init_tokens (self , document : TextDocument ) -> List [Token ]:
148
+ async def get_init_tokens (self , document : TextDocument , data_only : bool = False ) -> List [Token ]:
149
+ if data_only :
150
+ return await document .get_cache (self .__get_init_tokens_data_only )
113
151
return await document .get_cache (self .__get_init_tokens )
114
152
153
+ async def __get_init_tokens_data_only (self , document : TextDocument ) -> List [Token ]:
154
+ import robot .api
155
+
156
+ def get (text : str ) -> List [Token ]:
157
+ with io .StringIO (text ) as content :
158
+ return [e for e in robot .api .get_init_tokens (content , True ) if check_canceled_sync ()]
159
+
160
+ return await self .__get_tokens_internal (document , get )
161
+
115
162
async def __get_init_tokens (self , document : TextDocument ) -> List [Token ]:
116
163
import robot .api
117
164
@@ -121,15 +168,15 @@ def get(text: str) -> List[Token]:
121
168
122
169
return await self .__get_tokens_internal (document , get )
123
170
124
- async def get_model (self , document : TextDocument ) -> ast .AST :
171
+ async def get_model (self , document : TextDocument , data_only : bool = True ) -> ast .AST :
125
172
document_type = await self .get_document_type (document )
126
173
127
174
if document_type == DocumentType .INIT :
128
- return await self .get_init_model (document )
175
+ return await self .get_init_model (document , data_only )
129
176
if document_type == DocumentType .GENERAL :
130
- return await self .get_general_model (document )
177
+ return await self .get_general_model (document , data_only )
131
178
if document_type == DocumentType .RESOURCE :
132
- return await self .get_resource_model (document )
179
+ return await self .get_resource_model (document , data_only )
133
180
else :
134
181
raise UnknownFileTypeError (f"Unknown file type '{ document .uri } '." )
135
182
@@ -150,21 +197,37 @@ def get_tokens(_source: str, _data_only: bool = False) -> Generator[Token, None,
150
197
151
198
return cast (ast .AST , model )
152
199
153
- async def get_general_model (self , document : TextDocument ) -> ast .AST :
200
+ async def get_general_model (self , document : TextDocument , data_only : bool = True ) -> ast .AST :
201
+ if data_only :
202
+ return await document .get_cache (self .__get_general_model_data_only )
154
203
return await document .get_cache (self .__get_general_model )
155
204
205
+ async def __get_general_model_data_only (self , document : TextDocument ) -> ast .AST :
206
+ return self .__get_model (document , await self .get_general_tokens (document , True ), DocumentType .GENERAL )
207
+
156
208
async def __get_general_model (self , document : TextDocument ) -> ast .AST :
157
209
return self .__get_model (document , await self .get_general_tokens (document ), DocumentType .GENERAL )
158
210
159
- async def get_resource_model (self , document : TextDocument ) -> ast .AST :
211
+ async def get_resource_model (self , document : TextDocument , data_only : bool = True ) -> ast .AST :
212
+ if data_only :
213
+ return await document .get_cache (self .__get_resource_model_data_only )
214
+
160
215
return await document .get_cache (self .__get_resource_model )
161
216
217
+ async def __get_resource_model_data_only (self , document : TextDocument ) -> ast .AST :
218
+ return self .__get_model (document , await self .get_resource_tokens (document , True ), DocumentType .RESOURCE )
219
+
162
220
async def __get_resource_model (self , document : TextDocument ) -> ast .AST :
163
221
return self .__get_model (document , await self .get_resource_tokens (document ), DocumentType .RESOURCE )
164
222
165
- async def get_init_model (self , document : TextDocument ) -> ast .AST :
223
+ async def get_init_model (self , document : TextDocument , data_only : bool = True ) -> ast .AST :
224
+ if data_only :
225
+ return await document .get_cache (self .__get_init_model_data_only )
166
226
return await document .get_cache (self .__get_init_model )
167
227
228
+ async def __get_init_model_data_only (self , document : TextDocument ) -> ast .AST :
229
+ return self .__get_model (document , await self .get_init_tokens (document , True ), DocumentType .INIT )
230
+
168
231
async def __get_init_model (self , document : TextDocument ) -> ast .AST :
169
232
return self .__get_model (document , await self .get_init_tokens (document ), DocumentType .INIT )
170
233
0 commit comments