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

[Tapioca add-on] Add ServerAddon boilerplate #2035

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ Sorbet/TrueSigil:
Include:
- "**/*.rb"
- "**/*.rake"
Exclude:
- "lib/ruby_lsp/tapioca/server_addon.rb"
Copy link
Contributor Author

@KaanOzkan KaanOzkan Oct 7, 2024

Choose a reason for hiding this comment

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

Following the discussion on Shopify/ruby-lsp-rails#469 (comment). I'd like to somehow ensure sigs don't get added to the file in the future.


Style/CaseEquality:
Enabled: false
Expand Down
10 changes: 6 additions & 4 deletions lib/ruby_lsp/tapioca/addon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
return
end

require "tapioca/internal"

module RubyLsp
module Tapioca
class Addon < ::RubyLsp::Addon
Expand All @@ -40,6 +38,7 @@ def activate(global_state, outgoing_queue)
# thread
addon = T.cast(::RubyLsp::Addon.get("Ruby LSP Rails", ">= 0.3.18", "< 0.4"), ::RubyLsp::Rails::Addon)
@rails_runner_client = addon.rails_runner_client
@rails_runner_client.register_server_addon(File.expand_path("server_addon.rb", __dir__))
rescue IncompatibleApiError
# The requested version for the Rails add-on no longer matches. We need to upgrade and fix the breaking
# changes
Expand All @@ -62,6 +61,9 @@ def version

sig { params(changes: T::Array[{ uri: String, type: Integer }]).void }
def workspace_did_change_watched_files(changes)
return unless T.must(@global_state).experimental_features
return unless @rails_runner_client # Client is not ready
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I personally prefer multiple unless calls over combining them and thinking of De Morgan's Laws 😬


constants = changes.flat_map do |change|
path = URI(change[:uri]).to_standardized_path
entries = T.must(@index).entries_for(path)
Expand All @@ -74,8 +76,8 @@ def workspace_did_change_watched_files(changes)

return if constants.empty?

T.must(@rails_runner_client).trigger_reload
T.must(@rails_runner_client).delegate_notification(
@rails_runner_client.trigger_reload
@rails_runner_client.delegate_notification(
server_addon_name: "Tapioca",
request_name: "dsl",
params: { constants: constants },
Expand Down
27 changes: 27 additions & 0 deletions lib/ruby_lsp/tapioca/server_addon.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# typed: false
# frozen_string_literal: true

require "tapioca/internal"
vinistock marked this conversation as resolved.
Show resolved Hide resolved

module RubyLsp
module Tapioca
class ServerAddon < ::RubyLsp::Rails::ServerAddon
def name
"Tapioca"
end

def execute(request, params)
case request
when "dsl"
dsl(params)
end
end

private

def dsl(params)
# TODO
end
end
end
end
86 changes: 86 additions & 0 deletions sorbet/rbi/gems/[email protected]

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sorbet/tapioca/require.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
require "ruby_lsp/internal"
require "ruby_lsp/test_helper"
require "ruby_lsp/ruby_lsp_rails/addon"
require "ruby_lsp/ruby_lsp_rails/server"
require "rbs"
Loading