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

Update for latest ruby-lsp changes #301

Merged
merged 5 commits into from
Apr 3, 2024
Merged

Conversation

andyw8
Copy link
Contributor

@andyw8 andyw8 commented Mar 22, 2024

Needed due to Shopify/ruby-lsp#1648

@andyw8 andyw8 force-pushed the andyw8/update-for-ruby-lsp-refactor branch 3 times, most recently from 629a067 to 9c5d892 Compare March 24, 2024 13:22
block: T.proc.params(server: RubyLsp::Server, uri: URI::Generic).returns(T.type_parameter(:T)),
).returns(T.type_parameter(:T))
end
def with_server(source = nil, uri = URI("file:///fake.rb"), &block)
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 copied this from ruby-lsp, but is this how you were expecting we'd structure the tests for addons?

Copy link
Member

Choose a reason for hiding this comment

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

Instead of copying, I think we should move this in the Ruby LSP to a file that's not required by default like lib/ruby_lsp/test_case and every addon can just require the file and inherit from a class to get our test helpers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, I can do that. One minor niggle is that we we see the "initializing" message on each test, e.g.:

ruby-lsp-rails andyw8/update-for-ruby-lsp-refactor % be rake test
Run options: --seed 14480

# Running:

....Finished initializing Ruby LSP!
Ruby LSP detected this is a Sorbet project so will defer to Sorbet LSP for some functionality
.Finished initializing Ruby LSP!
.Finished initializing Ruby LSP!
.Finished initializing Ruby LSP!
.Finished initializing Ruby LSP!
.Finished initializing Ruby LSP!
.Finished initializing Ruby LSP!
(etc)

I'll see if there's a way to silence that during the tests.

Copy link
Member

Choose a reason for hiding this comment

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

You'll need to capture_subprocess_io wherever we are executing the initialized notification.

@andyw8 andyw8 force-pushed the andyw8/update-for-ruby-lsp-refactor branch 5 times, most recently from 3b081ae to c7b77d2 Compare March 30, 2024 19:31
@andyw8 andyw8 force-pushed the andyw8/update-for-ruby-lsp-refactor branch 2 times, most recently from 6ab9137 to 1182623 Compare April 2, 2024 21:25
@andyw8 andyw8 force-pushed the andyw8/update-for-ruby-lsp-refactor branch from 1182623 to 343a974 Compare April 2, 2024 21:27
@andyw8 andyw8 changed the title WIP: Update for latest ruby-lsp changes Update for latest ruby-lsp changes Apr 2, 2024
@andyw8 andyw8 added the chore Chore task label Apr 2, 2024
@andyw8 andyw8 marked this pull request as ready for review April 2, 2024 21:28
@andyw8 andyw8 requested a review from a team as a code owner April 2, 2024 21:28
@andyw8 andyw8 requested review from st0012 and KaanOzkan April 2, 2024 21:28
dispatcher: Prism::Dispatcher,
).void
end
def create_hover_listener(response_builder, nesting, index, dispatcher)
def create_hover_listener(response_builder, nesting, dispatcher)
index = T.must(@global_state).index
Hover.new(@client, response_builder, nesting, index, dispatcher)
Copy link
Member

Choose a reason for hiding this comment

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

I think we can follow Ruby LSP on passing the global state into listeners instead of index? FWIW, I'll need to do it for CodeLens in order to fix the duplicated test code lens issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 updated

sig { override.params(global_state: GlobalState, message_queue: Thread::Queue).void }
def activate(global_state, message_queue)
@global_state = T.let(global_state, T.nilable(RubyLsp::GlobalState))
$stderr.puts("Activating Ruby LSP Rails addon v#{VERSION}") unless ENV["RAILS_ENV"] == "test"
Copy link
Member

Choose a reason for hiding this comment

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

I think these stderr silencing changes are not required for bumping Ruby LSP? I also remember @vinistock proposed a better way to handle these messages. Should we handle these in a more sophisticated way in a separate PR instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is actually a bit tricky, I've removed the conditionals for now and we can address in a separate PR.

Copy link
Member

@vinistock vinistock left a comment

Choose a reason for hiding this comment

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

I put up a PR to ensure we deactivate addons on with_server Shopify/ruby-lsp#1872. Otherwise, we spawn a bunch of runner clients and don't shut them down gracefully.

I think we can address the stderr printing in a separate PR, given that it needs to be addressed in the base LSP too.

lib/ruby_lsp/ruby_lsp_rails/hover.rb Outdated Show resolved Hide resolved
@andyw8 andyw8 enabled auto-merge (squash) April 3, 2024 14:25
@vinistock
Copy link
Member

Nevermind what I said, I was mistaken. We're already invoking deactivate manually in with_server and I missed it.

@andyw8 andyw8 merged commit 1e83430 into main Apr 3, 2024
54 checks passed
@andyw8 andyw8 deleted the andyw8/update-for-ruby-lsp-refactor branch April 3, 2024 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Chore task
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants