Module: Ibex::LSP::SymbolIndexSourceQueries

Included in:
SymbolIndexBuilder
Defined in:
lib/ibex/lsp/symbol_index_source_queries.rb,
sig/ibex/lsp/symbol_index_source_queries.rbs

Overview

Locates lossless frontend tokens used by the symbol index.

Instance Method Summary collapse

Instance Method Details

#declaration_reference_names(declaration) ⇒ Array[String]

RBS:

  • (Frontend::AST::declaration declaration) -> Array[String]

Parameters:

  • declaration (Frontend::AST::declaration)

Returns:

  • (Array[String])


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ibex/lsp/symbol_index_source_queries.rb', line 38

def declaration_reference_names(declaration)
  case declaration
  when Frontend::AST::Start, Frontend::AST::OnErrorReduce
    declaration.names
  when Frontend::AST::Recovery
    declaration.sync_tokens
  when Frontend::AST::DisplayName, Frontend::AST::SemanticType
    [declaration.name]
  when Frontend::AST::Convert
    declaration.pairs.map(&:name)
  when Frontend::AST::Precedence
    declaration.levels.flat_map(&:symbols)
  else
    []
  end
end

#location_before?(left, right) ⇒ Boolean

RBS:

  • (Frontend::Location left, Frontend::Location right) -> bool

Parameters:

Returns:

  • (Boolean)


56
57
58
# File 'lib/ibex/lsp/symbol_index_source_queries.rb', line 56

def location_before?(left, right)
  left.line < right.line || (left.line == right.line && left.column < right.column)
end

#parameter_tokens(document, lhs_token) ⇒ Array[Frontend::Token]

RBS:

  • (Frontend::SourceDocument document, Frontend::Token lhs_token) -> Array[Frontend::Token]

Parameters:

Returns:



27
28
29
30
31
32
33
34
35
# File 'lib/ibex/lsp/symbol_index_source_queries.rb', line 27

def parameter_tokens(document, lhs_token)
  start_index = document.tokens.index(lhs_token)
  return [] unless start_index

  tail = document.tokens.drop(start_index + 1)
  return [] unless tail.first&.type == :"("

  tail.take_while { |token| token.type != :")" }.select { |token| token.type == :identifier }
end

#token_at(document, location, value) ⇒ Frontend::Token?

RBS:

  • (Frontend::SourceDocument document, Frontend::Location location, String value) -> Frontend::Token?

Parameters:

Returns:



20
21
22
23
24
# File 'lib/ibex/lsp/symbol_index_source_queries.rb', line 20

def token_at(document, location, value)
  document.tokens.find do |token|
    token.location.line == location.line && token.location.column == location.column && token.value == value
  end
end

#tokens_between(document, start, finish) ⇒ Array[Frontend::Token]

RBS:

  • (Frontend::SourceDocument document, Frontend::Location start, Frontend::Location? finish) -> Array[Frontend::Token]

Parameters:

Returns:



11
12
13
14
15
16
17
# File 'lib/ibex/lsp/symbol_index_source_queries.rb', line 11

def tokens_between(document, start, finish)
  document.tokens.select do |token|
    after = !location_before?(token.location, start)
    before = finish.nil? || location_before?(token.location, finish)
    after && before
  end
end