Module: RubyLsp::Mongoid::SignatureResolver

Included in:
Addon
Defined in:
lib/ruby_lsp/ruby_lsp_mongoid/signature_resolver.rb

Overview

Resolves method signatures from Mongoid modules in the Ruby LSP index. Used to update method signatures after initial indexing is complete.

Constant Summary collapse

INSTANCE_METHOD_SOURCES =

Mongoid modules that provide instance methods

[
  "Mongoid::Persistable::Savable",
  "Mongoid::Persistable::Updatable",
  "Mongoid::Persistable::Deletable",
  "Mongoid::Persistable::Destroyable",
  "Mongoid::Persistable::Upsertable",
  "Mongoid::Attributes",
  "Mongoid::Reloadable",
  "Mongoid::Stateful",
  "Mongoid::Changeable",
  "Mongoid::Inspectable",
].freeze
CLASS_METHOD_SOURCES =

Mongoid modules that provide class methods

[
  "Mongoid::Findable",
  "Mongoid::Criteria",
  "Mongoid::Persistable::Creatable::ClassMethods",
  "Mongoid::Clients::Sessions::ClassMethods",
].freeze
CORE_INSTANCE_METHODS =

Core instance methods to look up signatures for

%w[
  save save! update update! destroy delete upsert reload
  new_record? persisted? valid? changed?
  attributes attributes= assign_attributes read_attribute write_attribute
  changes errors to_key to_param model_name inspect
].freeze
CORE_CLASS_METHODS =

Core class methods to look up signatures for

%w[
  all where find find_by find_by! first last count exists? distinct
  create create! new build update_all delete_all destroy_all
  collection database
].freeze

Instance Method Summary collapse

Instance Method Details

#resolve_class_method_signature(index, method_name) ⇒ Array<RubyIndexer::Entry::Signature>?

Resolve class method signature from Mongoid modules

Parameters:

  • index (RubyIndexer::Index) —

    Ruby LSP index

  • method_name (String) —

    Method name to look up

Returns:

  • (Array<RubyIndexer::Entry::Signature>, nil) —

    Signatures or nil if not found



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/ruby_lsp/ruby_lsp_mongoid/signature_resolver.rb', line 65

def resolve_class_method_signature(index, method_name)
  CLASS_METHOD_SOURCES.each do |module_name|
    entries = index.resolve_method(method_name, module_name)
    next unless entries&.any?

    entry = entries.first
    return entry.signatures if entry.respond_to?(:signatures) && entry.signatures.any?
  end

  nil
end

#resolve_instance_method_signature(index, method_name) ⇒ Array<RubyIndexer::Entry::Signature>?

Resolve instance method signature from Mongoid modules

Parameters:

  • index (RubyIndexer::Index) —

    Ruby LSP index

  • method_name (String) —

    Method name to look up

Returns:

  • (Array<RubyIndexer::Entry::Signature>, nil) —

    Signatures or nil if not found



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ruby_lsp/ruby_lsp_mongoid/signature_resolver.rb', line 49

def resolve_instance_method_signature(index, method_name)
  INSTANCE_METHOD_SOURCES.each do |module_name|
    entries = index.resolve_method(method_name, module_name)
    next unless entries&.any?

    entry = entries.first
    return entry.signatures if entry.respond_to?(:signatures) && entry.signatures.any?
  end

  nil
end