Class: PlatformosCheck::LanguageServer::FilterHoverProvider

Inherits:
HoverProvider
  • Object
show all
Defined in:
lib/platformos_check/language_server/hover_providers/filter_hover_provider.rb

Constant Summary collapse

NAMED_FILTER =
/#{Liquid::FilterSeparator}\s*(\w+)/o
FILTER_SEPARATOR_INCLUDING_SPACES =
/\s*#{Liquid::FilterSeparator}/
INPUT_TYPE_VARIABLE =
'variable'

Constants included from RegexHelpers

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

Constants included from CompletionHelper

CompletionHelper::WORD

Instance Attribute Summary

Attributes inherited from HoverProvider

#storage

Instance Method Summary collapse

Methods inherited from HoverProvider

all, #doc_hash, #format_hash, inherited, #initialize

Methods included from RegexHelpers

#matches

Methods included from CompletionHelper

#cursor_on_first_word?, #cursor_on_start_content?, #first_word

Constructor Details

This class inherits a constructor from PlatformosCheck::LanguageServer::HoverProvider

Instance Method Details

#can_complete?(content, cursor) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
# File 'lib/platformos_check/language_server/hover_providers/filter_hover_provider.rb', line 29

def can_complete?(content, cursor)
  content.match?(Liquid::FilterSeparator) && (
    cursor_on_start_content?(content, cursor, Liquid::FilterSeparator) ||
    cursor_on_filter?(content, cursor)
  )
end

#completions(context) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/platformos_check/language_server/hover_providers/filter_hover_provider.rb', line 10

def completions(context)
  content = context.content
  cursor = context.cursor

  return [] if content.nil?
  return [] unless can_complete?(content, cursor)

  context = context_with_cursor_before_potential_filter_separator(context)
  variable_lookup = VariableLookupFinder.lookup(context)
  denied_filters = denied_filters_for(variable_lookup)
  available_filters_for(determine_input_type(variable_lookup))
    .select do |filter|
      partial_name = partial(content, cursor)
      (filter.name == partial_name || filter.aliases.any? { |a| a == partial_name }) && denied_filters.none?(filter.name)
    end
    .map { |filter| filter_to_completion(filter) }
    .first
end