Class: Spoom::LSP::DocumentSymbol
- Inherits:
-
T::Struct
- Object
- T::Struct
- Spoom::LSP::DocumentSymbol
- 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
-
.from_json(json) ⇒ Object
: (Hash[untyped, untyped] json) -> DocumentSymbol.
Instance Method Summary collapse
-
#accept_printer(printer) ⇒ Object
: (SymbolPrinter printer) -> void.
-
#kind_string ⇒ Object
: -> String.
-
#to_s ⇒ Object
: -> String.
Class Method Details
.from_json(json) ⇒ Object
: (Hash[untyped, untyped] json) -> DocumentSymbol
212 213 214 215 216 217 218 219 220 221 |
# File 'lib/spoom/sorbet/lsp/structures.rb', line 212 def 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
: (SymbolPrinter printer) -> void
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/spoom/sorbet/lsp/structures.rb', line 226 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
: -> String
258 259 260 |
# File 'lib/spoom/sorbet/lsp/structures.rb', line 258 def kind_string SYMBOL_KINDS[kind] || "<unknown:#{kind}>" end |
#to_s ⇒ Object
: -> String
253 254 255 |
# File 'lib/spoom/sorbet/lsp/structures.rb', line 253 def to_s "#{name} (#{range})" end |