File tree 2 files changed +56
-0
lines changed
crates/pgt_completions/src
2 files changed +56
-0
lines changed Original file line number Diff line number Diff line change @@ -110,4 +110,45 @@ mod tests {
110
110
assert_eq ! ( description, q. description, "{}" , q. message) ;
111
111
}
112
112
}
113
+
114
+ #[ tokio:: test]
115
+ async fn shows_multiple_columns_if_no_relation_specified ( ) {
116
+ let setup = r#"
117
+ create schema private;
118
+
119
+ create table public.users (
120
+ id serial primary key,
121
+ name text
122
+ );
123
+
124
+ create table public.audio_books (
125
+ id serial primary key,
126
+ narrator text
127
+ );
128
+
129
+ create table private.audio_books (
130
+ id serial primary key,
131
+ narrator_id text
132
+ );
133
+ "# ;
134
+
135
+ let case = TestCase {
136
+ query : format ! ( r#"select n{};"# , CURSOR_POS ) ,
137
+ description : "" ,
138
+ label : "" ,
139
+ message : "" ,
140
+ } ;
141
+
142
+ let ( tree, cache) = get_test_deps ( setup, case. get_input_query ( ) ) . await ;
143
+ let params = get_test_params ( & tree, & cache, case. get_input_query ( ) ) ;
144
+ let mut results = complete ( params) ;
145
+
146
+ let _ = results. items . split_off ( 3 ) ;
147
+
148
+ results. items . sort_by ( |a, b| a. label . cmp ( & b. label ) ) ;
149
+
150
+ let labels: Vec < String > = results. items . into_iter ( ) . map ( |c| c. label ) . collect ( ) ;
151
+
152
+ assert_eq ! ( labels, vec![ "name" , "narrator" , "narrator_id" ] ) ;
153
+ }
113
154
}
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ pub(crate) struct CompletionRelevance<'a> {
30
30
31
31
impl CompletionRelevance < ' _ > {
32
32
pub fn into_score ( mut self , ctx : & CompletionContext ) -> i32 {
33
+ self . check_is_user_defined ( ) ;
33
34
self . check_matches_schema ( ctx) ;
34
35
self . check_matches_query_input ( ctx) ;
35
36
self . check_if_catalog ( ctx) ;
@@ -168,4 +169,18 @@ impl CompletionRelevance<'_> {
168
169
self . score += 30 ;
169
170
}
170
171
}
172
+
173
+ fn check_is_user_defined ( & mut self ) {
174
+ let schema = match self . data {
175
+ CompletionRelevanceData :: Column ( c) => & c. schema_name ,
176
+ CompletionRelevanceData :: Function ( f) => & f. schema ,
177
+ CompletionRelevanceData :: Table ( t) => & t. schema ,
178
+ } ;
179
+
180
+ let system_schemas = [ "pg_catalog" , "information_schema" , "pg_toast" ] ;
181
+
182
+ if system_schemas. contains ( & schema. as_str ( ) ) {
183
+ self . score -= 10 ;
184
+ }
185
+ }
171
186
}
You can’t perform that action at this time.
0 commit comments