Module: Requests::TextDocument::GoToDefinition

Extended by:
GoToDefinition
Included in:
GoToDefinition
Defined in:
lib/holistic/language_server/requests/text_document/go_to_definition.rb

Overview

Instance Method Summary collapse

Instance Method Details

#call(request) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/holistic/language_server/requests/text_document/go_to_definition.rb', line 8

def call(request)
  cursor = build_cursor_from_params(request)

  request.application.unsaved_documents.find(cursor.file_path)&.then do |unsaved_document|
    if unsaved_document.has_unsaved_changes?
      ::Holistic::Ruby::Parser::LiveEditing::ProcessFileChanged.call(
        application: request.application,
        file_path: unsaved_document.path,
        content: unsaved_document.content
      )
    end
  end

  case ::Holistic::Ruby::Reference::FindReferencedScope.call(application: request.application, cursor:)
  in :not_found
    request.respond_with(nil)
  in :could_not_find_referenced_scope
    request.respond_with(nil)
  in [:referenced_scope_found, {reference:, referenced_scope:}]
    respond_with_location_link(request, reference, referenced_scope)
  end
end