@@ -5,6 +5,7 @@ use pgt_treesitter::TreesitterContext;
55use crate :: {
66 CompletionItemKind , CompletionText ,
77 builder:: { CompletionBuilder , PossibleCompletionItem } ,
8+ providers:: helper:: node_text_surrounded_by_quotes,
89 relevance:: { CompletionRelevanceData , filtering:: CompletionFilter , scoring:: CompletionScore } ,
910} ;
1011
@@ -17,33 +18,13 @@ pub fn complete_policies<'a>(
1718) {
1819 let available_policies = & schema_cache. policies ;
1920
20- let surrounded_by_quotes = ctx
21- . get_node_under_cursor_content ( )
22- . is_some_and ( |c| c. starts_with ( '"' ) && c. ends_with ( '"' ) && c != "\" \" " ) ;
23-
2421 for pol in available_policies {
25- let completion_text = if surrounded_by_quotes {
22+ let text = if node_text_surrounded_by_quotes ( ctx ) {
2623 // If we're within quotes, we want to change the content
2724 // *within* the quotes.
28- // If we attempt to replace outside the quotes, the VSCode
29- // client won't show the suggestions.
30- let range = get_range_to_replace ( ctx) ;
31- Some ( CompletionText {
32- text : pol. name . clone ( ) ,
33- is_snippet : false ,
34- range : TextRange :: new (
35- range. start ( ) + TextSize :: new ( 1 ) ,
36- range. end ( ) - TextSize :: new ( 1 ) ,
37- ) ,
38- } )
25+ pol. name . to_string ( )
3926 } else {
40- // If we aren't within quotes, we want to complete the
41- // full policy including quotation marks.
42- Some ( CompletionText {
43- is_snippet : false ,
44- text : format ! ( "\" {}\" " , pol. name) ,
45- range : get_range_to_replace ( ctx) ,
46- } )
27+ format ! ( "\" {}\" " , pol. name)
4728 } ;
4829
4930 let relevance = CompletionRelevanceData :: Policy ( pol) ;
@@ -54,7 +35,11 @@ pub fn complete_policies<'a>(
5435 filter : CompletionFilter :: from ( relevance) ,
5536 description : pol. table_name . to_string ( ) ,
5637 kind : CompletionItemKind :: Policy ,
57- completion_text,
38+ completion_text : Some ( CompletionText {
39+ text,
40+ range : get_range_to_replace ( ctx) ,
41+ is_snippet : false ,
42+ } ) ,
5843 detail : None ,
5944 } ;
6045
0 commit comments