lib/spoom/sorbet/lsp/structures.rb in spoom-1.1.11 vs lib/spoom/sorbet/lsp/structures.rb in spoom-1.1.12

- old
+ new

@@ -21,16 +21,20 @@ include PrintableSymbol const :contents, String const :range, T.nilable(Range) - sig { params(json: T::Hash[T.untyped, T.untyped]).returns(Hover) } - def self.from_json(json) - Hover.new( - contents: json['contents']['value'], - range: json['range'] ? Range.from_json(json['range']) : nil - ) + class << self + extend T::Sig + + sig { params(json: T::Hash[T.untyped, T.untyped]).returns(Hover) } + def from_json(json) + Hover.new( + contents: json["contents"]["value"], + range: json["range"] ? Range.from_json(json["range"]) : nil + ) + end end sig { override.params(printer: SymbolPrinter).void } def accept_printer(printer) printer.print("#{contents}\n") @@ -48,16 +52,20 @@ include PrintableSymbol const :line, Integer const :char, Integer - sig { params(json: T::Hash[T.untyped, T.untyped]).returns(Position) } - def self.from_json(json) - Position.new( - line: json['line'].to_i, - char: json['character'].to_i - ) + class << self + extend T::Sig + + sig { params(json: T::Hash[T.untyped, T.untyped]).returns(Position) } + def from_json(json) + Position.new( + line: json["line"].to_i, + char: json["character"].to_i + ) + end end sig { override.params(printer: SymbolPrinter).void } def accept_printer(printer) printer.print_colored("#{line}:#{char}", Color::LIGHT_BLACK) @@ -74,16 +82,20 @@ include PrintableSymbol const :start, Position const :end, Position - sig { params(json: T::Hash[T.untyped, T.untyped]).returns(Range) } - def self.from_json(json) - Range.new( - start: Position.from_json(json['start']), - end: Position.from_json(json['end']) - ) + class << self + extend T::Sig + + sig { params(json: T::Hash[T.untyped, T.untyped]).returns(Range) } + def from_json(json) + Range.new( + start: Position.from_json(json["start"]), + end: Position.from_json(json["end"]) + ) + end end sig { override.params(printer: SymbolPrinter).void } def accept_printer(printer) printer.print_object(start) @@ -102,16 +114,20 @@ include PrintableSymbol const :uri, String const :range, LSP::Range - sig { params(json: T::Hash[T.untyped, T.untyped]).returns(Location) } - def self.from_json(json) - Location.new( - uri: json['uri'], - range: Range.from_json(json['range']) - ) + class << self + extend T::Sig + + sig { params(json: T::Hash[T.untyped, T.untyped]).returns(Location) } + def from_json(json) + Location.new( + uri: json["uri"], + range: Range.from_json(json["range"]) + ) + end end sig { override.params(printer: SymbolPrinter).void } def accept_printer(printer) printer.print_colored("#{printer.clean_uri(uri)}:", Color::LIGHT_BLACK) @@ -130,24 +146,28 @@ const :label, T.nilable(String) const :doc, Object # TODO const :params, T::Array[T.untyped] # TODO - sig { params(json: T::Hash[T.untyped, T.untyped]).returns(SignatureHelp) } - def self.from_json(json) - SignatureHelp.new( - label: json['label'], - doc: json['documentation'], - params: json['parameters'], - ) + class << self + extend T::Sig + + sig { params(json: T::Hash[T.untyped, T.untyped]).returns(SignatureHelp) } + def from_json(json) + SignatureHelp.new( + label: json["label"], + doc: json["documentation"], + params: json["parameters"], + ) + end end sig { override.params(printer: SymbolPrinter).void } def accept_printer(printer) printer.print(label) printer.print("(") - printer.print(params.map { |l| "#{l['label']}: #{l['documentation']}" }.join(", ")) + printer.print(params.map { |l| "#{l["label"]}: #{l["documentation"]}" }.join(", ")) printer.print(")") end sig { returns(String) } def to_s @@ -162,18 +182,22 @@ const :range, LSP::Range const :code, Integer const :message, String const :informations, Object - sig { params(json: T::Hash[T.untyped, T.untyped]).returns(Diagnostic) } - def self.from_json(json) - Diagnostic.new( - range: Range.from_json(json['range']), - code: json['code'].to_i, - message: json['message'], - informations: json['relatedInformation'] - ) + class << self + extend T::Sig + + sig { params(json: T::Hash[T.untyped, T.untyped]).returns(Diagnostic) } + def from_json(json) + Diagnostic.new( + range: Range.from_json(json["range"]), + code: json["code"].to_i, + message: json["message"], + informations: json["relatedInformation"] + ) + end end sig { override.params(printer: SymbolPrinter).void } def accept_printer(printer) printer.print(to_s) @@ -194,39 +218,44 @@ const :kind, Integer const :location, T.nilable(Location) const :range, T.nilable(Range) const :children, T::Array[DocumentSymbol] - sig { params(json: T::Hash[T.untyped, T.untyped]).returns(DocumentSymbol) } - 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) } : [], - ) + class << self + extend T::Sig + + sig { params(json: T::Hash[T.untyped, T.untyped]).returns(DocumentSymbol) } + 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 end sig { override.params(printer: SymbolPrinter).void } 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(" ") printer.print_colored(name, Color::BLUE, Color::BOLD) - printer.print_colored(' (', Color::LIGHT_BLACK) + 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.print_colored(")", Color::LIGHT_BLACK) printer.printn unless children.empty? printer.indent printer.print_objects(children) printer.dedent @@ -301,10 +330,11 @@ end sig { params(object: T.nilable(PrintableSymbol)).void } def print_object(object) return unless object + object.accept_printer(self) end sig { params(objects: T::Array[PrintableSymbol]).void } def print_objects(objects) @@ -313,17 +343,18 @@ sig { params(uri: String).returns(String) } def clean_uri(uri) prefix = self.prefix return uri unless prefix + uri.delete_prefix(prefix) end sig { params(objects: T::Array[PrintableSymbol]).void } def print_list(objects) objects.each do |object| printt - print "* " + print("* ") print_object(object) printn end end end