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

Remove Rails doc DSL hover #472

Merged
merged 1 commit into from
Oct 3, 2024
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
25 changes: 1 addition & 24 deletions lib/ruby_lsp/ruby_lsp_rails/hover.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# typed: strict
# frozen_string_literal: true

require_relative "support/rails_document_client"

module RubyLsp
module Rails
# ![Hover demo](../../hover.gif)
Expand Down Expand Up @@ -34,7 +32,7 @@ def initialize(client, response_builder, node_context, global_state, dispatcher)
@response_builder = response_builder
@nesting = T.let(node_context.nesting, T::Array[String])
@index = T.let(global_state.index, RubyIndexer::Index)
dispatcher.register(self, :on_constant_path_node_enter, :on_constant_read_node_enter, :on_call_node_enter)
dispatcher.register(self, :on_constant_path_node_enter, :on_constant_read_node_enter)
end

sig { params(node: Prism::ConstantPathNode).void }
Expand All @@ -43,10 +41,7 @@ def on_constant_path_node_enter(node)
return unless entries

name = T.must(entries.first).name

generate_column_content(name)

generate_rails_document_link_hover(name, node.location)
end

sig { params(node: Prism::ConstantReadNode).void }
Expand All @@ -57,16 +52,6 @@ def on_constant_read_node_enter(node)
generate_column_content(T.must(entries.first).name)
end

sig { params(node: Prism::CallNode).void }
def on_call_node_enter(node)
message_value = node.message
message_loc = node.message_loc

return unless message_value && message_loc

generate_rails_document_link_hover(message_value, message_loc)
end

private

sig { params(name: String).void }
Expand All @@ -89,14 +74,6 @@ def generate_column_content(name)
category: :documentation,
)
end

sig { params(name: String, location: Prism::Location).void }
def generate_rails_document_link_hover(name, location)
urls = Support::RailsDocumentClient.generate_rails_document_urls(name)
return if urls.empty?

@response_builder.push(urls.join("\n\n"), category: :links)
end
end
end
end
131 changes: 0 additions & 131 deletions lib/ruby_lsp/ruby_lsp_rails/support/rails_document_client.rb

This file was deleted.

1 change: 0 additions & 1 deletion test/fixtures/search_index.js

This file was deleted.

56 changes: 0 additions & 56 deletions test/ruby_lsp_rails/hover_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,6 @@
module RubyLsp
module Rails
class HoverTest < ActiveSupport::TestCase
setup do
body = File.read("#{__dir__}/../../test/fixtures/search_index.js")
stub_request(:get, %r{https://api\.rubyonrails\.org/v.*/js/search_index\.js})
.with(
headers: {
"Host" => "api.rubyonrails.org",
"User-Agent" => %r{^ruby-lsp-rails\/.*$},
},
)
.to_return(status: 200, body: body, headers: {})

# Build the Rails documents index ahead of time
capture_io do
Support::RailsDocumentClient.send(:search_index)
end
end

test "hook returns model column information" do
expected_response = {
schema_file: "#{dummy_root}/db/schema.rb",
Expand Down Expand Up @@ -201,45 +184,6 @@ class User < ApplicationRecord
refute_match(/Schema/, response.contents.value)
end

test "shows documentation for routes DSLs" do
value = hover_on_source("root 'projects#index'", { line: 0, character: 0 }).contents.value

assert_match(/\[Rails Document: `ActionDispatch::Routing::Mapper::Resources#root`\]/, value)
assert_match(%r{\(https://api\.rubyonrails\.org/.*\.html#method-i-root\)}, value)
end

test "shows documentation for controller DSLs" do
value = hover_on_source("before_action :foo", { line: 0, character: 0 }).contents.value

assert_match(/\[Rails Document: `AbstractController::Callbacks::ClassMethods#before_action`\]/, value)
assert_match(%r{\(https://api\.rubyonrails\.org/.*\.html#method-i-before_action\)}, value)
end

test "shows documentation for job DSLs" do
value = hover_on_source("queue_as :default", { line: 0, character: 0 }).contents.value

assert_match(/\[Rails Document: `ActiveJob::QueueName::ClassMethods#queue_as`\]/, value)
assert_match(%r{\(https://api\.rubyonrails\.org/.*\.html#method-i-queue_as\)}, value)
end

test "shows documentation for model DSLs" do
value = hover_on_source("validate :foo", { line: 0, character: 0 }).contents.value

assert_match(/\[Rails Document: `ActiveModel::EachValidator#validate`\]/, value)
assert_match(%r{\(https://api\.rubyonrails\.org/.*\.html#method-i-validate\)}, value)
end

test "shows documentation for Rails constants" do
value = hover_on_source(<<~RUBY, { line: 2, character: 14 }).contents.value
class ActiveRecord::Base
end
ActiveRecord::Base
RUBY

assert_match(/\[Rails Document: `ActiveRecord::Base`\]/, value)
assert_match(%r{\(https://api\.rubyonrails\.org/.*Base\.html\)}, value)
end

private

def hover_on_source(source, position)
Expand Down
Loading