Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reloading for schema changes #282

Merged
merged 1 commit into from
Mar 6, 2024

Conversation

andyw8
Copy link
Contributor

@andyw8 andyw8 commented Mar 6, 2024

This change goes along with Shopify/ruby-lsp#1464 in ruby-lsp.

Partly addresses #257

We register for changes to the schema files, and trigger a reload so as to get the latest column information. (Using the same mechanism that reload! in the Rails console uses).

@@ -215,10 +215,6 @@ def hover_on_source(source, position)
assert_nil(response.error)
response.response
end

def dummy_root
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move into test_helper so that we can share.

sig { params(changes: T::Array[{ uri: String, type: Integer }]).void }
def workspace_did_change_watched_files(changes)
if changes.any? do |change|
change[:uri].end_with?("db/schema.rb") || change[:uri].end_with?("structure.sql")
Copy link
Contributor Author

@andyw8 andyw8 Mar 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally we would only have to support db/structure.sql but in Shopify/shopify we have additional structure files.

def trigger_reload
warn("Reloading Rails application...")
send_notification("reload")
warn("Reloading Rails application complete")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vinistock I realised it might be better to remove the second warn here, since that call is asynchronous?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. We can either remove it or turn the notification into a request and just return an OK from the server.

IMO, I'd go with the former. No need for extra complexity.

@andyw8 andyw8 force-pushed the andyw8/add-reloading-for-schema-changes branch from ee951f7 to 7ceefbb Compare March 6, 2024 18:20
@andyw8 andyw8 marked this pull request as ready for review March 6, 2024 18:22
@andyw8 andyw8 requested a review from a team as a code owner March 6, 2024 18:22
warn("Reloading Rails application")
send_notification("reload")
rescue IncompleteMessageError
warn("Ruby LSP Rails failed to get model information: #{@stderr.read}")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will correct this message.

@andyw8 andyw8 force-pushed the andyw8/add-reloading-for-schema-changes branch from 7ceefbb to 5f93af0 Compare March 6, 2024 18:23
@andyw8 andyw8 merged commit 27f3e56 into main Mar 6, 2024
54 checks passed
@andyw8 andyw8 deleted the andyw8/add-reloading-for-schema-changes branch March 6, 2024 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants