Sha256: 4c42e22581cac73bf50d5dfa6bad0224942b60ca5efb0e2ff2a8ea50d007b65a
Contents?: true
Size: 1.01 KB
Versions: 2
Compression:
Stored size: 1.01 KB
Contents
# frozen_string_literal: true module ThemeCheck module LanguageServer class CompletionEngine include PositionHelper def initialize(storage) @storage = storage @providers = CompletionProvider.all.map(&:new) end def completions(name, line, col) buffer = @storage.read(name) cursor = from_line_column_to_index(buffer, line, col) token = find_token(buffer, cursor) return [] if token.nil? @providers.flat_map do |p| p.completions( token.content, cursor - token.start ) end end def find_token(buffer, cursor) Tokens.new(buffer).find do |token| # Here we include the next character and exclude the first # one becase when we want to autocomplete inside a token # and at most 1 outside it since the cursor could be placed # at the end of the token. token.start < cursor && cursor <= token.end end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
theme-check-0.5.0 | lib/theme_check/language_server/completion_engine.rb |
theme-check-0.4.0 | lib/theme_check/language_server/completion_engine.rb |