@@ -48,7 +48,8 @@ impl<'larger, 'smaller> From<CompletionParams<'larger>> for SanitizedCompletionP
48
48
where
49
49
' larger : ' smaller ,
50
50
{
51
- fn from ( params : CompletionParams < ' larger > ) -> Self {
51
+ fn from ( mut params : CompletionParams < ' larger > ) -> Self {
52
+ params. text = params. text . to_ascii_lowercase ( ) ;
52
53
if cursor_inbetween_nodes ( & params. text , params. position )
53
54
|| cursor_prepared_to_write_token_after_last_node ( & params. text , params. position )
54
55
|| cursor_before_semicolon ( params. tree , params. position )
@@ -263,13 +264,43 @@ fn cursor_between_parentheses(sql: &str, position: TextSize) -> bool {
263
264
264
265
#[ cfg( test) ]
265
266
mod tests {
267
+ use pgt_schema_cache:: SchemaCache ;
266
268
use pgt_text_size:: TextSize ;
267
269
268
- use crate :: sanitization:: {
269
- cursor_before_semicolon, cursor_between_parentheses, cursor_inbetween_nodes,
270
- cursor_on_a_dot, cursor_prepared_to_write_token_after_last_node,
270
+ use crate :: {
271
+ CompletionParams , SanitizedCompletionParams ,
272
+ sanitization:: {
273
+ cursor_before_semicolon, cursor_between_parentheses, cursor_inbetween_nodes,
274
+ cursor_on_a_dot, cursor_prepared_to_write_token_after_last_node,
275
+ } ,
271
276
} ;
272
277
278
+ #[ test]
279
+ fn should_lowercase_everything_except_replaced_token ( ) {
280
+ let input = "SELECT FROM users WHERE ts = NOW();" ;
281
+
282
+ let position = TextSize :: new ( 7 ) ;
283
+ let cache = SchemaCache :: default ( ) ;
284
+
285
+ let mut ts = tree_sitter:: Parser :: new ( ) ;
286
+ ts. set_language ( tree_sitter_sql:: language ( ) ) . unwrap ( ) ;
287
+ let tree = ts. parse ( input, None ) . unwrap ( ) ;
288
+
289
+ let params = CompletionParams {
290
+ position,
291
+ schema : & cache,
292
+ text : input. into ( ) ,
293
+ tree : & tree,
294
+ } ;
295
+
296
+ let sanitized = SanitizedCompletionParams :: from ( params) ;
297
+
298
+ assert_eq ! (
299
+ sanitized. text,
300
+ "select REPLACED_TOKEN from users where ts = now();"
301
+ ) ;
302
+ }
303
+
273
304
#[ test]
274
305
fn test_cursor_inbetween_nodes ( ) {
275
306
// note: two spaces between select and from.
0 commit comments