1+ use pgt_text_size:: { TextRange , TextSize } ;
2+
13use crate :: {
24 CompletionItemKind , CompletionText ,
35 builder:: { CompletionBuilder , PossibleCompletionItem } ,
@@ -10,9 +12,9 @@ use super::helper::get_range_to_replace;
1012pub fn complete_policies < ' a > ( ctx : & CompletionContext < ' a > , builder : & mut CompletionBuilder < ' a > ) {
1113 let available_policies = & ctx. schema_cache . policies ;
1214
13- let has_quotes = ctx
15+ let surrounded_by_quotes = ctx
1416 . 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 != " \" \" " ) ;
1618
1719 for pol in available_policies {
1820 let relevance = CompletionRelevanceData :: Policy ( pol) ;
@@ -23,13 +25,22 @@ pub fn complete_policies<'a>(ctx: &CompletionContext<'a>, builder: &mut Completi
2325 filter : CompletionFilter :: from ( relevance) ,
2426 description : format ! ( "{}" , pol. table_name) ,
2527 kind : CompletionItemKind :: Policy ,
26- completion_text : if !has_quotes {
28+ completion_text : if !surrounded_by_quotes {
2729 Some ( CompletionText {
2830 text : format ! ( "\" {}\" " , pol. name) ,
2931 range : get_range_to_replace ( ctx) ,
3032 } )
3133 } 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+ } )
3344 } ,
3445 } ;
3546
0 commit comments