In Files

  • typeprof-0.21.2/lib/typeprof/lsp.rb

Class/Module Index [+]

Quicksearch

TypeProf::LSP

Constants

CompletionSession

Public Instance Methods

code_complete(loc, trigger_kind) click to toggle source
 
               # File typeprof-0.21.2/lib/typeprof/lsp.rb, line 159
def code_complete(loc, trigger_kind)
  case loc
  in { line: row, character: col }
  end
  unless row < @text.lines.length && col >= 1 && @text.lines[row][0, col] =~ /\.\w*$/
    return nil
  end
  start_offset = $~.begin(0)
  end_offset = $&.size

  case trigger_kind
  when LSP::CompletionTriggerKind::TRIGGER_FOR_INCOMPLETE_COMPLETIONS
    unless @current_completion_session&.reusable?(row, start_offset)
      puts "no reusable completion session but got TRIGGER_FOR_INCOMPLETE_COMPLETIONS"
      @current_completion_session = new_code_completion_session(row, start_offset, end_offset)
    end
    return @current_completion_session.results
  else
    @current_completion_session = new_code_completion_session(row, start_offset, end_offset)
    return @current_completion_session&.results
  end
end
            
new_code_completion_session(row, start_offset, end_offset) click to toggle source
 
               # File typeprof-0.21.2/lib/typeprof/lsp.rb, line 141
def new_code_completion_session(row, start_offset, end_offset)
  lines = @text.lines
  lines[row][start_offset, end_offset] = ".__typeprof_lsp_completion"
  tmp_text = lines.join
  res, = analyze(@uri, tmp_text)
  if res && res[:completion]
    results = res[:completion].keys.map do |name|
      {
        label: name,
        kind: 2, # Method
      }
    end
    return CompletionSession.new(results, row, start_offset)
  else
    nil
  end
end
            
There is an updated format of the API docs for this version here.