Class: Spoom::LSP::DocumentSymbol
- Inherits:
-
T::Struct
- Object
- T::Struct
- Spoom::LSP::DocumentSymbol
- Extended by:
- T::Sig
- Includes:
- PrintableSymbol
- Defined in:
- lib/spoom/sorbet/lsp/structures.rb
Constant Summary collapse
- SYMBOL_KINDS =
T.let({ 1 => "file", 2 => "module", 3 => "namespace", 4 => "package", 5 => "class", 6 => "def", 7 => "property", 8 => "field", 9 => "constructor", 10 => "enum", 11 => "interface", 12 => "function", 13 => "variable", 14 => "const", 15 => "string", 16 => "number", 17 => "boolean", 18 => "array", 19 => "object", 20 => "key", 21 => "null", 22 => "enum_member", 23 => "struct", 24 => "event", 25 => "operator", 26 => "type_parameter", }, T::Hash[Integer, String])
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.from_json(json) ⇒ Object
200 201 202 203 204 205 206 207 208 209 |
# File 'lib/spoom/sorbet/lsp/structures.rb', line 200 def self.from_json(json) DocumentSymbol.new( name: json['name'], detail: json['detail'], kind: json['kind'], location: json['location'] ? Location.from_json(json['location']) : nil, range: json['range'] ? Range.from_json(json['range']) : nil, children: json['children'] ? json['children'].map { |symbol| DocumentSymbol.from_json(symbol) } : [], ) end |
Instance Method Details
#accept_printer(printer) ⇒ Object
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/spoom/sorbet/lsp/structures.rb', line 212 def accept_printer(printer) h = serialize.hash return if printer.seen.include?(h) printer.seen.add(h) printer.printt printer.print(kind_string) printer.print(' ') printer.print_colored(name, Color::BLUE, Color::BOLD) printer.print_colored(' (', Color::LIGHT_BLACK) if range printer.print_object(range) elsif location printer.print_object(location) end printer.print_colored(')', Color::LIGHT_BLACK) printer.printn unless children.empty? printer.indent printer.print_objects(children) printer.dedent end # TODO: also display details? end |
#kind_string ⇒ Object
243 244 245 |
# File 'lib/spoom/sorbet/lsp/structures.rb', line 243 def kind_string SYMBOL_KINDS[kind] || "<unknown:#{kind}>" end |
#to_s ⇒ Object
238 239 240 |
# File 'lib/spoom/sorbet/lsp/structures.rb', line 238 def to_s "#{name} (#{range})" end |