Class: Spoom::LSP::DocumentSymbol

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, kind:, children:, detail: nil, location: nil, range: nil) ⇒ DocumentSymbol

: ( | name: String, | kind: Integer, | children: Array, | ?detail: String?, | ?location: Location?, | ?range: LSP::Range? | ) -> void



291
292
293
294
295
296
297
298
# File 'lib/spoom/sorbet/lsp/structures.rb', line 291

def initialize(name:, kind:, children:, detail: nil, location: nil, range: nil)
  @name = name
  @detail = detail
  @kind = kind
  @location = location
  @range = range
  @children = children
end

Instance Attribute Details

#children ⇒ Object (readonly)

: Array



281
282
283
# File 'lib/spoom/sorbet/lsp/structures.rb', line 281

def children
  @children
end

#detail ⇒ Object (readonly)

: String?



269
270
271
# File 'lib/spoom/sorbet/lsp/structures.rb', line 269

def detail
  @detail
end

#kind ⇒ Object (readonly)

: Integer



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

def kind
  @kind
end

#location ⇒ Object (readonly)

: Location?



275
276
277
# File 'lib/spoom/sorbet/lsp/structures.rb', line 275

def location
  @location
end

#name ⇒ Object (readonly)

: String



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

def name
  @name
end

#range ⇒ Object (readonly)

: LSP::Range?



278
279
280
# File 'lib/spoom/sorbet/lsp/structures.rb', line 278

def range
  @range
end

Class Method Details

.from_json(json) ⇒ Object

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



302
303
304
305
306
307
308
309
310
311
# File 'lib/spoom/sorbet/lsp/structures.rb', line 302

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



316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'lib/spoom/sorbet/lsp/structures.rb', line 316

def accept_printer(printer)
  return unless printer.seen.add?(deduplication_key)

  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



345
346
347
# File 'lib/spoom/sorbet/lsp/structures.rb', line 345

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

#to_s ⇒ Object

: -> String



340
341
342
# File 'lib/spoom/sorbet/lsp/structures.rb', line 340

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