Class: PlatformosCheck::LanguageServer::DocumentLinkProvider
Constant Summary
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
#bounded, #from_index_to_row_column, #from_row_column_to_index
#matches
Constructor Details
#initialize(storage = InMemoryStorage.new) ⇒ DocumentLinkProvider
Returns a new instance of DocumentLinkProvider.
22
23
24
|
# File 'lib/platformos_check/language_server/document_link_provider.rb', line 22
def initialize(storage = InMemoryStorage.new)
@storage = storage
end
|
Class Attribute Details
.app_file_type ⇒ Object
Returns the value of attribute app_file_type.
11
12
13
|
# File 'lib/platformos_check/language_server/document_link_provider.rb', line 11
def app_file_type
@app_file_type
end
|
.default_dir ⇒ Object
Returns the value of attribute default_dir.
11
12
13
|
# File 'lib/platformos_check/language_server/document_link_provider.rb', line 11
def default_dir
@default_dir
end
|
.default_extension ⇒ Object
Returns the value of attribute default_extension.
11
12
13
|
# File 'lib/platformos_check/language_server/document_link_provider.rb', line 11
def default_extension
@default_extension
end
|
.partial_regexp ⇒ Object
Returns the value of attribute partial_regexp.
11
12
13
|
# File 'lib/platformos_check/language_server/document_link_provider.rb', line 11
def partial_regexp
@partial_regexp
end
|
Class Method Details
.all ⇒ Object
13
14
15
|
# File 'lib/platformos_check/language_server/document_link_provider.rb', line 13
def all
@all ||= []
end
|
.inherited(subclass) ⇒ Object
17
18
19
|
# File 'lib/platformos_check/language_server/document_link_provider.rb', line 17
def inherited(subclass)
all << subclass
end
|
Instance Method Details
#app_file_type ⇒ Object
26
27
28
|
# File 'lib/platformos_check/language_server/document_link_provider.rb', line 26
def app_file_type
self.class.app_file_type
end
|
#default_dir ⇒ Object
30
31
32
|
# File 'lib/platformos_check/language_server/document_link_provider.rb', line 30
def default_dir
self.class.default_dir
end
|
#default_extension ⇒ Object
34
35
36
|
# File 'lib/platformos_check/language_server/document_link_provider.rb', line 34
def default_extension
self.class.default_extension
end
|
#default_relative_path(partial) ⇒ Object
77
78
79
80
81
82
83
84
85
|
# File 'lib/platformos_check/language_server/document_link_provider.rb', line 77
def default_relative_path(partial)
return Pathname.new("app/#{default_dir}/#{partial}#{default_extension}") unless partial.start_with?('modules/')
partial_components = partial.split(File::SEPARATOR)
module_prefix = partial_components.shift(2).join(File::SEPARATOR)
partial_without_module = partial_components.join(File::SEPARATOR)
Pathname.new("#{module_prefix}/public/#{default_dir}/#{partial_without_module}#{default_extension}")
end
|
#document_links(buffer, platformos_app) ⇒ Object
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
68
|
# File 'lib/platformos_check/language_server/document_link_provider.rb', line 42
def document_links(buffer, platformos_app)
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], platformos_app),
range: {
start: {
line: start_row,
character: start_column
},
end: {
line: end_row,
character: end_column
}
}
}
end
end
|
#file_link(partial, platformos_app) ⇒ Object
70
71
72
73
74
75
|
# File 'lib/platformos_check/language_server/document_link_provider.rb', line 70
def file_link(partial, platformos_app)
relative_path = platformos_app.send(app_file_type).detect { |f| f.name == partial }&.relative_path
relative_path ||= default_relative_path(partial)
file_uri(@storage.path(relative_path))
end
|
#partial_regexp ⇒ Object
38
39
40
|
# File 'lib/platformos_check/language_server/document_link_provider.rb', line 38
def partial_regexp
self.class.partial_regexp
end
|