Class: RubyLsp::Requests::Support::RailsDocumentClient

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/ruby_lsp/requests/support/rails_document_client.rb

Constant Summary collapse

RAILS_DOC_HOST =
"https://api.rubyonrails.org"
SUPPORTED_RAILS_DOC_NAMESPACES =
T.let(
  Regexp.union(
    /ActionDispatch/,
    /ActionController/,
    /AbstractController/,
    /ActiveRecord/,
    /ActiveModel/,
    /ActiveStorage/,
    /ActionText/,
    /ActiveJob/,
  ).freeze,
  Regexp,
)
RAILTIES_VERSION =
T.let(
  [*::Gem::Specification.default_stubs, *::Gem::Specification.stubs].find do |s|
    s.name == "railties"
  end&.version&.to_s,
  T.nilable(String),
)

Class Method Summary collapse

Class Method Details

.generate_rails_document_urls(name) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ruby_lsp/requests/support/rails_document_client.rb', line 37

def generate_rails_document_urls(name)
  docs = search_index&.fetch(name, nil)

  return [] unless docs

  docs.map do |doc|
    owner = doc[:owner]

    link_name =
      # class/module name
      if owner == name
        name
      else
        "#{owner}##{name}"
      end

    "[Rails Document: `#{link_name}`](#{doc[:url]})"
  end
end