class Rsense::Server::Code

Constants

FIND_DEFINITION_METHOD_NAME_PREFIX
TYPE_INFERENCE_METHOD_NAME

Attributes

lines[RW]

Public Class Methods

new(code_str) click to toggle source
# File lib/rsense/server/code.rb, line 8
def initialize(code_str)
  @lines = code_str.split("\n")
end

Public Instance Methods

inject_definition_marker(injection, location) click to toggle source
# File lib/rsense/server/code.rb, line 28
def inject_definition_marker(injection, location)
  row = location["row"] - 1
  column = location["column"] - 1
  lines = @lines.clone
  line = lines[row]
  match = line.slice(0, column).match(/.*(?:\.|::|\s)(\w+?[!?]?)/)
  start = match.end(0)
  line.insert(start - 1, injection)
  lines.join("\n")
end
inject_inference_marker(location) click to toggle source
# File lib/rsense/server/code.rb, line 12
def inject_inference_marker(location)
  row = location["row"] - 1
  column = location["column"] - 1
  lines = @lines.clone
  line = lines[row]
  return lines.join("\n") unless line && line.length >= column - 1 && column > 1
  if line.slice(column - 1).end_with?(".")
    line.insert(column, TYPE_INFERENCE_METHOD_NAME)
  elsif line.slice(column - 2..column - 1).end_with?("::")
    line.insert(column, TYPE_INFERENCE_METHOD_NAME)
  else
    line.insert(column, ".#{TYPE_INFERENCE_METHOD_NAME}")
  end
  lines.join("\n")
end