jazzy 0.13.5 → 0.14.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/Tests.yml +52 -0
- data/.rubocop.yml +139 -24
- data/CHANGELOG.md +105 -0
- data/CONTRIBUTING.md +5 -5
- data/Dangerfile +11 -8
- data/Gemfile +3 -1
- data/Gemfile.lock +101 -77
- data/README.md +81 -13
- data/Rakefile +13 -12
- data/bin/jazzy +3 -2
- data/bin/sourcekitten +0 -0
- data/jazzy.gemspec +8 -6
- data/js/package-lock.json +30 -25
- data/js/package.json +3 -3
- data/lib/jazzy/config.rb +125 -72
- data/lib/jazzy/doc.rb +3 -1
- data/lib/jazzy/doc_builder.rb +79 -84
- data/lib/jazzy/docset_builder.rb +3 -1
- data/lib/jazzy/documentation_generator.rb +6 -2
- data/lib/jazzy/executable.rb +3 -0
- data/lib/jazzy/extensions/bitbucket/img/bitbucket.svg +11 -0
- data/lib/jazzy/{themes/apple/assets → extensions/github}/img/gh.png +0 -0
- data/lib/jazzy/extensions/gitlab/img/gitlab.svg +23 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_AMS-Regular.ttf +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_AMS-Regular.woff +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_AMS-Regular.woff2 +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Caligraphic-Bold.ttf +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Caligraphic-Bold.woff +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Caligraphic-Bold.woff2 +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Caligraphic-Regular.ttf +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Caligraphic-Regular.woff +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Caligraphic-Regular.woff2 +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Fraktur-Bold.ttf +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Fraktur-Bold.woff +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Fraktur-Bold.woff2 +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Fraktur-Regular.ttf +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Fraktur-Regular.woff +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Fraktur-Regular.woff2 +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Main-Bold.ttf +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Main-Bold.woff +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Main-Bold.woff2 +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Main-BoldItalic.ttf +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Main-BoldItalic.woff +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Main-BoldItalic.woff2 +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Main-Italic.ttf +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Main-Italic.woff +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Main-Italic.woff2 +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Main-Regular.ttf +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Main-Regular.woff +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Main-Regular.woff2 +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Math-BoldItalic.ttf +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Math-BoldItalic.woff +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Math-BoldItalic.woff2 +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Math-Italic.ttf +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Math-Italic.woff +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Math-Italic.woff2 +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_SansSerif-Bold.ttf +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_SansSerif-Bold.woff +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_SansSerif-Bold.woff2 +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_SansSerif-Italic.ttf +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_SansSerif-Italic.woff +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_SansSerif-Italic.woff2 +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_SansSerif-Regular.ttf +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_SansSerif-Regular.woff +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_SansSerif-Regular.woff2 +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Script-Regular.ttf +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Script-Regular.woff +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Script-Regular.woff2 +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Size1-Regular.ttf +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Size1-Regular.woff +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Size1-Regular.woff2 +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Size2-Regular.ttf +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Size2-Regular.woff +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Size2-Regular.woff2 +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Size3-Regular.ttf +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Size3-Regular.woff +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Size3-Regular.woff2 +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Size4-Regular.ttf +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Size4-Regular.woff +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Size4-Regular.woff2 +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Typewriter-Regular.ttf +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Typewriter-Regular.woff +0 -0
- data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Typewriter-Regular.woff2 +0 -0
- data/lib/jazzy/extensions/katex/css/katex.min.css +1 -1
- data/lib/jazzy/extensions/katex/js/katex.min.js +1 -1
- data/lib/jazzy/gem_version.rb +3 -1
- data/lib/jazzy/highlighter.rb +17 -3
- data/lib/jazzy/jazzy_markdown.rb +112 -31
- data/lib/jazzy/podspec_documenter.rb +14 -16
- data/lib/jazzy/search_builder.rb +4 -3
- data/lib/jazzy/source_declaration/access_control_level.rb +7 -5
- data/lib/jazzy/source_declaration/type.rb +29 -3
- data/lib/jazzy/source_declaration.rb +18 -3
- data/lib/jazzy/source_document.rb +8 -5
- data/lib/jazzy/source_host.rb +111 -0
- data/lib/jazzy/source_mark.rb +8 -6
- data/lib/jazzy/source_module.rb +6 -6
- data/lib/jazzy/sourcekitten.rb +157 -86
- data/lib/jazzy/stats.rb +14 -3
- data/lib/jazzy/symbol_graph/constraint.rb +98 -0
- data/lib/jazzy/symbol_graph/ext_node.rb +116 -0
- data/lib/jazzy/symbol_graph/graph.rb +200 -0
- data/lib/jazzy/symbol_graph/relationship.rb +48 -0
- data/lib/jazzy/symbol_graph/sym_node.rb +176 -0
- data/lib/jazzy/symbol_graph/symbol.rb +248 -0
- data/lib/jazzy/symbol_graph.rb +95 -0
- data/lib/jazzy/themes/apple/assets/css/highlight.css.scss +63 -59
- data/lib/jazzy/themes/apple/assets/css/jazzy.css.scss +26 -2
- data/lib/jazzy/themes/apple/assets/js/jazzy.js +4 -0
- data/lib/jazzy/themes/apple/assets/js/jazzy.search.js +4 -0
- data/lib/jazzy/themes/apple/assets/js/jquery.min.js +2 -2
- data/lib/jazzy/themes/apple/assets/js/lunr.min.js +3 -3
- data/lib/jazzy/themes/apple/templates/doc.mustache +4 -5
- data/lib/jazzy/themes/apple/templates/footer.mustache +1 -1
- data/lib/jazzy/themes/apple/templates/header.mustache +6 -6
- data/lib/jazzy/themes/apple/templates/task.mustache +6 -11
- data/lib/jazzy/themes/fullwidth/assets/css/highlight.css.scss +63 -59
- data/lib/jazzy/themes/fullwidth/assets/css/jazzy.css.scss +11 -2
- data/lib/jazzy/themes/fullwidth/assets/js/jazzy.js +4 -0
- data/lib/jazzy/themes/fullwidth/assets/js/jazzy.search.js +4 -0
- data/lib/jazzy/themes/fullwidth/assets/js/jquery.min.js +2 -2
- data/lib/jazzy/themes/fullwidth/assets/js/lunr.min.js +3 -3
- data/lib/jazzy/themes/fullwidth/templates/doc.mustache +4 -5
- data/lib/jazzy/themes/fullwidth/templates/footer.mustache +1 -1
- data/lib/jazzy/themes/fullwidth/templates/header.mustache +8 -8
- data/lib/jazzy/themes/fullwidth/templates/task.mustache +6 -11
- data/lib/jazzy/themes/jony/assets/css/highlight.css.scss +63 -59
- data/lib/jazzy/themes/jony/assets/css/jazzy.css.scss +26 -2
- data/lib/jazzy/themes/jony/assets/js/jazzy.js +4 -0
- data/lib/jazzy/themes/jony/assets/js/jquery.min.js +2 -2
- data/lib/jazzy/themes/jony/templates/doc.mustache +4 -5
- data/lib/jazzy/themes/jony/templates/footer.mustache +1 -1
- data/lib/jazzy/themes/jony/templates/header.mustache +6 -6
- data/lib/jazzy/themes/jony/templates/task.mustache +6 -11
- data/lib/jazzy.rb +2 -0
- data/spec/integration_spec.rb +59 -45
- data/spec/spec_helper/pre_flight.rb +2 -0
- data/spec/spec_helper.rb +3 -1
- metadata +39 -19
- data/.circleci/config.yml +0 -83
- data/lib/jazzy/themes/fullwidth/assets/img/gh.png +0 -0
- data/lib/jazzy/themes/jony/assets/img/gh.png +0 -0
- data/spec/sourcekitten_spec.rb +0 -6
@@ -0,0 +1,248 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# rubocop:disable Metrics/ClassLength
|
4
|
+
module Jazzy
|
5
|
+
module SymbolGraph
|
6
|
+
# A Symbol is a tidied-up SymbolGraph JSON object
|
7
|
+
class Symbol
|
8
|
+
attr_accessor :usr
|
9
|
+
attr_accessor :path_components
|
10
|
+
attr_accessor :declaration
|
11
|
+
attr_accessor :kind
|
12
|
+
attr_accessor :acl
|
13
|
+
attr_accessor :spi
|
14
|
+
attr_accessor :location # can be nil, keys :filename :line :character
|
15
|
+
attr_accessor :constraints # array, can be empty
|
16
|
+
attr_accessor :doc_comments # can be nil
|
17
|
+
attr_accessor :attributes # array, can be empty
|
18
|
+
attr_accessor :generic_type_params # set, can be empty
|
19
|
+
attr_accessor :parameter_names # array, can be nil
|
20
|
+
|
21
|
+
def name
|
22
|
+
path_components[-1] || '??'
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize(hash)
|
26
|
+
self.usr = hash[:identifier][:precise]
|
27
|
+
self.path_components = hash[:pathComponents]
|
28
|
+
raw_decl, keywords = parse_decl_fragments(hash[:declarationFragments])
|
29
|
+
init_kind(hash[:kind][:identifier], keywords)
|
30
|
+
init_declaration(raw_decl)
|
31
|
+
if func_signature = hash[:functionSignature]
|
32
|
+
init_func_signature(func_signature)
|
33
|
+
end
|
34
|
+
init_acl(hash[:accessLevel])
|
35
|
+
self.spi = hash[:spi]
|
36
|
+
if location = hash[:location]
|
37
|
+
init_location(location)
|
38
|
+
end
|
39
|
+
init_constraints(hash, raw_decl)
|
40
|
+
if comments_hash = hash[:docComment]
|
41
|
+
init_doc_comments(comments_hash)
|
42
|
+
end
|
43
|
+
init_attributes(hash[:availability] || [])
|
44
|
+
init_generic_type_params(hash)
|
45
|
+
end
|
46
|
+
|
47
|
+
def parse_decl_fragments(fragments)
|
48
|
+
decl = ''
|
49
|
+
keywords = Set.new
|
50
|
+
fragments.each do |frag|
|
51
|
+
decl += frag[:spelling]
|
52
|
+
keywords.add(frag[:spelling]) if frag[:kind] == 'keyword'
|
53
|
+
end
|
54
|
+
[decl, keywords]
|
55
|
+
end
|
56
|
+
|
57
|
+
# Repair problems with SymbolGraph's declprinter
|
58
|
+
|
59
|
+
def init_declaration(raw_decl)
|
60
|
+
# Too much 'Self.TypeName'; omitted arg labels look odd;
|
61
|
+
# duplicated constraints; swift 5.3 vs. master workaround
|
62
|
+
self.declaration = raw_decl
|
63
|
+
.gsub(/\bSelf\./, '')
|
64
|
+
.gsub(/(?<=\(|, )_: /, '_ arg: ')
|
65
|
+
.gsub(/ where.*$/, '')
|
66
|
+
if kind == 'source.lang.swift.decl.class'
|
67
|
+
declaration.sub!(/\s*:.*$/, '')
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# Remember pieces of methods for later markdown parsing
|
72
|
+
|
73
|
+
def init_func_signature(func_signature)
|
74
|
+
self.parameter_names =
|
75
|
+
(func_signature[:parameters] || []).map { |h| h[:name] }
|
76
|
+
end
|
77
|
+
|
78
|
+
# Mapping SymbolGraph's declkinds to SourceKit
|
79
|
+
|
80
|
+
KIND_MAP = {
|
81
|
+
'class' => 'class',
|
82
|
+
'struct' => 'struct',
|
83
|
+
'enum' => 'enum',
|
84
|
+
'enum.case' => 'enumelement', # intentional
|
85
|
+
'protocol' => 'protocol',
|
86
|
+
'init' => 'function.constructor',
|
87
|
+
'deinit' => 'function.destructor',
|
88
|
+
'func.op' => 'function.operator',
|
89
|
+
'type.method' => 'function.method.class',
|
90
|
+
'static.method' => 'function.method.static',
|
91
|
+
'method' => 'function.method.instance',
|
92
|
+
'func' => 'function.free',
|
93
|
+
'type.property' => 'var.class',
|
94
|
+
'static.property' => 'var.static',
|
95
|
+
'property' => 'var.instance',
|
96
|
+
'var' => 'var.global',
|
97
|
+
'subscript' => 'function.subscript',
|
98
|
+
'type.subscript' => 'function.subscript',
|
99
|
+
'static.subscript' => 'function.subscript',
|
100
|
+
'typealias' => 'typealias',
|
101
|
+
'associatedtype' => 'associatedtype',
|
102
|
+
'actor' => 'actor',
|
103
|
+
}.freeze
|
104
|
+
|
105
|
+
# We treat 'static var' differently to 'class var'
|
106
|
+
# We treat actors as first-class entities
|
107
|
+
def adjust_kind_for_declaration(kind, keywords)
|
108
|
+
if kind == 'swift.class' && keywords.member?('actor')
|
109
|
+
return 'swift.actor'
|
110
|
+
end
|
111
|
+
return kind unless keywords.member?('static')
|
112
|
+
|
113
|
+
kind.gsub(/type/, 'static')
|
114
|
+
end
|
115
|
+
|
116
|
+
def init_kind(kind, keywords)
|
117
|
+
adjusted = adjust_kind_for_declaration(kind, keywords)
|
118
|
+
sourcekit_kind = KIND_MAP[adjusted.sub('swift.', '')]
|
119
|
+
raise "Unknown symbol kind '#{kind}'" unless sourcekit_kind
|
120
|
+
|
121
|
+
self.kind = "source.lang.swift.decl.#{sourcekit_kind}"
|
122
|
+
end
|
123
|
+
|
124
|
+
# Mapping SymbolGraph's ACL to SourceKit
|
125
|
+
|
126
|
+
def init_acl(acl)
|
127
|
+
self.acl = "source.lang.swift.accessibility.#{acl}"
|
128
|
+
end
|
129
|
+
|
130
|
+
# Symbol location - only available for public+ decls
|
131
|
+
|
132
|
+
def init_location(loc_hash)
|
133
|
+
self.location = {}
|
134
|
+
location[:filename] = loc_hash[:uri].sub(%r{^file://}, '')
|
135
|
+
location[:line] = loc_hash[:position][:line]
|
136
|
+
location[:character] = loc_hash[:position][:character]
|
137
|
+
end
|
138
|
+
|
139
|
+
# Generic constraints: in one or both of two places.
|
140
|
+
# There can be duplicates; these are removed by `Constraint`.
|
141
|
+
def init_constraints(hash, raw_decl)
|
142
|
+
raw_constraints = %i[swiftGenerics swiftExtension].flat_map do |key|
|
143
|
+
next [] unless container = hash[key]
|
144
|
+
|
145
|
+
container[:constraints] || []
|
146
|
+
end
|
147
|
+
|
148
|
+
constraints =
|
149
|
+
Constraint.new_list_for_symbol(raw_constraints, path_components)
|
150
|
+
if raw_decl =~ / where (.*)$/
|
151
|
+
constraints +=
|
152
|
+
Constraint.new_list_from_declaration(Regexp.last_match[1])
|
153
|
+
end
|
154
|
+
|
155
|
+
self.constraints = constraints.sort.uniq
|
156
|
+
end
|
157
|
+
|
158
|
+
# Generic type params
|
159
|
+
def init_generic_type_params(hash)
|
160
|
+
self.generic_type_params = Set.new(
|
161
|
+
if (generics = hash[:swiftGenerics]) &&
|
162
|
+
(parameters = generics[:parameters])
|
163
|
+
parameters.map { |p| p[:name] }
|
164
|
+
else
|
165
|
+
[]
|
166
|
+
end,
|
167
|
+
)
|
168
|
+
end
|
169
|
+
|
170
|
+
def init_doc_comments(comments_hash)
|
171
|
+
self.doc_comments = comments_hash[:lines]
|
172
|
+
.map { |l| l[:text] }
|
173
|
+
.join("\n")
|
174
|
+
end
|
175
|
+
|
176
|
+
# Availability
|
177
|
+
# Re-encode this as Swift. Should really teach Jazzy about these,
|
178
|
+
# could maybe then do something smarter here.
|
179
|
+
def availability_attributes(avail_hash_list)
|
180
|
+
avail_hash_list.map do |avail|
|
181
|
+
str = '@available('
|
182
|
+
if avail[:isUnconditionallyDeprecated]
|
183
|
+
str += '*, deprecated'
|
184
|
+
elsif domain = avail[:domain]
|
185
|
+
str += domain
|
186
|
+
%i[introduced deprecated obsoleted].each do |event|
|
187
|
+
if version = avail[event]
|
188
|
+
str += ", #{event}: #{decode_version(version)}"
|
189
|
+
end
|
190
|
+
end
|
191
|
+
else
|
192
|
+
warn "Found confusing availability: #{avail}"
|
193
|
+
next nil
|
194
|
+
end
|
195
|
+
|
196
|
+
str += ", message: \"#{avail[:message]}\"" if avail[:message]
|
197
|
+
str += ", renamed: \"#{avail[:renamed]}\"" if avail[:renamed]
|
198
|
+
|
199
|
+
str + ')'
|
200
|
+
end.compact
|
201
|
+
end
|
202
|
+
|
203
|
+
def decode_version(hash)
|
204
|
+
str = hash[:major].to_s
|
205
|
+
str += ".#{hash[:minor]}" if hash[:minor]
|
206
|
+
str += ".#{hash[:patch]}" if hash[:patch]
|
207
|
+
str
|
208
|
+
end
|
209
|
+
|
210
|
+
def spi_attributes
|
211
|
+
spi ? ['@_spi(Unknown)'] : []
|
212
|
+
end
|
213
|
+
|
214
|
+
def init_attributes(avail_hash_list)
|
215
|
+
self.attributes =
|
216
|
+
availability_attributes(avail_hash_list) + spi_attributes
|
217
|
+
end
|
218
|
+
|
219
|
+
# Sort order
|
220
|
+
include Comparable
|
221
|
+
|
222
|
+
def <=>(other)
|
223
|
+
# Things with location: order by file/line/column
|
224
|
+
# (pls tell what wheel i am reinventing :/)
|
225
|
+
if location && other_loc = other.location
|
226
|
+
if location[:filename] == other_loc[:filename]
|
227
|
+
if location[:line] == other_loc[:line]
|
228
|
+
return location[:character] <=> other_loc[:character]
|
229
|
+
end
|
230
|
+
|
231
|
+
return location[:line] <=> other_loc[:line]
|
232
|
+
end
|
233
|
+
return location[:filename] <=> other_loc[:filename]
|
234
|
+
end
|
235
|
+
|
236
|
+
# Things with a location before things without a location
|
237
|
+
return +1 if location.nil? && other.location
|
238
|
+
return -1 if location && other.location.nil?
|
239
|
+
|
240
|
+
# Things without a location: by name and then USR
|
241
|
+
return usr <=> other.usr if name == other.name
|
242
|
+
|
243
|
+
name <=> other.name
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|
248
|
+
# rubocop:enable Metrics/ClassLength
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'set'
|
4
|
+
require 'jazzy/symbol_graph/graph'
|
5
|
+
require 'jazzy/symbol_graph/constraint'
|
6
|
+
require 'jazzy/symbol_graph/symbol'
|
7
|
+
require 'jazzy/symbol_graph/relationship'
|
8
|
+
require 'jazzy/symbol_graph/sym_node'
|
9
|
+
require 'jazzy/symbol_graph/ext_node'
|
10
|
+
|
11
|
+
# This is the top-level symbolgraph driver that deals with
|
12
|
+
# figuring out arguments, running the tool, and loading the
|
13
|
+
# results.
|
14
|
+
|
15
|
+
module Jazzy
|
16
|
+
module SymbolGraph
|
17
|
+
# Run `swift symbolgraph-extract` with configured args,
|
18
|
+
# parse the results, and return as JSON in SourceKit[ten]
|
19
|
+
# format.
|
20
|
+
def self.build(config)
|
21
|
+
Dir.mktmpdir do |tmp_dir|
|
22
|
+
args = arguments(config, tmp_dir)
|
23
|
+
|
24
|
+
Executable.execute_command('swift',
|
25
|
+
args.unshift('symbolgraph-extract'),
|
26
|
+
true) # raise on error
|
27
|
+
|
28
|
+
Dir[tmp_dir + '/*.symbols.json'].map do |filename|
|
29
|
+
# The @ part is for extensions in our module (before the @)
|
30
|
+
# of types in another module (after the @).
|
31
|
+
filename =~ /(.*?)(@(.*?))?\.symbols/
|
32
|
+
module_name = Regexp.last_match[3] || Regexp.last_match[1]
|
33
|
+
{
|
34
|
+
filename =>
|
35
|
+
Graph.new(File.read(filename), module_name).to_sourcekit,
|
36
|
+
}
|
37
|
+
end.to_json
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Figure out the args to pass to symbolgraph-extract
|
42
|
+
def self.arguments(config, output_path)
|
43
|
+
if config.module_name.empty?
|
44
|
+
raise 'error: `--swift-build-tool symbolgraph` requires `--module`.'
|
45
|
+
end
|
46
|
+
|
47
|
+
user_args = config.build_tool_arguments.join
|
48
|
+
|
49
|
+
if user_args =~ /-(?:module-name|minimum-access-level|output-dir)/
|
50
|
+
raise 'error: `--build-tool-arguments` for '\
|
51
|
+
"`--swift-build-tool symbolgraph` can't use `-module`, "\
|
52
|
+
'`-minimum-access-level`, or `-output-dir`.'
|
53
|
+
end
|
54
|
+
|
55
|
+
# Default set
|
56
|
+
args = [
|
57
|
+
'-module-name', config.module_name,
|
58
|
+
'-minimum-access-level', 'private',
|
59
|
+
'-output-dir', output_path,
|
60
|
+
'-skip-synthesized-members'
|
61
|
+
]
|
62
|
+
|
63
|
+
# Things user can override
|
64
|
+
args += ['-sdk', sdk(config)] unless user_args =~ /-sdk/
|
65
|
+
args += ['-target', target] unless user_args =~ /-target/
|
66
|
+
args += ['-F', config.source_directory.to_s] unless user_args =~ /-F(?!s)/
|
67
|
+
args += ['-I', config.source_directory.to_s] unless user_args =~ /-I/
|
68
|
+
|
69
|
+
args + config.build_tool_arguments
|
70
|
+
end
|
71
|
+
|
72
|
+
# Get the SDK path. On !darwin this just isn't needed.
|
73
|
+
def self.sdk(config)
|
74
|
+
`xcrun --show-sdk-path --sdk #{config.sdk}`.chomp
|
75
|
+
end
|
76
|
+
|
77
|
+
# Guess a default LLVM target. Feels like the tool should figure this
|
78
|
+
# out from sdk + the binary somehow?
|
79
|
+
def self.target
|
80
|
+
`swift -version` =~ /Target: (.*?)$/
|
81
|
+
Regexp.last_match[1] || 'x86_64-apple-macosx10.15'
|
82
|
+
end
|
83
|
+
|
84
|
+
# This is a last-ditch fallback for when symbolgraph doesn't
|
85
|
+
# provide a name - at least conforming external types to local
|
86
|
+
# protocols.
|
87
|
+
def self.demangle(usr)
|
88
|
+
args = %w[demangle -simplified -compact].append(usr.sub(/^s:/, 's'))
|
89
|
+
output, = Executable.execute_command('swift', args, true)
|
90
|
+
output.chomp
|
91
|
+
rescue StandardError
|
92
|
+
usr
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -1,63 +1,67 @@
|
|
1
|
+
/*! Jazzy - https://github.com/realm/jazzy
|
2
|
+
* Copyright Realm Inc.
|
3
|
+
* SPDX-License-Identifier: MIT
|
4
|
+
*/
|
1
5
|
/* Credit to https://gist.github.com/wataru420/2048287 */
|
2
6
|
|
3
7
|
.highlight {
|
4
|
-
.c { color: #999988; font-style: italic }
|
5
|
-
.err { color: #a61717; background-color: #e3d2d2 }
|
6
|
-
.k { color: #000000; font-weight: bold }
|
7
|
-
.o { color: #000000; font-weight: bold }
|
8
|
-
.cm { color: #999988; font-style: italic }
|
9
|
-
.cp { color: #999999; font-weight: bold }
|
10
|
-
.c1 { color: #999988; font-style: italic }
|
11
|
-
.cs { color: #999999; font-weight: bold; font-style: italic }
|
12
|
-
.gd { color: #000000; background-color: #ffdddd }
|
13
|
-
.gd .x { color: #000000; background-color: #ffaaaa }
|
14
|
-
.ge { color: #000000; font-style: italic }
|
15
|
-
.gr { color: #aa0000 }
|
16
|
-
.gh { color: #999999 }
|
17
|
-
.gi { color: #000000; background-color: #ddffdd }
|
18
|
-
.gi .x { color: #000000; background-color: #aaffaa }
|
19
|
-
.go { color: #888888 }
|
20
|
-
.gp { color: #555555 }
|
21
|
-
.gs { font-weight: bold }
|
22
|
-
.gu { color: #aaaaaa }
|
23
|
-
.gt { color: #aa0000 }
|
24
|
-
.kc { color: #000000; font-weight: bold }
|
25
|
-
.kd { color: #000000; font-weight: bold }
|
26
|
-
.kp { color: #000000; font-weight: bold }
|
27
|
-
.kr { color: #000000; font-weight: bold }
|
28
|
-
.kt { color: #445588; }
|
29
|
-
.m { color: #009999 }
|
30
|
-
.s { color: #d14 }
|
31
|
-
.na { color: #008080 }
|
32
|
-
.nb { color: #0086B3 }
|
33
|
-
.nc { color: #445588; font-weight: bold }
|
34
|
-
.no { color: #008080 }
|
35
|
-
.ni { color: #800080 }
|
36
|
-
.ne { color: #990000; font-weight: bold }
|
37
|
-
.nf { color: #990000; }
|
38
|
-
.nn { color: #555555 }
|
39
|
-
.nt { color: #000080 }
|
40
|
-
.nv { color: #008080 }
|
41
|
-
.ow { color: #000000; font-weight: bold }
|
42
|
-
.w { color: #bbbbbb }
|
43
|
-
.mf { color: #009999 }
|
44
|
-
.mh { color: #009999 }
|
45
|
-
.mi { color: #009999 }
|
46
|
-
.mo { color: #009999 }
|
47
|
-
.sb { color: #d14 }
|
48
|
-
.sc { color: #d14 }
|
49
|
-
.sd { color: #d14 }
|
50
|
-
.s2 { color: #d14 }
|
51
|
-
.se { color: #d14 }
|
52
|
-
.sh { color: #d14 }
|
53
|
-
.si { color: #d14 }
|
54
|
-
.sx { color: #d14 }
|
55
|
-
.sr { color: #009926 }
|
56
|
-
.s1 { color: #d14 }
|
57
|
-
.ss { color: #990073 }
|
58
|
-
.bp { color: #999999 }
|
59
|
-
.vc { color: #008080 }
|
60
|
-
.vg { color: #008080 }
|
61
|
-
.vi { color: #008080 }
|
62
|
-
.il { color: #009999 }
|
8
|
+
.c { color: #999988; font-style: italic } // Comment
|
9
|
+
.err { color: #a61717; background-color: #e3d2d2 } // Error
|
10
|
+
.k { color: #000000; font-weight: bold } // Keyword
|
11
|
+
.o { color: #000000; font-weight: bold } // Operator
|
12
|
+
.cm { color: #999988; font-style: italic } // Comment.Multiline
|
13
|
+
.cp { color: #999999; font-weight: bold } // Comment.Preproc
|
14
|
+
.c1 { color: #999988; font-style: italic } // Comment.Single
|
15
|
+
.cs { color: #999999; font-weight: bold; font-style: italic } // Comment.Special
|
16
|
+
.gd { color: #000000; background-color: #ffdddd } // Generic.Deleted
|
17
|
+
.gd .x { color: #000000; background-color: #ffaaaa } // Generic.Deleted.Specific
|
18
|
+
.ge { color: #000000; font-style: italic } // Generic.Emph
|
19
|
+
.gr { color: #aa0000 } // Generic.Error
|
20
|
+
.gh { color: #999999 } // Generic.Heading
|
21
|
+
.gi { color: #000000; background-color: #ddffdd } // Generic.Inserted
|
22
|
+
.gi .x { color: #000000; background-color: #aaffaa } // Generic.Inserted.Specific
|
23
|
+
.go { color: #888888 } // Generic.Output
|
24
|
+
.gp { color: #555555 } // Generic.Prompt
|
25
|
+
.gs { font-weight: bold } // Generic.Strong
|
26
|
+
.gu { color: #aaaaaa } // Generic.Subheading
|
27
|
+
.gt { color: #aa0000 } // Generic.Traceback
|
28
|
+
.kc { color: #000000; font-weight: bold } // Keyword.Constant
|
29
|
+
.kd { color: #000000; font-weight: bold } // Keyword.Declaration
|
30
|
+
.kp { color: #000000; font-weight: bold } // Keyword.Pseudo
|
31
|
+
.kr { color: #000000; font-weight: bold } // Keyword.Reserved
|
32
|
+
.kt { color: #445588; } // Keyword.Type
|
33
|
+
.m { color: #009999 } // Literal.Number
|
34
|
+
.s { color: #d14 } // Literal.String
|
35
|
+
.na { color: #008080 } // Name.Attribute
|
36
|
+
.nb { color: #0086B3 } // Name.Builtin
|
37
|
+
.nc { color: #445588; font-weight: bold } // Name.Class
|
38
|
+
.no { color: #008080 } // Name.Constant
|
39
|
+
.ni { color: #800080 } // Name.Entity
|
40
|
+
.ne { color: #990000; font-weight: bold } // Name.Exception
|
41
|
+
.nf { color: #990000; } // Name.Function
|
42
|
+
.nn { color: #555555 } // Name.Namespace
|
43
|
+
.nt { color: #000080 } // Name.Tag
|
44
|
+
.nv { color: #008080 } // Name.Variable
|
45
|
+
.ow { color: #000000; font-weight: bold } // Operator.Word
|
46
|
+
.w { color: #bbbbbb } // Text.Whitespace
|
47
|
+
.mf { color: #009999 } // Literal.Number.Float
|
48
|
+
.mh { color: #009999 } // Literal.Number.Hex
|
49
|
+
.mi { color: #009999 } // Literal.Number.Integer
|
50
|
+
.mo { color: #009999 } // Literal.Number.Oct
|
51
|
+
.sb { color: #d14 } // Literal.String.Backtick
|
52
|
+
.sc { color: #d14 } // Literal.String.Char
|
53
|
+
.sd { color: #d14 } // Literal.String.Doc
|
54
|
+
.s2 { color: #d14 } // Literal.String.Double
|
55
|
+
.se { color: #d14 } // Literal.String.Escape
|
56
|
+
.sh { color: #d14 } // Literal.String.Heredoc
|
57
|
+
.si { color: #d14 } // Literal.String.Interpol
|
58
|
+
.sx { color: #d14 } // Literal.String.Other
|
59
|
+
.sr { color: #009926 } // Literal.String.Regex
|
60
|
+
.s1 { color: #d14 } // Literal.String.Single
|
61
|
+
.ss { color: #990073 } // Literal.String.Symbol
|
62
|
+
.bp { color: #999999 } // Name.Builtin.Pseudo
|
63
|
+
.vc { color: #008080 } // Name.Variable.Class
|
64
|
+
.vg { color: #008080 } // Name.Variable.Global
|
65
|
+
.vi { color: #008080 } // Name.Variable.Instance
|
66
|
+
.il { color: #009999 } // Literal.Number.Integer.Long
|
63
67
|
}
|
@@ -1,3 +1,7 @@
|
|
1
|
+
/*! Jazzy - https://github.com/realm/jazzy
|
2
|
+
* Copyright Realm Inc.
|
3
|
+
* SPDX-License-Identifier: MIT
|
4
|
+
*/
|
1
5
|
////////////////////////////////
|
2
6
|
// Constants
|
3
7
|
////////////////////////////////
|
@@ -23,7 +27,8 @@ $breadcrumb_padding_top: 17px;
|
|
23
27
|
|
24
28
|
$code_font: 0.95em Menlo, monospace;
|
25
29
|
|
26
|
-
$
|
30
|
+
$gray_border_color: #e2e2e2;
|
31
|
+
$gray_border: 1px solid $gray_border_color;
|
27
32
|
$declaration_language_border: 5px solid #cde9f4;
|
28
33
|
|
29
34
|
$aside_color: #aaa;
|
@@ -141,6 +146,25 @@ blockquote {
|
|
141
146
|
border-left: 4px solid #ccc;
|
142
147
|
}
|
143
148
|
|
149
|
+
// HRs
|
150
|
+
|
151
|
+
hr {
|
152
|
+
height: 1px;
|
153
|
+
border: none;
|
154
|
+
background-color: $gray_border_color;
|
155
|
+
}
|
156
|
+
|
157
|
+
// Footnotes
|
158
|
+
|
159
|
+
.footnote-ref {
|
160
|
+
display: inline-block;
|
161
|
+
scroll-margin-top: $content-top-offset;
|
162
|
+
}
|
163
|
+
|
164
|
+
.footnote-def {
|
165
|
+
scroll-margin-top: $content-top-offset;
|
166
|
+
}
|
167
|
+
|
144
168
|
// General Content Wrapper
|
145
169
|
|
146
170
|
.content-wrapper {
|
@@ -161,7 +185,7 @@ header {
|
|
161
185
|
z-index: 3;
|
162
186
|
img {
|
163
187
|
padding-right: 6px;
|
164
|
-
vertical-align: -
|
188
|
+
vertical-align: -3px;
|
165
189
|
height: 16px;
|
166
190
|
}
|
167
191
|
a {
|