Class: Ibex::LSP::ParserConfigurationAssistance
- Inherits:
-
Object
- Object
- Ibex::LSP::ParserConfigurationAssistance
- Defined in:
- lib/ibex/lsp/parser_configuration_assistance.rb
Overview
Provides static editor assistance for the root parser declaration without evaluating grammar code.
Constant Summary collapse
- SETTING_VALUES =
: Hash[String, Array[String]]
Frontend::ParserConfigurationSupport::PARSER_SETTING_VALUES
- SETTING_DOCUMENTATION =
{ "algorithm" => "`parser.algorithm` selects parser-table construction. Values: `slr`, `lalr`, `ielr`, `lr1`.", "entries" => "`parser.entries` selects shared or isolated construction for multiple start symbols. " \ "Values: `shared`, `isolated`.", "cst_trivia" => "`cst.trivia` selects CST trivia ownership. Values: `leading`, `balanced`, `drop`; " \ "requires `pragma cst`." }.freeze
- VALUE_DOCUMENTATION =
: Hash[String, String]
{ "slr" => "`slr` — SLR parser-table construction.", "lalr" => "`lalr` — LALR parser-table construction.", "ielr" => "`ielr` — IELR parser-table construction with canonical LR(1) verification support.", "lr1" => "`lr1` — canonical LR(1) parser-table construction.", "shared" => "`shared` — construct multiple entries in one shared automaton.", "isolated" => "`isolated` — construct each of multiple entries independently.", "leading" => "`leading` — attach leading trivia to the following CST node.", "balanced" => "`balanced` — attach trivia between the surrounding CST nodes.", "drop" => "`drop` — omit CST trivia; location and incremental APIs are unavailable." }.freeze
Instance Method Summary collapse
- #completion(position) ⇒ Object
- #hover(position) ⇒ Object
-
#initialize(store, path) ⇒ ParserConfigurationAssistance
constructor
A new instance of ParserConfigurationAssistance.
Constructor Details
#initialize(store, path) ⇒ ParserConfigurationAssistance
Returns a new instance of ParserConfigurationAssistance.
28 29 30 31 |
# File 'lib/ibex/lsp/parser_configuration_assistance.rb', line 28 def initialize(store, path) @store = store @path = path end |
Instance Method Details
#completion(position) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ibex/lsp/parser_configuration_assistance.rb', line 34 def completion(position) source = source! codec = PositionCodec.new(source) offset = codec.byte_offset(position) line_start = line_start(source, offset) return completion_list([]) unless parser_block_open?(source.byteslice(0, line_start) || "") prefix = source.byteslice(line_start, offset - line_start) || "" value_match = prefix.match(/\A\s*(algorithm|entries|cst_trivia)\s+([A-Za-z_]*)\z/) if value_match setting = value_match[1] || raise("parser setting capture is missing") return completion_list(value_items(setting)) end return completion_list(setting_items) if prefix.match?(/\A\s*[A-Za-z_]*\z/) completion_list([]) end |
#hover(position) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ibex/lsp/parser_configuration_assistance.rb', line 53 def hover(position) source = source! codec = PositionCodec.new(source) offset = codec.byte_offset(position) start = line_start(source, offset) return unless parser_block_open?(source.byteslice(0, start) || "") finish = source.index("\n", start) || source.bytesize line = source.byteslice(start, finish - start) || "" match = line.match( /\A\s*(algorithm|entries|cst_trivia)\s+(slr|lalr|ielr|lr1|shared|isolated|leading|balanced|drop)\s*(?:#.*)?\z/ ) return unless match token, token_start, token_end = hovered_token(match, line, start, offset) return unless token documentation = SETTING_DOCUMENTATION[token] || VALUE_DOCUMENTATION[token] { "contents" => { "kind" => "markdown", "value" => documentation }, "range" => { "start" => codec.position(token_start), "end" => codec.position(token_end) } } end |