Sha256: 59c33822b29c981101122566962d35cd710d5e46c5ea51ee1908f4f5c6051966

Contents?: true

Size: 1.55 KB

Versions: 13

Compression:

Stored size: 1.55 KB

Contents

# frozen_string_literal: true

module ThemeCheck
  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

13 entries across 13 versions & 1 rubygems

Version Path
theme-check-1.15.0 lib/theme_check/language_server/document_link_provider.rb
theme-check-1.14.0 lib/theme_check/language_server/document_link_provider.rb
theme-check-1.13.0 lib/theme_check/language_server/document_link_provider.rb
theme-check-1.12.1 lib/theme_check/language_server/document_link_provider.rb
theme-check-1.12.0 lib/theme_check/language_server/document_link_provider.rb
theme-check-1.11.0 lib/theme_check/language_server/document_link_provider.rb
theme-check-1.10.3 lib/theme_check/language_server/document_link_provider.rb
theme-check-1.10.2 lib/theme_check/language_server/document_link_provider.rb
theme-check-1.10.1 lib/theme_check/language_server/document_link_provider.rb
theme-check-1.10.0 lib/theme_check/language_server/document_link_provider.rb
theme-check-1.9.2 lib/theme_check/language_server/document_link_provider.rb
theme-check-1.9.1 lib/theme_check/language_server/document_link_provider.rb
theme-check-1.9.0 lib/theme_check/language_server/document_link_provider.rb