Module: PlatformosCheck::LanguageServer::CompletionHelper

Included in:
CompletionProvider, HoverProvider
Defined in:
lib/platformos_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
19
# File 'lib/platformos_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/platformos_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



21
22
23
# File 'lib/platformos_check/language_server/completion_helper.rb', line 21

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