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
- #declaration_reference_names(declaration) ⇒ Array[String]
- #location_before?(left, right) ⇒ Boolean
- #parameter_tokens(document, lhs_token) ⇒ Array[Frontend::Token]
- #token_at(document, location, value) ⇒ Frontend::Token?
- #tokens_between(document, start, finish) ⇒ Array[Frontend::Token]
Instance Method Details
#declaration_reference_names(declaration) ⇒ 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
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]
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?
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]
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 |