Sha256: 2eebbc1dd58e4693044e724038e55e4087c8f31e8b092e7ad3d31bc268a8a25d

Contents?: true

Size: 1.55 KB

Versions: 1

Compression:

Stored size: 1.55 KB

Contents

# frozen_string_literal: true

module PlatformosCheck
  module LanguageServer
    class DocumentLinkProvider
      include RegexHelpers
      include PositionHelper
      include URIHelper

      class << self
        attr_accessor :partial_regexp, :destination_directory, :destination_postfix

        def all
          @all ||= []
        end

        def inherited(subclass)
          all << subclass
        end
      end

      def initialize(storage = InMemoryStorage.new)
        @storage = storage
      end

      def partial_regexp
        self.class.partial_regexp
      end

      def destination_directory
        self.class.destination_directory
      end

      def destination_postfix
        self.class.destination_postfix
      end

      def document_links(buffer)
        matches(buffer, partial_regexp).map do |match|
          start_row, start_column = from_index_to_row_column(
            buffer,
            match.begin(:partial)
          )

          end_row, end_column = from_index_to_row_column(
            buffer,
            match.end(:partial)
          )

          {
            target: file_link(match[:partial]),
            range: {
              start: {
                line: start_row,
                character: start_column
              },
              end: {
                line: end_row,
                character: end_column
              }
            }
          }
        end
      end

      def file_link(partial)
        file_uri(@storage.path(destination_directory + '/' + partial + destination_postfix))
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
platformos-check-0.0.1 lib/platformos_check/language_server/document_link_provider.rb