-
Notifications
You must be signed in to change notification settings - Fork 135
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] Implement boilerplate add-on code #2088
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8dac3a4
Add ruby-lsp and ruby-lsp-rails to Gemfile for add-on development
KaanOzkan 3ee179c
Add requires to generate ruby-lsp related RBIs
vinistock 876469a
Generate gem RBIs
KaanOzkan 6c57bbf
Prevent re-definition error for source URI
vinistock 0bda321
Add add-on boiler plate
KaanOzkan 0bb1961
Add ServerAddon boilerplate
KaanOzkan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
RubyLsp::Addon.depend_on_ruby_lsp!(">= 0.22.1", "< 0.23") | ||
|
||
begin | ||
# The Tapioca add-on depends on the Rails add-on to add a runtime component to the runtime server. We can allow the | ||
# add-on to work outside of a Rails context in the future, but that may require Tapioca spawning its own runtime | ||
# server | ||
require "ruby_lsp/ruby_lsp_rails/runner_client" | ||
rescue LoadError | ||
return | ||
end | ||
|
||
module RubyLsp | ||
module Tapioca | ||
class Addon < ::RubyLsp::Addon | ||
extend T::Sig | ||
|
||
sig { void } | ||
def initialize | ||
super | ||
|
||
@global_state = T.let(nil, T.nilable(RubyLsp::GlobalState)) | ||
@rails_runner_client = T.let(nil, T.nilable(RubyLsp::Rails::RunnerClient)) | ||
end | ||
|
||
sig { override.params(global_state: RubyLsp::GlobalState, outgoing_queue: Thread::Queue).void } | ||
def activate(global_state, outgoing_queue) | ||
@global_state = global_state | ||
return unless @global_state.enabled_feature?(:tapiocaAddon) | ||
|
||
Thread.new do | ||
# Get a handle to the Rails add-on's runtime client. The call to `rails_runner_client` will block this thread | ||
# until the server has finished booting, but it will not block the main LSP. This has to happen inside of a | ||
# thread | ||
addon = T.cast(::RubyLsp::Addon.get("Ruby LSP Rails", ">= 0.3.17", "< 0.4"), ::RubyLsp::Rails::Addon) | ||
@rails_runner_client = addon.rails_runner_client | ||
outgoing_queue << Notification.window_log_message("Activating Tapioca add-on v#{version}") | ||
@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 | ||
end | ||
end | ||
|
||
sig { override.void } | ||
def deactivate | ||
end | ||
|
||
sig { override.returns(String) } | ||
def name | ||
"Tapioca" | ||
end | ||
|
||
sig { override.returns(String) } | ||
def version | ||
"0.1.0" | ||
end | ||
|
||
sig { params(changes: T::Array[{ uri: String, type: Integer }]).void } | ||
def workspace_did_change_watched_files(changes) | ||
return unless T.must(@global_state).enabled_feature?(:tapiocaAddon) | ||
return unless @rails_runner_client # Client is not ready | ||
|
||
nil | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# typed: false | ||
# frozen_string_literal: true | ||
|
||
require "tapioca/internal" | ||
|
||
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) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,9 +25,6 @@ class Source < URI::File | |
# have the uri gem in their own bundle and thus not use a compatible version. | ||
PARSER = T.let(const_defined?(:RFC2396_PARSER) ? RFC2396_PARSER : DEFAULT_PARSER, RFC2396_Parser) | ||
|
||
alias_method(:gem_name, :host) | ||
alias_method(:line_number, :fragment) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Causes re-definition error for source URI |
||
|
||
sig { returns(T.nilable(String)) } | ||
attr_reader :gem_version | ||
|
||
|
@@ -54,6 +51,16 @@ def build(gem_name:, gem_version:, path:, line_number:) | |
end | ||
end | ||
|
||
sig { returns(T.nilable(String)) } | ||
def gem_name | ||
host | ||
end | ||
|
||
sig { returns(T.nilable(String)) } | ||
def line_number | ||
fragment | ||
end | ||
|
||
sig { params(v: T.nilable(String)).void } | ||
def set_path(v) # rubocop:disable Naming/AccessorMethodName | ||
return if v.nil? | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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)