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
- #cursor_on_first_word?(content, cursor) ⇒ Boolean
- #cursor_on_start_content?(content, cursor, regex) ⇒ Boolean
- #first_word(content) ⇒ Object
- #matches(s, re) ⇒ Object
Instance Method Details
#cursor_on_first_word?(content, cursor) ⇒ 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
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 |
#matches(s, re) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/theme_check/language_server/completion_helper.rb', line 24 def matches(s, re) start_at = 0 matches = [] while (m = s.match(re, start_at)) matches.push(m) start_at = m.end(0) end matches end |