@@ -9,19 +9,25 @@ use super::CompletionRelevanceData;
99#[ derive( Debug ) ]
1010pub ( crate ) struct CompletionScore < ' a > {
1111 score : i32 ,
12+ skip : bool ,
1213 data : CompletionRelevanceData < ' a > ,
1314}
1415
1516impl < ' a > From < CompletionRelevanceData < ' a > > for CompletionScore < ' a > {
1617 fn from ( value : CompletionRelevanceData < ' a > ) -> Self {
1718 Self {
1819 score : 0 ,
20+ skip : false ,
1921 data : value,
2022 }
2123 }
2224}
2325
2426impl CompletionScore < ' _ > {
27+ pub fn should_skip ( & self ) -> bool {
28+ self . skip
29+ }
30+
2531 pub fn get_score ( & self ) -> i32 {
2632 self . score
2733 }
@@ -55,20 +61,35 @@ impl CompletionScore<'_> {
5561
5662 let fz_matcher = SkimMatcherV2 :: default ( ) ;
5763
58- if let Some ( score) =
59- fz_matcher. fuzzy_match ( name. as_str ( ) , content. to_ascii_lowercase ( ) . as_str ( ) )
60- {
61- let scorei32: i32 = score
62- . try_into ( )
63- . expect ( "The length of the input exceeds i32 capacity" ) ;
64-
65- // the scoring value isn't linear.
66- // here are a couple of samples:
67- // - item: bytea_string_agg_transfn, input: n, score: 15
68- // - item: numeric_uplus, input: n, score: 31
69- // - item: settings, input: sett, score: 91
70- // - item: user_settings, input: sett, score: 82
71- self . score += scorei32 / 2 ;
64+ let check_against = match ctx. identifier_qualifiers {
65+ // If both qualifiers are already written out, we must check the item's name itself.
66+ ( Some ( _) , Some ( _) ) => content. to_ascii_lowercase ( ) ,
67+
68+ _ => self
69+ . get_table_name ( )
70+ . and_then ( |tbl| ctx. get_used_alias_for_table ( tbl) )
71+ . map ( |alias| format ! ( "{}.{}" , alias, name) )
72+ . unwrap_or ( name) ,
73+ } ;
74+
75+ match fz_matcher. fuzzy_match (
76+ check_against. as_str ( ) ,
77+ content. to_ascii_lowercase ( ) . as_str ( ) ,
78+ ) {
79+ Some ( score) => {
80+ let scorei32: i32 = score
81+ . try_into ( )
82+ . expect ( "The length of the input exceeds i32 capacity" ) ;
83+
84+ // the scoring value isn't linear.
85+ // here are a couple of samples:
86+ // - item: bytea_string_agg_transfn, input: n, score: 15
87+ // - item: numeric_uplus, input: n, score: 31
88+ // - item: settings, input: sett, score: 91
89+ // - item: user_settings, input: sett, score: 82
90+ self . score += scorei32 / 2 ;
91+ }
92+ None => self . skip = true ,
7293 }
7394 }
7495
0 commit comments