Sha256: a8d7e33aa8b2876ca73552c04660b3f70b43e93bc4b69e68b7891d22e4fc0b26
Contents?: true
Size: 1.33 KB
Versions: 24
Compression:
Stored size: 1.33 KB
Contents
# frozen_string_literal: true module PlatformosCheck module LanguageServer class CompletionContext include PositionHelper attr_reader :storage, :relative_path, :line, :col def initialize(storage, relative_path, line, col) @storage = storage @relative_path = relative_path @line = line @col = col end def buffer @buffer ||= storage.read(relative_path) end def buffer_until_previous_row @buffer_without_current_row ||= buffer[0..absolute_cursor].lines[0...-1].join end def absolute_cursor @absolute_cursor ||= from_row_column_to_index(buffer, line, col) end def cursor @cursor ||= (absolute_cursor - token&.start) || 0 end def content @content ||= token&.content end def token @token ||= Tokens.new(buffer).find do |t| # 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. t.start < absolute_cursor && absolute_cursor <= t.end end end def clone_and_overwrite(col:) CompletionContext.new(storage, relative_path, line, col) end end end end
Version data entries
24 entries across 24 versions & 1 rubygems