Sha256: db6b04a90ebf467451f2a048b6477705e33f9ba2958f9e5c121e7541c74022d3

Contents?: true

Size: 835 Bytes

Versions: 4

Compression:

Stored size: 835 Bytes

Contents

module Yoda
  module Cli
    # Provide parsing methods of positon representation with the format `path/to/file:line_num:character_num`
    module FileCursorParsable
      private

      # Returns a cursor literal to parse.
      # @abstract
      # @return [String]
      def filename_with_position
        fail NotImplementedError
      end

      # @return [String, nil] represents the filename part.
      def filename
        @filename ||= filename_with_position.split(':').first
      end

      # Parse location part of cursor literal and returns the parsed location.
      # @return [Parsing::Location]
      def position
        @position ||= begin
          row, column = filename_with_position.split(':').slice(1..2)
          Parsing::Location.new(row: row.to_i, column: column.to_i)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
yoda-language-server-0.10.1 lib/yoda/cli/file_cursor_parsable.rb
yoda-language-server-0.10.0 lib/yoda/cli/file_cursor_parsable.rb
yoda-language-server-0.9.0 lib/yoda/cli/file_cursor_parsable.rb
yoda-language-server-0.8.0 lib/yoda/cli/file_cursor_parsable.rb