Sha256: 9e41ac52c75de1a2b42acd4e48730b8966fd3212cf8f91d8cf3687fdf0556768

Contents?: true

Size: 1.25 KB

Versions: 82

Compression:

Stored size: 1.25 KB

Contents

module Steep
  module Services
    class ContentChange
      class Position
        attr_reader :line, :column

        def initialize(line:, column:)
          @line = line
          @column = column
        end

        def ==(other)
          other.is_a?(Position) && other.line == line && other.column == column
        end

        alias eql? ==

        def hash
          self.class.hash ^ line ^ column
        end
      end

      attr_reader :range, :text

      def initialize(range: nil, text:)
        @range = range
        @text = text
      end

      def ==(other)
        other.is_a?(ContentChange) && other.range == range && other.text == text
      end

      alias eql? ==

      def hash
        self.class.hash ^ range.hash ^ text.hash
      end

      def self.string(string)
        new(text: string)
      end

      def apply_to(text)
        if range
          text = text.dup
          start_pos, end_pos = range

          buf = RBS::Buffer.new(name: :_, content: text)
          start_pos = buf.loc_to_pos([start_pos.line, start_pos.column])
          end_pos = buf.loc_to_pos([end_pos.line, end_pos.column])

          text[start_pos...end_pos] = self.text
          text
        else
          self.text
        end
      end
    end
  end
end

Version data entries

82 entries across 82 versions & 3 rubygems

Version Path
steep-1.10.0 lib/steep/services/content_change.rb
steep-1.10.0.pre.3 lib/steep/services/content_change.rb
steep-1.10.0.pre.2 lib/steep/services/content_change.rb
steep-1.10.0.pre.1 lib/steep/services/content_change.rb
steep-1.10.0.dev.1 lib/steep/services/content_change.rb
steep-relaxed-1.9.4.3 lib/steep/services/content_change.rb
steep-relaxed-1.9.3.3 lib/steep/services/content_change.rb
steep-activesupport-4-1.9.4 lib/steep/services/content_change.rb
steep-activesupport-4-1.9.3.1 lib/steep/services/content_change.rb
steep-1.9.4 lib/steep/services/content_change.rb
steep-activesupport-4-1.9.3 lib/steep/services/content_change.rb
steep-1.9.3 lib/steep/services/content_change.rb
steep-1.9.2 lib/steep/services/content_change.rb
steep-1.9.1 lib/steep/services/content_change.rb
steep-1.9.0 lib/steep/services/content_change.rb
steep-1.9.0.dev.2 lib/steep/services/content_change.rb
steep-1.9.0.dev.1 lib/steep/services/content_change.rb
steep-1.8.3 lib/steep/services/content_change.rb
steep-1.8.2 lib/steep/services/content_change.rb
steep-1.8.1 lib/steep/services/content_change.rb