Skip to content

Commit d649d69

Browse files
committed
Fix incorrect return type in Walker.normalize_ast
As of Solargraph 0.51.0, I started hitting exceptions from walker.rb like this: ``` [WARN] wrong number of arguments (given 3, expected 1..2) .../solargraph-rails/lib/solargraph/rails/walker.rb:78:in `initialize' /Users/broz/src/solargraph-rails/lib/solargraph/rails/walker.rb:67:in `new' /Users/broz/src/solargraph-rails/lib/solargraph/rails/walker.rb:67:in `from_source' /Users/broz/src/solargraph-rails/lib/solargraph/rails/model.rb:15:in `process' /Users/broz/src/solargraph-rails/lib/solargraph-rails.rb:48:in `block in local' /Users/broz/src/solargraph-rails/lib/solargraph-rails.rb:61:in `run_feature' /Users/broz/src/solargraph-rails/lib/solargraph-rails.rb:48:in `local' /Users/broz/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/solargraph-0.51.0/lib/solargraph/convention.rb:28:in `block in for_local' /Users/broz/.rbenv/versions/3.1.6/lib/ruby/3.1.0/set.rb:511:in `each_key' /Users/broz/.rbenv/versions/3.1.6/lib/ruby/3.1.0/set.rb:511:in `each' /Users/broz/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/solargraph-0.51.0/lib/solargraph/convention.rb:27:in `for_local' /Users/broz/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/solargraph-0.51.0/lib/solargraph/source_map.rb:32:in `initialize' /Users/broz/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/solargraph-0.51.0/lib/solargraph/source_map.rb:158:in `new' /Users/broz/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/solargraph-0.51.0/lib/solargraph/source_map.rb:158:in `map' /Users/broz/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/solargraph-0.51.0/lib/solargraph/api_map.rb:54:in `map' /Users/broz/src/solargraph-rails/spec/helpers.rb:4:in `load_string' /Users/broz/src/solargraph-rails/spec/solargraph-rails/model_spec.rb:80:in `block (3 levels) in <top (required)>' ``` It looks like it happens in cases where Solargraph's source.node is a ::Parser::AST::Node. There's a special case in Walker.normalize_ast() that is triggering that does not look correct on its face - it should always return an array of nodes, since the result is splatted in Walker.from_source. The spec added reproduces this in newer solargraphs.
1 parent 144cec0 commit d649d69

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/solargraph/rails/walker.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def self.normalize_ast(source)
5454
ast = source.node
5555

5656
if ast.is_a?(::Parser::AST::Node)
57-
ast
57+
[ast]
5858
else
5959
NodeParser.parse_with_comments(source.code, source.filename)
6060
end

spec/solargraph-rails/model_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ class Transaction < ActiveRecord::Base
7575
assert_class_method(api_map, 'Transaction.positive', ['Class<Transaction>'])
7676
end
7777

78+
it 'handles primary_abstract_class without breaking' do
79+
expect do
80+
load_string 'app/models/application_record.rb',
81+
<<-RUBY
82+
class ApplicationRecord < ActiveRecord::Base
83+
primary_abstract_class
84+
end
85+
RUBY
86+
end.not_to raise_error
87+
end
88+
7889
it 'generates scope methods with parameters' do
7990
load_string 'app/models/person.rb',
8091
<<-RUBY

0 commit comments

Comments
 (0)