1
+ use pgt_text_size:: { TextRange , TextSize } ;
2
+
1
3
use crate :: {
2
4
CompletionItemKind , CompletionText ,
3
5
builder:: { CompletionBuilder , PossibleCompletionItem } ,
@@ -10,9 +12,9 @@ use super::helper::get_range_to_replace;
10
12
pub fn complete_policies < ' a > ( ctx : & CompletionContext < ' a > , builder : & mut CompletionBuilder < ' a > ) {
11
13
let available_policies = & ctx. schema_cache . policies ;
12
14
13
- let has_quotes = ctx
15
+ let surrounded_by_quotes = ctx
14
16
. get_node_under_cursor_content ( )
15
- . is_some_and ( |c| c. starts_with ( '"' ) && c. ends_with ( '"' ) ) ;
17
+ . is_some_and ( |c| c. starts_with ( '"' ) && c. ends_with ( '"' ) && c != " \" \" " ) ;
16
18
17
19
for pol in available_policies {
18
20
let relevance = CompletionRelevanceData :: Policy ( pol) ;
@@ -23,13 +25,22 @@ pub fn complete_policies<'a>(ctx: &CompletionContext<'a>, builder: &mut Completi
23
25
filter : CompletionFilter :: from ( relevance) ,
24
26
description : format ! ( "{}" , pol. table_name) ,
25
27
kind : CompletionItemKind :: Policy ,
26
- completion_text : if !has_quotes {
28
+ completion_text : if !surrounded_by_quotes {
27
29
Some ( CompletionText {
28
30
text : format ! ( "\" {}\" " , pol. name) ,
29
31
range : get_range_to_replace ( ctx) ,
30
32
} )
31
33
} else {
32
- None
34
+ let range = get_range_to_replace ( ctx) ;
35
+ Some ( CompletionText {
36
+ text : pol. name . clone ( ) ,
37
+
38
+ // trim the quotes.
39
+ range : TextRange :: new (
40
+ range. start ( ) + TextSize :: new ( 1 ) ,
41
+ range. end ( ) - TextSize :: new ( 1 ) ,
42
+ ) ,
43
+ } )
33
44
} ,
34
45
} ;
35
46
0 commit comments