Class: ThemeCheck::LanguageServer::ObjectCompletionProvider

Inherits:
CompletionProvider show all
Defined in:
lib/theme_check/language_server/completion_providers/object_completion_provider.rb

Constant Summary

Constants included from RegexHelpers

RegexHelpers::START_OR_END_QUOTE, RegexHelpers::VARIABLE

Constants included from CompletionHelper

CompletionHelper::WORD

Instance Method Summary collapse

Methods inherited from CompletionProvider

all, inherited, #initialize

Methods included from RegexHelpers

#href_to_file_size, #matches

Methods included from CompletionHelper

#cursor_on_first_word?, #cursor_on_start_content?, #first_word

Constructor Details

This class inherits a constructor from ThemeCheck::LanguageServer::CompletionProvider

Instance Method Details

#completions(content, cursor) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/theme_check/language_server/completion_providers/object_completion_provider.rb', line 6

def completions(content, cursor)
  return [] unless (variable_lookup = variable_lookup_at_cursor(content, cursor))
  return [] unless variable_lookup.lookups.empty?
  return [] if content[cursor - 1] == "."
  ShopifyLiquid::Object.labels
    .select { |w| w.start_with?(partial(variable_lookup)) }
    .map { |object| object_to_completion(object) }
end

#partial(variable_lookup) ⇒ Object



19
20
21
# File 'lib/theme_check/language_server/completion_providers/object_completion_provider.rb', line 19

def partial(variable_lookup)
  variable_lookup.name || ''
end

#variable_lookup_at_cursor(content, cursor) ⇒ Object



15
16
17
# File 'lib/theme_check/language_server/completion_providers/object_completion_provider.rb', line 15

def variable_lookup_at_cursor(content, cursor)
  VariableLookupFinder.lookup(content, cursor)
end