@@ -63,7 +63,7 @@ impl CompletionScore<'_> {
6363 if case {
6464 println ! ( "{} after clause type check" , self . score) ;
6565 }
66- self . check_matching_wrapping_node ( ctx) ;
66+ self . check_without_content ( ctx) ;
6767 if case {
6868 println ! ( "{} after wrapping node check" , self . score) ;
6969 }
@@ -247,37 +247,49 @@ impl CompletionScore<'_> {
247247 }
248248 }
249249
250- fn check_matching_wrapping_node ( & mut self , ctx : & TreesitterContext ) {
251- let wrapping_node = match ctx. wrapping_node_kind . as_ref ( ) {
252- None => return ,
253- Some ( wn) => wn,
254- } ;
250+ // ok i think we need a rule set first.
251+ // generally, we want to prefer columns that match a mentioned relation. that's already handled elsewhere. same with schema matches.
255252
256- let has_qualifier = ctx. has_any_qualifier ( ) ;
253+ // so, what here? we want to handle the *no content* case.
254+ // in that case, we want to check the current node_kind.
257255
258- self . score += match self . data {
259- CompletionRelevanceData :: Table ( _) => match wrapping_node {
260- WrappingNode :: Relation if has_qualifier => 15 ,
261- WrappingNode :: Relation if !has_qualifier => 10 ,
262- WrappingNode :: BinaryExpression => 5 ,
263- _ => -50 ,
264- } ,
265- CompletionRelevanceData :: Function ( _) => match wrapping_node {
266- WrappingNode :: BinaryExpression => 15 ,
267- WrappingNode :: Relation => 10 ,
268- _ => -50 ,
269- } ,
270- CompletionRelevanceData :: Column ( _) => match wrapping_node {
271- WrappingNode :: BinaryExpression => 15 ,
272- WrappingNode :: Assignment => 15 ,
273- _ => -15 ,
274- } ,
275- CompletionRelevanceData :: Schema ( _) => match wrapping_node {
276- WrappingNode :: Relation if !has_qualifier => 15 ,
277- _ => -50 ,
256+ fn check_without_content ( & mut self , ctx : & TreesitterContext ) {
257+ // the function is only concerned with cases where the user hasn't typed anything yet.
258+ if ctx
259+ . get_node_under_cursor_content ( )
260+ . is_some_and ( |c| !sanitization:: is_sanitized_token ( c. as_str ( ) ) )
261+ {
262+ return ;
263+ }
264+
265+ match ctx. node_under_cursor . kind ( ) {
266+ "function_identifier" | "table_identifier"
267+ if self . get_schema_name ( ) . is_some_and ( |s| s == "public" ) =>
268+ {
269+ self . score += 10 ;
270+ }
271+
272+ "schema_identifier" if self . get_schema_name ( ) . is_some_and ( |s| s == "public" ) => {
273+ self . score += 10 ;
274+ }
275+
276+ "any_identifier" => match self . data {
277+ CompletionRelevanceData :: Table ( table) => {
278+ if table. schema == "public" {
279+ self . score += 10 ;
280+ }
281+ }
282+ CompletionRelevanceData :: Schema ( schema) => {
283+ if schema. name != "public" {
284+ self . score += 10 ;
285+ } else {
286+ self . score -= 20 ;
287+ }
288+ }
289+ _ => { }
278290 } ,
279- CompletionRelevanceData :: Policy ( _ ) => 0 ,
280- CompletionRelevanceData :: Role ( _ ) => 0 ,
291+
292+ _ => return ,
281293 }
282294 }
283295
0 commit comments