Class: Rubydex::MCPServer::FindConstantReferencesTool

Inherits:
BaseTool
  • Object
show all
Defined in:
lib/rubydex/mcp_server/tools/find_constant_references_tool.rb

Constant Summary

Constants inherited from BaseTool

BaseTool::DEFAULT_LIMIT

Instance Method Summary collapse

Methods inherited from BaseTool

#declaration_kind, #display_location, #document_for_path, #file_path_for_uri, #format_path, #initialize, #lookup_declaration, #paginate, #response

Methods inherited from Tool

description, inherited, input_schema, to_h, tool_name, tools_by_name

Constructor Details

This class inherits a constructor from Rubydex::MCPServer::BaseTool

Instance Method Details

#call(name:, limit: nil, offset: nil) ⇒ Object

: (name: String, ?limit: Integer, ?offset: Integer) -> Tool::Response



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rubydex/mcp_server/tools/find_constant_references_tool.rb', line 18

def call(name:, limit: nil, offset: nil)
  declaration = lookup_declaration(name)

  case declaration
  when Error
    response(declaration)
  else
    references = case declaration
    when Rubydex::Namespace, Rubydex::Constant, Rubydex::ConstantAlias
      declaration.references
    else
      []
    end
    page, total = paginate(references, offset, limit, 200)
    payload = page.map do |reference|
      display = reference.location.to_display
      {
        path: format_path(display.uri),
        line: display.start_line,
        column: display.start_column,
      }
    end

    response(name: name, references: payload, total: total)
  end
end