@@ -70,6 +70,15 @@ impl CompletionFilter<'_> {
7070 }
7171 }
7272
73+ if ctx
74+ . node_under_cursor
75+ . as_ref ( )
76+ . is_some_and ( |n| n. kind ( ) == "any_identifier" )
77+ && ctx. matches_ancestor_history ( & [ "alias" ] )
78+ {
79+ return None ;
80+ }
81+
7382 // No autocompletions if there are two identifiers without a separator.
7483 if ctx. node_under_cursor . as_ref ( ) . is_some_and ( |node| {
7584 node. prev_sibling ( ) . is_some_and ( |p| {
@@ -95,62 +104,78 @@ impl CompletionFilter<'_> {
95104 fn check_specific_node_type ( & self , ctx : & TreesitterContext ) -> Option < ( ) > {
96105 let kind = ctx. node_under_cursor . as_ref ( ) . map ( |n| n. kind ( ) ) ?;
97106
98- let is_allowed =
99- match kind {
100- "column_identifier" => matches ! ( self . data, CompletionRelevanceData :: Column ( _) ) ,
101- "role_identifier" => matches ! ( self . data, CompletionRelevanceData :: Role ( _) ) ,
102- "function_identifier" => matches ! ( self . data, CompletionRelevanceData :: Function ( _) ) ,
103- "schema_identifier" => matches ! ( self . data, CompletionRelevanceData :: Schema ( _) ) ,
104- "table_identifier" => matches ! ( self . data, CompletionRelevanceData :: Table ( _) ) ,
105- "policy_identifier" => matches ! ( self . data, CompletionRelevanceData :: Policy ( _) ) ,
106-
107- "any_identifier" => match self . data {
108- CompletionRelevanceData :: Column ( _) => ctx
109- . node_under_cursor_is_within_field_name ( & [
110- "object_reference_1of1" ,
111- "object_reference_2of2" ,
112- "object_reference_3of3" ,
113- "column_reference_1of1" ,
114- "column_reference_2of2" ,
115- "column_reference_3of3" ,
116- ] ) ,
117-
118- CompletionRelevanceData :: Schema ( _) => ctx
119- . node_under_cursor_is_within_field_name ( & [
120- "object_reference_1of1" ,
121- "object_reference_1of2" ,
122- "object_reference_1of3" ,
123- "type_reference_1of1" ,
124- "table_reference_1of1" ,
125- "column_reference_1of1" ,
126- "column_reference_1of2" ,
127- "function_reference_1of1" ,
128- ] ) ,
129-
130- CompletionRelevanceData :: Function ( _) => ctx
131- . node_under_cursor_is_within_field_name ( & [
132- "object_reference_1of1" ,
133- "object_reference_2of2" ,
134- "function_reference_1of1" ,
135- ] ) ,
136-
137- CompletionRelevanceData :: Table ( _) => ctx
138- . node_under_cursor_is_within_field_name ( & [
139- "object_reference_1of1" ,
140- "object_reference_1of2" ,
141- "object_reference_2of2" ,
142- "object_reference_2of3" ,
143- "table_reference_1of1" ,
144- "column_reference_1of1" ,
145- "column_reference_1of2" ,
146- "column_reference_2of2" ,
147- ] ) ,
148-
149- _ => false ,
150- } ,
107+ let is_allowed = match kind {
108+ "column_identifier" => matches ! ( self . data, CompletionRelevanceData :: Column ( _) ) ,
109+ "role_identifier" => matches ! ( self . data, CompletionRelevanceData :: Role ( _) ) ,
110+ "function_identifier" => matches ! ( self . data, CompletionRelevanceData :: Function ( _) ) ,
111+ "schema_identifier" => matches ! ( self . data, CompletionRelevanceData :: Schema ( _) ) ,
112+ "table_identifier" => matches ! ( self . data, CompletionRelevanceData :: Table ( _) ) ,
113+ "policy_identifier" => matches ! ( self . data, CompletionRelevanceData :: Policy ( _) ) ,
114+
115+ "any_identifier" => {
116+ if false || ctx. matches_ancestor_history ( & [ "insert_values" , "object_reference" ] ) {
117+ false
118+ } else {
119+ match self . data {
120+ CompletionRelevanceData :: Column ( _) => {
121+ ctx. node_under_cursor_is_within_field_name ( & [
122+ "object_reference_1of1" ,
123+ "object_reference_2of2" ,
124+ "object_reference_3of3" ,
125+ "column_reference_1of1" ,
126+ "column_reference_2of2" ,
127+ "column_reference_3of3" ,
128+ ] ) && !ctx
129+ . node_under_cursor_is_within_field_name ( & [ "binary_expr_right" ] )
130+ && !ctx. matches_ancestor_history ( & [
131+ "insert_values" ,
132+ "object_reference" ,
133+ ] )
134+ }
151135
152- _ => false ,
153- } ;
136+ CompletionRelevanceData :: Schema ( _) => ctx
137+ . node_under_cursor_is_within_field_name ( & [
138+ "object_reference_1of1" ,
139+ "object_reference_1of2" ,
140+ "object_reference_1of3" ,
141+ "type_reference_1of1" ,
142+ "table_reference_1of1" ,
143+ "column_reference_1of1" ,
144+ "column_reference_1of2" ,
145+ "function_reference_1of1" ,
146+ ] ) ,
147+
148+ CompletionRelevanceData :: Function ( f) => {
149+ ctx. node_under_cursor_is_within_field_name ( & [
150+ "object_reference_1of1" ,
151+ "object_reference_2of2" ,
152+ "function_reference_1of1" ,
153+ ] ) && !( ctx. matches_ancestor_history ( & [
154+ "check_or_using_clause" ,
155+ "binary_expression" ,
156+ "object_reference" ,
157+ ] ) && matches ! ( f. kind, ProcKind :: Aggregate ) )
158+ }
159+
160+ CompletionRelevanceData :: Table ( _) => ctx
161+ . node_under_cursor_is_within_field_name ( & [
162+ "object_reference_1of1" ,
163+ "object_reference_1of2" ,
164+ "object_reference_2of2" ,
165+ "object_reference_2of3" ,
166+ "table_reference_1of1" ,
167+ "column_reference_1of1" ,
168+ "column_reference_1of2" ,
169+ "column_reference_2of2" ,
170+ ] ) ,
171+
172+ _ => false ,
173+ }
174+ }
175+ }
176+
177+ _ => false ,
178+ } ;
154179
155180 if is_allowed { Some ( ( ) ) } else { None }
156181 }
0 commit comments