@@ -28,73 +28,49 @@ def initialize(client, response_builder, node_context, dispatcher, uri)
2828
2929 sig { params ( node : Prism ::CallNode ) . void }
3030 def on_call_node_enter ( node )
31- if node . name == :where
32- handle_active_record_where_completions ( call_node : node )
33- elsif @node_context . call_node && @node_context . call_node &.name == :where
34- handle_active_record_where_completions ( call_node : T . must ( @node_context . call_node ) , current_node : node )
31+ if @node_context . call_node && @node_context . call_node &.name == :where
32+ handle_active_record_where_completions ( node )
3533 end
3634 end
3735
3836 private
3937
40- sig { params ( call_node : Prism ::CallNode , current_node : T . nilable ( Prism :: CallNode ) ) . void }
41- def handle_active_record_where_completions ( call_node : , current_node : nil )
42- receiver = call_node . receiver
38+ sig { params ( node : Prism ::CallNode ) . void }
39+ def handle_active_record_where_completions ( node )
40+ receiver = T . must ( @node_context . call_node ) . receiver
4341 return if receiver . nil?
4442 return unless receiver . is_a? ( Prism ::ConstantReadNode )
4543
4644 resolved_class = @client . model ( receiver . name . to_s )
4745 return if resolved_class . nil?
4846
49- arguments = call_node . arguments &.arguments
47+ arguments = T . must ( @node_context . call_node ) . arguments &.arguments
5048 existing_args = T . let ( { } , T ::Hash [ String , T ::Boolean ] )
5149
5250 if arguments &.is_a? ( Array )
53- return if current_node && current_node_is_argument_value? ( current_node : current_node , arguments : arguments )
51+ return if node_is_argument_value? ( node : node , arguments : arguments )
5452
5553 existing_args = get_call_node_arguments ( arguments : arguments )
5654 end
5755
5856 resolved_class [ :columns ] . each do |column |
59- next if current_node && ! column [ 0 ] . start_with? ( current_node . name . to_s )
57+ next unless column [ 0 ] . start_with? ( node . name . to_s )
6058 next if existing_args [ column [ 0 ] ]
6159
62- if current_node
63- location = current_node . location
64- range = Interface ::Range . new (
65- start : Interface ::Position . new (
66- line : location . start_line - 1 ,
67- character : location . start_column ,
68- ) ,
69- end : Interface ::Position . new ( line : location . end_line - 1 , character : location . end_column ) ,
70- )
71- else
72- location = call_node . location
73- # unclear how to calculate location in this scenario
74- range = Interface ::Range . new (
75- start : Interface ::Position . new (
76- line : location . start_line - 1 ,
77- character : 0 ,
78- ) ,
79- end : Interface ::Position . new ( line : location . end_line - 1 , character : 0 ) ,
80- )
81-
82- end
83-
8460 @response_builder << Interface ::CompletionItem . new (
8561 label : column [ 0 ] ,
8662 filter_text : column [ 0 ] ,
8763 label_details : Interface ::CompletionItemLabelDetails . new (
8864 description : "Filter #{ receiver . name } records by #{ column [ 0 ] } " ,
8965 ) ,
90- text_edit : Interface ::TextEdit . new ( range : range , new_text : "#{ column [ 0 ] } : " ) ,
66+ text_edit : Interface ::TextEdit . new ( range : range_from_location ( node . location ) , new_text : "#{ column [ 0 ] } : " ) ,
9167 kind : Constant ::CompletionItemKind ::FIELD ,
9268 )
9369 end
9470 end
9571
96- sig { params ( current_node : Prism ::Node , arguments : T ::Array [ Prism ::Node ] ) . returns ( T ::Boolean ) }
97- def current_node_is_argument_value? ( current_node :, arguments :)
72+ sig { params ( node : Prism ::Node , arguments : T ::Array [ Prism ::Node ] ) . returns ( T ::Boolean ) }
73+ def node_is_argument_value? ( node :, arguments :)
9874 arguments . any? do |argument |
9975 next unless argument . is_a? ( Prism ::KeywordHashNode )
10076
@@ -103,7 +79,7 @@ def current_node_is_argument_value?(current_node:, arguments:)
10379
10480 value = e . value
10581 if value . is_a? ( Prism ::CallNode )
106- value == current_node
82+ value == node
10783 end
10884 end
10985 end
0 commit comments