Class: ThemeCheck::LanguageServer::DocumentLinkEngine
- Inherits:
-
Object
- Object
- ThemeCheck::LanguageServer::DocumentLinkEngine
- Includes:
- PositionHelper, RegexHelpers
- Defined in:
- lib/theme_check/language_server/document_link_engine.rb
Constant Summary
Constants included from RegexHelpers
RegexHelpers::START_OR_END_QUOTE, RegexHelpers::VARIABLE
Instance Method Summary collapse
- #asset_link(partial) ⇒ Object
- #document_links(relative_path) ⇒ Object
-
#initialize(storage) ⇒ DocumentLinkEngine
constructor
A new instance of DocumentLinkEngine.
- #snippet_link(partial) ⇒ Object
Methods included from RegexHelpers
Methods included from PositionHelper
#bounded, #from_index_to_row_column, #from_row_column_to_index
Constructor Details
#initialize(storage) ⇒ DocumentLinkEngine
Returns a new instance of DocumentLinkEngine.
9 10 11 |
# File 'lib/theme_check/language_server/document_link_engine.rb', line 9 def initialize(storage) @storage = storage end |
Instance Method Details
#asset_link(partial) ⇒ Object
73 74 75 |
# File 'lib/theme_check/language_server/document_link_engine.rb', line 73 def asset_link(partial) file_link('assets', partial, '') end |
#document_links(relative_path) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 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 65 66 67 |
# File 'lib/theme_check/language_server/document_link_engine.rb', line 13 def document_links(relative_path) buffer = @storage.read(relative_path) return [] unless buffer snippet_matches = matches(buffer, PARTIAL_RENDER).map do |match| start_line, start_character = from_index_to_row_column( buffer, match.begin(:partial), ) end_line, end_character = from_index_to_row_column( buffer, match.end(:partial) ) { target: snippet_link(match[:partial]), range: { start: { line: start_line, character: start_character, }, end: { line: end_line, character: end_character, }, }, } end asset_matches = matches(buffer, ASSET_INCLUDE).map do |match| start_line, start_character = from_index_to_row_column( buffer, match.begin(:partial), ) end_line, end_character = from_index_to_row_column( buffer, match.end(:partial) ) { target: asset_link(match[:partial]), range: { start: { line: start_line, character: start_character, }, end: { line: end_line, character: end_character, }, }, } end snippet_matches + asset_matches end |
#snippet_link(partial) ⇒ Object
69 70 71 |
# File 'lib/theme_check/language_server/document_link_engine.rb', line 69 def snippet_link(partial) file_link('snippets', partial, '.liquid') end |