jazzy 0.13.5 → 0.13.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,208 @@
1
+ # rubocop:disable Metrics/ClassLength
2
+ module Jazzy
3
+ module SymbolGraph
4
+ # A Symbol is a tidied-up SymbolGraph JSON object
5
+ class Symbol
6
+ attr_accessor :usr
7
+ attr_accessor :path_components
8
+ attr_accessor :declaration
9
+ attr_accessor :kind
10
+ attr_accessor :acl
11
+ attr_accessor :location # can be nil, keys :filename :line :character
12
+ attr_accessor :constraints # array, can be empty
13
+ attr_accessor :doc_comments # can be nil
14
+ attr_accessor :availability # array, can be empty
15
+ attr_accessor :generic_type_params # set, can be empty
16
+
17
+ def name
18
+ path_components[-1] || '??'
19
+ end
20
+
21
+ def initialize(hash)
22
+ self.usr = hash[:identifier][:precise]
23
+ self.path_components = hash[:pathComponents]
24
+ raw_decl = hash[:declarationFragments].map { |f| f[:spelling] }.join
25
+ init_kind(hash[:kind][:identifier])
26
+ init_declaration(raw_decl)
27
+ init_acl(hash[:accessLevel])
28
+ if location = hash[:location]
29
+ init_location(location)
30
+ end
31
+ init_constraints(hash, raw_decl)
32
+ if comments_hash = hash[:docComment]
33
+ init_doc_comments(comments_hash)
34
+ end
35
+ init_availability(hash[:availability] || [])
36
+ init_generic_type_params(hash)
37
+ end
38
+
39
+ # Repair problems with SymbolGraph's declprinter
40
+
41
+ def init_declaration(raw_decl)
42
+ # Too much 'Self.TypeName'; omitted arg labels look odd;
43
+ # duplicated constraints; swift 5.3 vs. master workaround
44
+ self.declaration =
45
+ raw_decl.gsub(/\bSelf\./, '')
46
+ .gsub(/(?<=\(|, )_: /, '_ arg: ')
47
+ .gsub(/ where.*$/, '')
48
+ if kind == 'source.lang.swift.decl.class'
49
+ declaration.sub!(/\s*:.*$/, '')
50
+ end
51
+ end
52
+
53
+ # Mapping SymbolGraph's declkinds to SourceKit
54
+
55
+ KIND_MAP = {
56
+ 'class' => 'class',
57
+ 'struct' => 'struct',
58
+ 'enum' => 'enum',
59
+ 'enum.case' => 'enumelement', # intentional
60
+ 'protocol' => 'protocol',
61
+ 'init' => 'function.constructor',
62
+ 'deinit' => 'function.destructor',
63
+ 'func.op' => 'function.operator',
64
+ 'type.method' => 'function.method.class',
65
+ 'static.method' => 'function.method.static',
66
+ 'method' => 'function.method.instance',
67
+ 'func' => 'function.free',
68
+ 'type.property' => 'var.class',
69
+ 'static.property' => 'var.static',
70
+ 'property' => 'var.instance',
71
+ 'var' => 'var.global',
72
+ 'subscript' => 'function.subscript',
73
+ 'type.subscript' => 'function.subscript',
74
+ 'static.subscript' => 'function.subscript',
75
+ 'typealias' => 'typealias',
76
+ 'associatedtype' => 'associatedtype',
77
+ }.freeze
78
+
79
+ # We treat 'static var' differently to 'class var'
80
+ def adjust_kind_for_declaration(kind)
81
+ return kind unless declaration =~ /\bstatic\b/
82
+ kind.gsub(/type/, 'static')
83
+ end
84
+
85
+ def init_kind(kind)
86
+ adjusted = adjust_kind_for_declaration(kind)
87
+ sourcekit_kind = KIND_MAP[adjusted.sub('swift.', '')]
88
+ raise "Unknown symbol kind '#{kind}'" unless sourcekit_kind
89
+ self.kind = 'source.lang.swift.decl.' + sourcekit_kind
90
+ end
91
+
92
+ # Mapping SymbolGraph's ACL to SourceKit
93
+
94
+ def init_acl(acl)
95
+ self.acl = 'source.lang.swift.accessibility.' + acl
96
+ end
97
+
98
+ # Symbol location - only available for public+ decls
99
+
100
+ def init_location(loc_hash)
101
+ self.location = {}
102
+ location[:filename] = loc_hash[:uri].sub(%r{^file://}, '')
103
+ location[:line] = loc_hash[:position][:line]
104
+ location[:character] = loc_hash[:position][:character]
105
+ end
106
+
107
+ # Generic constraints: in one or both of two places.
108
+ # There can be duplicates; these are removed by `Constraint`.
109
+ def init_constraints(hash, raw_decl)
110
+ raw_constraints = %i[swiftGenerics swiftExtension].flat_map do |key|
111
+ next [] unless container = hash[key]
112
+ container[:constraints] || []
113
+ end
114
+
115
+ constraints =
116
+ Constraint.new_list_for_symbol(raw_constraints, path_components)
117
+ if raw_decl =~ / where (.*)$/
118
+ constraints +=
119
+ Constraint.new_list_from_declaration(Regexp.last_match[1])
120
+ end
121
+
122
+ self.constraints = constraints.sort.uniq
123
+ end
124
+
125
+ # Generic type params
126
+ def init_generic_type_params(hash)
127
+ self.generic_type_params = Set.new(
128
+ if (generics = hash[:swiftGenerics]) &&
129
+ (parameters = generics[:parameters])
130
+ parameters.map { |p| p[:name] }
131
+ else
132
+ []
133
+ end,
134
+ )
135
+ end
136
+
137
+ def init_doc_comments(comments_hash)
138
+ self.doc_comments =
139
+ comments_hash[:lines].map { |l| l[:text] }
140
+ .join("\n")
141
+ end
142
+
143
+ # Availability
144
+ # Re-encode this as Swift. Should really teach Jazzy about these,
145
+ # could maybe then do something smarter here.
146
+ def init_availability(avail_hash_list)
147
+ self.availability = avail_hash_list.map do |avail|
148
+ str = '@available('
149
+ if avail[:isUnconditionallyDeprecated]
150
+ str += '*, deprecated'
151
+ elsif domain = avail[:domain]
152
+ str += domain
153
+ %i[introduced deprecated obsoleted].each do |event|
154
+ if version = avail[event]
155
+ str += ", #{event}: #{decode_version(version)}"
156
+ end
157
+ end
158
+ else
159
+ warn "Found confusing availability: #{avail}"
160
+ next nil
161
+ end
162
+
163
+ str += ', message: "' + avail[:message] + '"' if avail[:message]
164
+ str += ', renamed: "' + avail[:renamed] + '"' if avail[:renamed]
165
+
166
+ str + ')'
167
+ end.compact
168
+ end
169
+
170
+ def decode_version(hash)
171
+ str = hash[:major].to_s
172
+ str += ".#{hash[:minor]}" if hash[:minor]
173
+ str += ".#{hash[:patch]}" if hash[:patch]
174
+ str
175
+ end
176
+
177
+ # Sort order
178
+ include Comparable
179
+
180
+ # rubocop:disable Metrics/CyclomaticComplexity
181
+ # rubocop:disable Metrics/PerceivedComplexity
182
+ def <=>(other)
183
+ # Things with location: order by file/line/column
184
+ # (pls tell what wheel i am reinventing :/)
185
+ if location && other_loc = other.location
186
+ if location[:filename] == other_loc[:filename]
187
+ if location[:line] == other_loc[:line]
188
+ return location[:character] <=> other_loc[:character]
189
+ end
190
+ return location[:line] <=> other_loc[:line]
191
+ end
192
+ return location[:filename] <=> other_loc[:filename]
193
+ end
194
+
195
+ # Things with a location before things without a location
196
+ return +1 if location.nil? && other.location
197
+ return -1 if location && other.location.nil?
198
+
199
+ # Things without a location: by name and then USR
200
+ return usr <=> other.usr if name == other.name
201
+ name <=> other.name
202
+ end
203
+ # rubocop:enable Metrics/PerceivedComplexity
204
+ # rubocop:enable Metrics/CyclomaticComplexity
205
+ end
206
+ end
207
+ end
208
+ # rubocop:enable Metrics/ClassLength
@@ -174,7 +174,7 @@ describe_cli 'jazzy' do
174
174
  "-I #{base} " \
175
175
  '-fmodules'
176
176
  `#{sourcekitten} doc --objc #{objc_args} > objc.json`
177
- `#{sourcekitten} doc > swift.json`
177
+ `#{sourcekitten} doc -- clean build > swift.json`
178
178
  end
179
179
 
180
180
  behaves_like cli_spec 'misc_jazzy_objc_features',
@@ -214,17 +214,26 @@ describe_cli 'jazzy' do
214
214
  end
215
215
 
216
216
  describe 'Creates Siesta docs' do
217
+ # Siesta already has Docs/
218
+ # Use the default Swift version rather than the specified 4.0
217
219
  behaves_like cli_spec 'document_siesta',
218
- # Siesta already has Docs/
219
- '--output api-docs',
220
- # Use the default Swift version rather than the
221
- # specified 4.0
222
- '--swift-version='
220
+ '--output api-docs ' \
221
+ '--swift-version= '
223
222
  end
224
223
 
225
224
  describe 'Creates docs for Swift project with a variety of contents' do
226
- behaves_like cli_spec 'misc_jazzy_features',
227
- '-b -Xswiftc,-swift-version,-Xswiftc,4.2'
225
+ behaves_like cli_spec 'misc_jazzy_features'
226
+ end
227
+
228
+ describe 'Creates docs for Swift project from a .swiftmodule' do
229
+ build_path = Dir.getwd + 'tmp/.build'
230
+ package_path =
231
+ ROOT + 'spec/integration_specs/misc_jazzy_symgraph_features/before'
232
+ `swift build --package-path #{package_path} --build-path #{build_path}`
233
+ module_path = `swift build --build-path #{build_path} --show-bin-path`
234
+ behaves_like cli_spec 'misc_jazzy_symgraph_features',
235
+ '--swift-build-tool symbolgraph ' \
236
+ "--build-tool-arguments -I=#{module_path} "
228
237
  end
229
238
  end if !spec_subset || spec_subset == 'swift'
230
239
 
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jazzy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.5
4
+ version: 0.13.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - JP Simard
8
8
  - Tim Anglade
9
9
  - Samuel Giddins
10
10
  - John Fairhurst
11
- autorequire:
11
+ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2020-07-06 00:00:00.000000000 Z
14
+ date: 2020-11-08 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: cocoapods
@@ -273,6 +273,13 @@ files:
273
273
  - lib/jazzy/source_module.rb
274
274
  - lib/jazzy/sourcekitten.rb
275
275
  - lib/jazzy/stats.rb
276
+ - lib/jazzy/symbol_graph.rb
277
+ - lib/jazzy/symbol_graph/constraint.rb
278
+ - lib/jazzy/symbol_graph/ext_node.rb
279
+ - lib/jazzy/symbol_graph/graph.rb
280
+ - lib/jazzy/symbol_graph/relationship.rb
281
+ - lib/jazzy/symbol_graph/sym_node.rb
282
+ - lib/jazzy/symbol_graph/symbol.rb
276
283
  - lib/jazzy/themes/apple/assets/css/highlight.css.scss
277
284
  - lib/jazzy/themes/apple/assets/css/jazzy.css.scss
278
285
  - lib/jazzy/themes/apple/assets/img/carat.png
@@ -334,7 +341,7 @@ homepage: https://github.com/realm/jazzy
334
341
  licenses:
335
342
  - MIT
336
343
  metadata: {}
337
- post_install_message:
344
+ post_install_message:
338
345
  rdoc_options: []
339
346
  require_paths:
340
347
  - lib
@@ -349,9 +356,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
349
356
  - !ruby/object:Gem::Version
350
357
  version: '0'
351
358
  requirements: []
352
- rubyforge_project:
353
- rubygems_version: 2.7.3
354
- signing_key:
359
+ rubygems_version: 3.1.4
360
+ signing_key:
355
361
  specification_version: 4
356
362
  summary: Soulful docs for Swift & Objective-C.
357
363
  test_files: []