Sha256: f0fe6755df96c109bb47a528da0bbd607a1e074880a372a4494f088751cd4cef

Contents?: true

Size: 1.31 KB

Versions: 16

Compression:

Stored size: 1.31 KB

Contents

module Rsense
  module Server
    class Code
      attr_accessor :lines
      TYPE_INFERENCE_METHOD_NAME = Rsense::Server::Command::TYPE_INFERENCE_METHOD_NAME
      FIND_DEFINITION_METHOD_NAME_PREFIX = Rsense::Server::Command::FIND_DEFINITION_METHOD_NAME_PREFIX

      def initialize(code_str)
        @lines = code_str.split("\n")
      end

      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

      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

    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
rsense-server-0.5.18 lib/rsense/server/code.rb
rsense-server-0.5.17 lib/rsense/server/code.rb
rsense-server-0.5.16 lib/rsense/server/code.rb
rsense-server-0.5.15 lib/rsense/server/code.rb
rsense-server-0.5.14 lib/rsense/server/code.rb
rsense-server-0.5.13 lib/rsense/server/code.rb
rsense-server-0.5.12 lib/rsense/server/code.rb
rsense-server-0.5.11 lib/rsense/server/code.rb
rsense-server-0.5.10 lib/rsense/server/code.rb
rsense-server-0.5.9 lib/rsense/server/code.rb
rsense-server-0.5.8 lib/rsense/server/code.rb
rsense-server-0.5.7 lib/rsense/server/code.rb
rsense-server-0.5.6 lib/rsense/server/code.rb
rsense-server-0.5.5 lib/rsense/server/code.rb
rsense-server-0.5.4 lib/rsense/server/code.rb
rsense-server-0.5.2 lib/rsense/server/code.rb