lib/jazzy/symbol_graph/symbol.rb in jazzy-0.14.0 vs lib/jazzy/symbol_graph/symbol.rb in jazzy-0.14.1
- old
+ new
@@ -8,42 +8,54 @@
attr_accessor :usr
attr_accessor :path_components
attr_accessor :declaration
attr_accessor :kind
attr_accessor :acl
+ attr_accessor :spi
attr_accessor :location # can be nil, keys :filename :line :character
attr_accessor :constraints # array, can be empty
attr_accessor :doc_comments # can be nil
- attr_accessor :availability # array, can be empty
+ attr_accessor :attributes # array, can be empty
attr_accessor :generic_type_params # set, can be empty
attr_accessor :parameter_names # array, can be nil
def name
path_components[-1] || '??'
end
def initialize(hash)
self.usr = hash[:identifier][:precise]
self.path_components = hash[:pathComponents]
- raw_decl = hash[:declarationFragments].map { |f| f[:spelling] }.join
- init_kind(hash[:kind][:identifier])
+ raw_decl, keywords = parse_decl_fragments(hash[:declarationFragments])
+ init_kind(hash[:kind][:identifier], keywords)
init_declaration(raw_decl)
if func_signature = hash[:functionSignature]
init_func_signature(func_signature)
end
init_acl(hash[:accessLevel])
+ self.spi = hash[:spi]
if location = hash[:location]
init_location(location)
end
init_constraints(hash, raw_decl)
if comments_hash = hash[:docComment]
init_doc_comments(comments_hash)
end
- init_availability(hash[:availability] || [])
+ init_attributes(hash[:availability] || [])
init_generic_type_params(hash)
end
+ def parse_decl_fragments(fragments)
+ decl = ''
+ keywords = Set.new
+ fragments.each do |frag|
+ decl += frag[:spelling]
+ keywords.add(frag[:spelling]) if frag[:kind] == 'keyword'
+ end
+ [decl, keywords]
+ end
+
# Repair problems with SymbolGraph's declprinter
def init_declaration(raw_decl)
# Too much 'Self.TypeName'; omitted arg labels look odd;
# duplicated constraints; swift 5.3 vs. master workaround
@@ -85,21 +97,26 @@
'subscript' => 'function.subscript',
'type.subscript' => 'function.subscript',
'static.subscript' => 'function.subscript',
'typealias' => 'typealias',
'associatedtype' => 'associatedtype',
+ 'actor' => 'actor',
}.freeze
# We treat 'static var' differently to 'class var'
- def adjust_kind_for_declaration(kind)
- return kind unless declaration =~ /\bstatic\b/
+ # We treat actors as first-class entities
+ def adjust_kind_for_declaration(kind, keywords)
+ if kind == 'swift.class' && keywords.member?('actor')
+ return 'swift.actor'
+ end
+ return kind unless keywords.member?('static')
kind.gsub(/type/, 'static')
end
- def init_kind(kind)
- adjusted = adjust_kind_for_declaration(kind)
+ def init_kind(kind, keywords)
+ adjusted = adjust_kind_for_declaration(kind, keywords)
sourcekit_kind = KIND_MAP[adjusted.sub('swift.', '')]
raise "Unknown symbol kind '#{kind}'" unless sourcekit_kind
self.kind = "source.lang.swift.decl.#{sourcekit_kind}"
end
@@ -157,12 +174,12 @@
end
# Availability
# Re-encode this as Swift. Should really teach Jazzy about these,
# could maybe then do something smarter here.
- def init_availability(avail_hash_list)
- self.availability = avail_hash_list.map do |avail|
+ def availability_attributes(avail_hash_list)
+ avail_hash_list.map do |avail|
str = '@available('
if avail[:isUnconditionallyDeprecated]
str += '*, deprecated'
elsif domain = avail[:domain]
str += domain
@@ -186,9 +203,18 @@
def decode_version(hash)
str = hash[:major].to_s
str += ".#{hash[:minor]}" if hash[:minor]
str += ".#{hash[:patch]}" if hash[:patch]
str
+ end
+
+ def spi_attributes
+ spi ? ['@_spi(Unknown)'] : []
+ end
+
+ def init_attributes(avail_hash_list)
+ self.attributes =
+ availability_attributes(avail_hash_list) + spi_attributes
end
# Sort order
include Comparable