Module: Requests::TextDocument::Completion

Extended by:
Completion
Included in:
Completion
Defined in:
lib/holistic/language_server/requests/text_document/completion.rb

Defined Under Namespace

Modules: CompletionKind

Instance Method Summary collapse

Instance Method Details

#call(request) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/holistic/language_server/requests/text_document/completion.rb', line 7

def call(request)
  cursor = build_cursor_from_request_params(request)

  document = request.application.unsaved_documents.find(cursor.file_path)

  if document.nil?
    ::Holistic.logger.info("aborting completion because document was not found for #{cursor.file_path}")

    return request.respond_with(nil) 
  end

  if document.has_unsaved_changes?
    ::Holistic::Ruby::Parser::LiveEditing::ProcessFileChanged.call(
      application: request.application,
      file_path: document.path,
      content: document.content
    )
  end

  code = document.expand_code(cursor)

  if code.blank?
    ::Holistic.logger.info("aborting completion because code under cursor was blank: #{cursor.inspect}")

    return request.respond_with(nil)
  end

  scope = request.application.scopes.find_inner_most_scope_by_cursor(cursor) || request.application.scopes.root

  ::Holistic.logger.info("scope under cursor is: #{scope.fully_qualified_name}")

  suggestions = ::Holistic::Ruby::Autocompletion::Suggest.call(code:, scope:)

  respond_with_suggestions(request, suggestions)
end