Class: Spoom::LSP::DocumentSymbol

Inherits:
T::Struct
  • Object
show all
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



227
228
229
230
231
232
233
234
235
236
# File 'lib/spoom/sorbet/lsp/structures.rb', line 227

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



240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/spoom/sorbet/lsp/structures.rb', line 240

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



272
273
274
# File 'lib/spoom/sorbet/lsp/structures.rb', line 272

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

#to_sObject



267
268
269
# File 'lib/spoom/sorbet/lsp/structures.rb', line 267

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