Module: ThemeCheck::LanguageServer::CompletionHelper

Included in:
CompletionProvider
Defined in:
lib/theme_check/language_server/completion_helper.rb

Constant Summary collapse

WORD =
/\w+/

Instance Method Summary collapse

Instance Method Details

#cursor_on_first_word?(content, cursor) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
# File 'lib/theme_check/language_server/completion_helper.rb', line 12

def cursor_on_first_word?(content, cursor)
  word = content.match(WORD)
  return false if word.nil?
  word_start = word.begin(0)
  word_end = word.end(0)
  word_start <= cursor && cursor <= word_end
end

#cursor_on_start_content?(content, cursor, regex) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/theme_check/language_server/completion_helper.rb', line 8

def cursor_on_start_content?(content, cursor, regex)
  content.slice(0, cursor).match?(/#{regex}(?:\s|\n)*$/m)
end

#first_word(content) ⇒ Object



20
21
22
# File 'lib/theme_check/language_server/completion_helper.rb', line 20

def first_word(content)
  return content.match(WORD)[0] if content.match?(WORD)
end