class RubyLsp::ResponseBuilders::SemanticHighlighting

: [ResponseType = Interface::SemanticTokens]

def add_token(location, type, modifiers = [])

: (Prism::Location location, Symbol type, ?Array[Symbol] modifiers) -> void
def add_token(location, type, modifiers = [])
  end_code_unit = location.cached_end_code_units_offset(@code_units_cache)
  length = end_code_unit - location.cached_start_code_units_offset(@code_units_cache)
  modifiers_indices = modifiers.filter_map { |modifier| TOKEN_MODIFIERS[modifier] }
  @stack.push(
    SemanticToken.new(
      start_line: location.start_line,
      start_code_unit_column: location.cached_start_code_units_column(@code_units_cache),
      length: length,
      type: TOKEN_TYPES[type], #: as !nil
      modifier: modifiers_indices,
    ),
  )
end

def initialize(code_units_cache)

: ((^(Integer arg0) -> Integer | Prism::CodeUnitsCache) code_units_cache) -> void
def initialize(code_units_cache)
  super()
  @code_units_cache = code_units_cache
  @stack = [] #: Array[SemanticToken]
end

def last

: -> SemanticToken?
def last
  @stack.last
end

def last_token_matches?(location)

: (Prism::Location location) -> bool
def last_token_matches?(location)
  token = @stack.last
  return false unless token
  token.start_line == location.start_line &&
    token.start_code_unit_column == location.cached_start_code_units_column(@code_units_cache)
end

def response

: -> Array[SemanticToken]
@override
def response
  @stack
end