Class: Spoom::LSP::DocumentSymbol

Inherits:
T::Struct
  • Object
show all
Includes:
PrintableSymbol
Defined in:
lib/spoom/sorbet/lsp/structures.rb

Constant Summary collapse

SYMBOL_KINDS =
{
  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",
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_json(json) ⇒ Object

: (Hash[untyped, untyped] json) -> DocumentSymbol



209
210
211
212
213
214
215
216
217
218
# File 'lib/spoom/sorbet/lsp/structures.rb', line 209

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



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/spoom/sorbet/lsp/structures.rb', line 223

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_stringObject

: -> String



255
256
257
# File 'lib/spoom/sorbet/lsp/structures.rb', line 255

def kind_string
  SYMBOL_KINDS[kind] || "<unknown:#{kind}>"
end

#to_sObject

: -> String



250
251
252
# File 'lib/spoom/sorbet/lsp/structures.rb', line 250

def to_s
  "#{name} (#{range})"
end