Skip to content

Commit e85a41b

Browse files
committed
Avoid inspecting schema info for abstract classes
Hovering on model classes like ApplicationRecord in a Rails application results in raising an ActiveRecord::TableNotSpecifiedError, which we should be accounting for. Before: ``` Started GET "/ruby_lsp_rails/models/ApplicationRecord" for ::1 at 2024-02-03 08:15:12 -0600 ActiveRecord::TableNotSpecified (ApplicationRecord has no table configured. Set one with ApplicationRecord.table_name=): ... ``` After: ``` Started GET "/ruby_lsp_rails/models/ApplicationRecord" for ::1 at 2024-02-03 08:17:35 -0600 ```
1 parent 5afb7a3 commit e85a41b

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/ruby_lsp_rails/rack_app.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def call(env)
3131
def resolve_database_info_from_model(model_name)
3232
const = ActiveSupport::Inflector.safe_constantize(model_name)
3333

34-
if const && const < ActiveRecord::Base
34+
if const && const < ActiveRecord::Base && !const.abstract_class?
3535
begin
3636
schema_file = ActiveRecord::Tasks::DatabaseTasks.schema_dump_path(const.connection.pool.db_config)
3737
rescue => e

test/ruby_lsp_rails/rack_app_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ class RackAppTest < ActionDispatch::IntegrationTest
3535
assert_response(:not_found)
3636
end
3737

38+
test "GET show returns not_found if class is an abstract model" do
39+
get "/ruby_lsp_rails/models/ApplicationRecord"
40+
assert_response(:not_found)
41+
end
42+
3843
test "GET activate returns success to display that server is running" do
3944
get "/ruby_lsp_rails/activate"
4045
assert_response(:success)

0 commit comments

Comments
 (0)