Class: ThemeCheck::LanguageServer::DocumentLinkProvider

Inherits:
Object
  • Object
show all
Includes:
URIHelper, PositionHelper, RegexHelpers
Defined in:
lib/theme_check/language_server/document_link_provider.rb

Constant Summary

Constants included from RegexHelpers

RegexHelpers::HTML_LIQUID_PLACEHOLDER, RegexHelpers::LIQUID_TAG, RegexHelpers::LIQUID_TAG_OR_VARIABLE, RegexHelpers::LIQUID_VARIABLE, RegexHelpers::START_OR_END_QUOTE

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from URIHelper

#file_path, #file_uri

Methods included from PositionHelper

#bounded, #from_index_to_row_column, #from_row_column_to_index

Methods included from RegexHelpers

#matches

Constructor Details

#initialize(storage = InMemoryStorage.new) ⇒ DocumentLinkProvider

Returns a new instance of DocumentLinkProvider.



22
23
24
# File 'lib/theme_check/language_server/document_link_provider.rb', line 22

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

Class Attribute Details

.destination_directoryObject

Returns the value of attribute destination_directory.



11
12
13
# File 'lib/theme_check/language_server/document_link_provider.rb', line 11

def destination_directory
  @destination_directory
end

.destination_postfixObject

Returns the value of attribute destination_postfix.



11
12
13
# File 'lib/theme_check/language_server/document_link_provider.rb', line 11

def destination_postfix
  @destination_postfix
end

.partial_regexpObject

Returns the value of attribute partial_regexp.



11
12
13
# File 'lib/theme_check/language_server/document_link_provider.rb', line 11

def partial_regexp
  @partial_regexp
end

Class Method Details

.allObject



13
14
15
# File 'lib/theme_check/language_server/document_link_provider.rb', line 13

def all
  @all ||= []
end

.inherited(subclass) ⇒ Object



17
18
19
# File 'lib/theme_check/language_server/document_link_provider.rb', line 17

def inherited(subclass)
  all << subclass
end

Instance Method Details

#destination_directoryObject



30
31
32
# File 'lib/theme_check/language_server/document_link_provider.rb', line 30

def destination_directory
  self.class.destination_directory
end

#destination_postfixObject



34
35
36
# File 'lib/theme_check/language_server/document_link_provider.rb', line 34

def destination_postfix
  self.class.destination_postfix
end


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/theme_check/language_server/document_link_provider.rb', line 38

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


66
67
68
# File 'lib/theme_check/language_server/document_link_provider.rb', line 66

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

#partial_regexpObject



26
27
28
# File 'lib/theme_check/language_server/document_link_provider.rb', line 26

def partial_regexp
  self.class.partial_regexp
end