jazzy 0.13.4 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/Tests.yml +52 -0
  3. data/.rubocop.yml +123 -24
  4. data/CHANGELOG.md +103 -0
  5. data/CONTRIBUTING.md +5 -5
  6. data/Dangerfile +11 -8
  7. data/Gemfile +3 -1
  8. data/Gemfile.lock +91 -69
  9. data/README.md +85 -13
  10. data/Rakefile +19 -13
  11. data/bin/jazzy +3 -2
  12. data/bin/sourcekitten +0 -0
  13. data/jazzy.gemspec +8 -6
  14. data/js/package-lock.json +30 -25
  15. data/js/package.json +3 -3
  16. data/lib/jazzy.rb +2 -0
  17. data/lib/jazzy/config.rb +124 -70
  18. data/lib/jazzy/doc.rb +3 -1
  19. data/lib/jazzy/doc_builder.rb +75 -81
  20. data/lib/jazzy/docset_builder.rb +3 -1
  21. data/lib/jazzy/documentation_generator.rb +6 -2
  22. data/lib/jazzy/executable.rb +3 -0
  23. data/lib/jazzy/extensions/bitbucket/img/bitbucket.svg +11 -0
  24. data/lib/jazzy/{themes/apple/assets → extensions/github}/img/gh.png +0 -0
  25. data/lib/jazzy/extensions/gitlab/img/gitlab.svg +23 -0
  26. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_AMS-Regular.ttf +0 -0
  27. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_AMS-Regular.woff +0 -0
  28. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_AMS-Regular.woff2 +0 -0
  29. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Caligraphic-Bold.ttf +0 -0
  30. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Caligraphic-Bold.woff +0 -0
  31. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Caligraphic-Bold.woff2 +0 -0
  32. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Caligraphic-Regular.ttf +0 -0
  33. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Caligraphic-Regular.woff +0 -0
  34. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Caligraphic-Regular.woff2 +0 -0
  35. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Fraktur-Bold.ttf +0 -0
  36. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Fraktur-Bold.woff +0 -0
  37. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Fraktur-Bold.woff2 +0 -0
  38. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Fraktur-Regular.ttf +0 -0
  39. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Fraktur-Regular.woff +0 -0
  40. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Fraktur-Regular.woff2 +0 -0
  41. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Main-Bold.ttf +0 -0
  42. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Main-Bold.woff +0 -0
  43. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Main-Bold.woff2 +0 -0
  44. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Main-BoldItalic.ttf +0 -0
  45. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Main-BoldItalic.woff +0 -0
  46. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Main-BoldItalic.woff2 +0 -0
  47. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Main-Italic.ttf +0 -0
  48. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Main-Italic.woff +0 -0
  49. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Main-Italic.woff2 +0 -0
  50. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Main-Regular.ttf +0 -0
  51. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Main-Regular.woff +0 -0
  52. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Main-Regular.woff2 +0 -0
  53. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Math-BoldItalic.ttf +0 -0
  54. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Math-BoldItalic.woff +0 -0
  55. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Math-BoldItalic.woff2 +0 -0
  56. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Math-Italic.ttf +0 -0
  57. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Math-Italic.woff +0 -0
  58. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Math-Italic.woff2 +0 -0
  59. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_SansSerif-Bold.ttf +0 -0
  60. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_SansSerif-Bold.woff +0 -0
  61. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_SansSerif-Bold.woff2 +0 -0
  62. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_SansSerif-Italic.ttf +0 -0
  63. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_SansSerif-Italic.woff +0 -0
  64. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_SansSerif-Italic.woff2 +0 -0
  65. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_SansSerif-Regular.ttf +0 -0
  66. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_SansSerif-Regular.woff +0 -0
  67. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_SansSerif-Regular.woff2 +0 -0
  68. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Script-Regular.ttf +0 -0
  69. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Script-Regular.woff +0 -0
  70. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Script-Regular.woff2 +0 -0
  71. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Size1-Regular.ttf +0 -0
  72. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Size1-Regular.woff +0 -0
  73. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Size1-Regular.woff2 +0 -0
  74. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Size2-Regular.ttf +0 -0
  75. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Size2-Regular.woff +0 -0
  76. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Size2-Regular.woff2 +0 -0
  77. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Size3-Regular.ttf +0 -0
  78. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Size3-Regular.woff +0 -0
  79. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Size3-Regular.woff2 +0 -0
  80. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Size4-Regular.ttf +0 -0
  81. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Size4-Regular.woff +0 -0
  82. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Size4-Regular.woff2 +0 -0
  83. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Typewriter-Regular.ttf +0 -0
  84. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Typewriter-Regular.woff +0 -0
  85. data/lib/jazzy/extensions/katex/css/fonts/KaTeX_Typewriter-Regular.woff2 +0 -0
  86. data/lib/jazzy/extensions/katex/css/katex.min.css +1 -1
  87. data/lib/jazzy/extensions/katex/js/katex.min.js +1 -1
  88. data/lib/jazzy/gem_version.rb +3 -1
  89. data/lib/jazzy/highlighter.rb +5 -3
  90. data/lib/jazzy/jazzy_markdown.rb +101 -30
  91. data/lib/jazzy/podspec_documenter.rb +14 -16
  92. data/lib/jazzy/search_builder.rb +4 -3
  93. data/lib/jazzy/source_declaration.rb +24 -5
  94. data/lib/jazzy/source_declaration/access_control_level.rb +7 -5
  95. data/lib/jazzy/source_declaration/type.rb +33 -1
  96. data/lib/jazzy/source_document.rb +8 -5
  97. data/lib/jazzy/source_host.rb +111 -0
  98. data/lib/jazzy/source_mark.rb +8 -6
  99. data/lib/jazzy/source_module.rb +6 -6
  100. data/lib/jazzy/sourcekitten.rb +105 -79
  101. data/lib/jazzy/stats.rb +4 -2
  102. data/lib/jazzy/symbol_graph.rb +95 -0
  103. data/lib/jazzy/symbol_graph/constraint.rb +98 -0
  104. data/lib/jazzy/symbol_graph/ext_node.rb +116 -0
  105. data/lib/jazzy/symbol_graph/graph.rb +195 -0
  106. data/lib/jazzy/symbol_graph/relationship.rb +42 -0
  107. data/lib/jazzy/symbol_graph/sym_node.rb +163 -0
  108. data/lib/jazzy/symbol_graph/symbol.rb +222 -0
  109. data/lib/jazzy/themes/apple/assets/css/highlight.css.scss +63 -59
  110. data/lib/jazzy/themes/apple/assets/css/jazzy.css.scss +101 -4
  111. data/lib/jazzy/themes/apple/assets/img/spinner.gif +0 -0
  112. data/lib/jazzy/themes/apple/assets/js/jazzy.js +4 -0
  113. data/lib/jazzy/themes/apple/assets/js/jazzy.search.js +74 -0
  114. data/lib/jazzy/themes/apple/assets/js/jquery.min.js +2 -2
  115. data/lib/jazzy/themes/apple/assets/js/lunr.min.js +6 -0
  116. data/lib/jazzy/themes/apple/assets/js/typeahead.jquery.js +1694 -0
  117. data/lib/jazzy/themes/apple/templates/doc.mustache +35 -0
  118. data/lib/jazzy/themes/apple/templates/footer.mustache +1 -1
  119. data/lib/jazzy/themes/apple/templates/header.mustache +10 -3
  120. data/lib/jazzy/themes/apple/templates/task.mustache +4 -4
  121. data/lib/jazzy/themes/fullwidth/assets/css/highlight.css.scss +63 -59
  122. data/lib/jazzy/themes/fullwidth/assets/css/jazzy.css.scss +11 -2
  123. data/lib/jazzy/themes/fullwidth/assets/js/jazzy.js +4 -0
  124. data/lib/jazzy/themes/fullwidth/assets/js/jazzy.search.js +4 -0
  125. data/lib/jazzy/themes/fullwidth/assets/js/jquery.min.js +2 -2
  126. data/lib/jazzy/themes/fullwidth/assets/js/lunr.min.js +3 -3
  127. data/lib/jazzy/themes/fullwidth/templates/doc.mustache +30 -0
  128. data/lib/jazzy/themes/fullwidth/templates/footer.mustache +1 -1
  129. data/lib/jazzy/themes/fullwidth/templates/header.mustache +5 -5
  130. data/lib/jazzy/themes/fullwidth/templates/task.mustache +4 -4
  131. data/lib/jazzy/themes/jony/assets/css/highlight.css.scss +63 -59
  132. data/lib/jazzy/themes/jony/assets/css/jazzy.css.scss +34 -2
  133. data/lib/jazzy/themes/jony/assets/js/jazzy.js +4 -0
  134. data/lib/jazzy/themes/jony/assets/js/jquery.min.js +2 -2
  135. data/lib/jazzy/themes/jony/templates/doc.mustache +30 -0
  136. data/lib/jazzy/themes/jony/templates/footer.mustache +1 -1
  137. data/lib/jazzy/themes/jony/templates/header.mustache +5 -5
  138. data/lib/jazzy/themes/jony/templates/task.mustache +4 -4
  139. data/spec/integration_spec.rb +54 -42
  140. data/spec/spec_helper.rb +3 -1
  141. data/spec/spec_helper/pre_flight.rb +2 -0
  142. metadata +43 -19
  143. data/.circleci/config.yml +0 -83
  144. data/lib/jazzy/themes/fullwidth/assets/img/gh.png +0 -0
  145. data/lib/jazzy/themes/jony/assets/img/gh.png +0 -0
  146. data/spec/sourcekitten_spec.rb +0 -6
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jazzy
4
+ module SymbolGraph
5
+ # A Relationship is a tidied-up SymbolGraph JSON object
6
+ class Relationship
7
+ attr_accessor :kind
8
+ attr_accessor :source_usr
9
+ attr_accessor :target_usr
10
+ attr_accessor :target_fallback # can be nil
11
+ attr_accessor :constraints # array, can be empty
12
+
13
+ KINDS = %w[memberOf conformsTo defaultImplementationOf
14
+ overrides inheritsFrom requirementOf
15
+ optionalRequirementOf].freeze
16
+
17
+ def protocol_requirement?
18
+ %i[requirementOf optionalRequirementOf].include? kind
19
+ end
20
+
21
+ def default_implementation?
22
+ kind == :defaultImplementationOf
23
+ end
24
+
25
+ def initialize(hash)
26
+ kind = hash[:kind]
27
+ unless KINDS.include?(kind)
28
+ raise "Unknown relationship kind '#{kind}'"
29
+ end
30
+
31
+ self.kind = kind.to_sym
32
+ self.source_usr = hash[:source]
33
+ self.target_usr = hash[:target]
34
+ if fallback = hash[:targetFallback]
35
+ # Strip the leading module name
36
+ self.target_fallback = fallback.sub(/^.*?\./, '')
37
+ end
38
+ self.constraints = Constraint.new_list(hash[:swiftConstraints] || [])
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,163 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jazzy
4
+ module SymbolGraph
5
+ # The rebuilt syntax tree is made of nodes that either match
6
+ # symbols or that we fabricate for extensions. This is the common
7
+ # treeishness.
8
+ class BaseNode
9
+ attr_accessor :children # array, can be empty
10
+ attr_accessor :parent # can be nil
11
+
12
+ def initialize
13
+ self.children = []
14
+ end
15
+
16
+ def add_child(child)
17
+ child.parent = self
18
+ children.append(child)
19
+ end
20
+
21
+ def children_to_sourcekit
22
+ children.sort.map(&:to_sourcekit)
23
+ end
24
+ end
25
+
26
+ # A SymNode is a node of the reconstructed syntax tree holding a symbol.
27
+ # It can turn itself into SourceKit and helps decode extensions.
28
+ class SymNode < BaseNode
29
+ attr_accessor :symbol
30
+ attr_writer :override
31
+ attr_writer :protocol_requirement
32
+ attr_writer :unlisted
33
+ attr_accessor :superclass_name
34
+
35
+ def override?
36
+ @override
37
+ end
38
+
39
+ def protocol_requirement?
40
+ @protocol_requirement
41
+ end
42
+
43
+ def top_level_decl?
44
+ !@unlisted && parent.nil?
45
+ end
46
+
47
+ def initialize(symbol)
48
+ self.symbol = symbol
49
+ super()
50
+ end
51
+
52
+ def qualified_name
53
+ symbol.path_components.join('.')
54
+ end
55
+
56
+ def parent_qualified_name
57
+ symbol.path_components[0...-1].join('.')
58
+ end
59
+
60
+ def protocol?
61
+ symbol.kind.end_with?('protocol')
62
+ end
63
+
64
+ def constraints
65
+ symbol.constraints
66
+ end
67
+
68
+ # Add another SymNode as a member if possible.
69
+ # It must go in an extension if either:
70
+ # - it has different generic constraints to us; or
71
+ # - we're a protocol and it's a default impl / ext method
72
+ def try_add_child(node, unique_context_constraints)
73
+ unless unique_context_constraints.empty? &&
74
+ (!protocol? || node.protocol_requirement?)
75
+ return false
76
+ end
77
+
78
+ add_child(node)
79
+ true
80
+ end
81
+
82
+ # The `Constraint`s on this decl that are both:
83
+ # 1. Unique, ie. not just inherited from its context; and
84
+ # 2. Constraining the *context's* gen params rather than our own.
85
+ def unique_context_constraints(context)
86
+ return symbol.constraints unless context
87
+
88
+ new_generic_type_params =
89
+ symbol.generic_type_params - context.symbol.generic_type_params
90
+
91
+ (symbol.constraints - context.symbol.constraints)
92
+ .select { |con| con.type_names.disjoint?(new_generic_type_params) }
93
+ end
94
+
95
+ # Messy check whether we need to fabricate an extension for a protocol
96
+ # conformance: don't bother if it's already in the type declaration.
97
+ def conformance?(protocol)
98
+ return false unless symbol.declaration =~ /(?<=:).*?(?=(where|$))/
99
+
100
+ Regexp.last_match[0] =~ /\b#{protocol}\b/
101
+ end
102
+
103
+ # Generate the 'where' clause for the declaration
104
+ def where_clause
105
+ parent_constraints = parent&.constraints || []
106
+ (constraints - parent_constraints).to_where_clause
107
+ end
108
+
109
+ def inherits_clause
110
+ return '' unless superclass_name
111
+
112
+ " : #{superclass_name}"
113
+ end
114
+
115
+ def full_declaration
116
+ symbol.availability
117
+ .append(symbol.declaration + inherits_clause + where_clause)
118
+ .join("\n")
119
+ end
120
+
121
+ # rubocop:disable Metrics/MethodLength
122
+ def to_sourcekit
123
+ declaration = full_declaration
124
+ xml_declaration = "<swift>#{CGI.escapeHTML(declaration)}</swift>"
125
+
126
+ hash = {
127
+ 'key.kind' => symbol.kind,
128
+ 'key.usr' => symbol.usr,
129
+ 'key.name' => symbol.name,
130
+ 'key.accessibility' => symbol.acl,
131
+ 'key.parsed_decl' => declaration,
132
+ 'key.annotated_decl' => xml_declaration,
133
+ }
134
+ if docs = symbol.doc_comments
135
+ hash['key.doc.comment'] = docs
136
+ hash['key.doc.full_as_xml'] = ''
137
+ end
138
+ if params = symbol.parameter_names
139
+ hash['key.doc.parameters'] =
140
+ params.map { |name| { 'name' => name } }
141
+ end
142
+ if location = symbol.location
143
+ hash['key.filepath'] = location[:filename]
144
+ hash['key.doc.line'] = location[:line] + 1
145
+ hash['key.doc.column'] = location[:character] + 1
146
+ end
147
+ unless children.empty?
148
+ hash['key.substructure'] = children_to_sourcekit
149
+ end
150
+
151
+ hash
152
+ end
153
+ # rubocop:enable Metrics/MethodLength
154
+
155
+ # Sort order - by symbol
156
+ include Comparable
157
+
158
+ def <=>(other)
159
+ symbol <=> other.symbol
160
+ end
161
+ end
162
+ end
163
+ end
@@ -0,0 +1,222 @@
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 :location # can be nil, keys :filename :line :character
14
+ attr_accessor :constraints # array, can be empty
15
+ attr_accessor :doc_comments # can be nil
16
+ attr_accessor :availability # array, can be empty
17
+ attr_accessor :generic_type_params # set, can be empty
18
+ attr_accessor :parameter_names # array, can be nil
19
+
20
+ def name
21
+ path_components[-1] || '??'
22
+ end
23
+
24
+ def initialize(hash)
25
+ self.usr = hash[:identifier][:precise]
26
+ self.path_components = hash[:pathComponents]
27
+ raw_decl = hash[:declarationFragments].map { |f| f[:spelling] }.join
28
+ init_kind(hash[:kind][:identifier])
29
+ init_declaration(raw_decl)
30
+ if func_signature = hash[:functionSignature]
31
+ init_func_signature(func_signature)
32
+ end
33
+ init_acl(hash[:accessLevel])
34
+ if location = hash[:location]
35
+ init_location(location)
36
+ end
37
+ init_constraints(hash, raw_decl)
38
+ if comments_hash = hash[:docComment]
39
+ init_doc_comments(comments_hash)
40
+ end
41
+ init_availability(hash[:availability] || [])
42
+ init_generic_type_params(hash)
43
+ end
44
+
45
+ # Repair problems with SymbolGraph's declprinter
46
+
47
+ def init_declaration(raw_decl)
48
+ # Too much 'Self.TypeName'; omitted arg labels look odd;
49
+ # duplicated constraints; swift 5.3 vs. master workaround
50
+ self.declaration = raw_decl
51
+ .gsub(/\bSelf\./, '')
52
+ .gsub(/(?<=\(|, )_: /, '_ arg: ')
53
+ .gsub(/ where.*$/, '')
54
+ if kind == 'source.lang.swift.decl.class'
55
+ declaration.sub!(/\s*:.*$/, '')
56
+ end
57
+ end
58
+
59
+ # Remember pieces of methods for later markdown parsing
60
+
61
+ def init_func_signature(func_signature)
62
+ self.parameter_names =
63
+ (func_signature[:parameters] || []).map { |h| h[:name] }
64
+ end
65
+
66
+ # Mapping SymbolGraph's declkinds to SourceKit
67
+
68
+ KIND_MAP = {
69
+ 'class' => 'class',
70
+ 'struct' => 'struct',
71
+ 'enum' => 'enum',
72
+ 'enum.case' => 'enumelement', # intentional
73
+ 'protocol' => 'protocol',
74
+ 'init' => 'function.constructor',
75
+ 'deinit' => 'function.destructor',
76
+ 'func.op' => 'function.operator',
77
+ 'type.method' => 'function.method.class',
78
+ 'static.method' => 'function.method.static',
79
+ 'method' => 'function.method.instance',
80
+ 'func' => 'function.free',
81
+ 'type.property' => 'var.class',
82
+ 'static.property' => 'var.static',
83
+ 'property' => 'var.instance',
84
+ 'var' => 'var.global',
85
+ 'subscript' => 'function.subscript',
86
+ 'type.subscript' => 'function.subscript',
87
+ 'static.subscript' => 'function.subscript',
88
+ 'typealias' => 'typealias',
89
+ 'associatedtype' => 'associatedtype',
90
+ }.freeze
91
+
92
+ # We treat 'static var' differently to 'class var'
93
+ def adjust_kind_for_declaration(kind)
94
+ return kind unless declaration =~ /\bstatic\b/
95
+
96
+ kind.gsub(/type/, 'static')
97
+ end
98
+
99
+ def init_kind(kind)
100
+ adjusted = adjust_kind_for_declaration(kind)
101
+ sourcekit_kind = KIND_MAP[adjusted.sub('swift.', '')]
102
+ raise "Unknown symbol kind '#{kind}'" unless sourcekit_kind
103
+
104
+ self.kind = "source.lang.swift.decl.#{sourcekit_kind}"
105
+ end
106
+
107
+ # Mapping SymbolGraph's ACL to SourceKit
108
+
109
+ def init_acl(acl)
110
+ self.acl = "source.lang.swift.accessibility.#{acl}"
111
+ end
112
+
113
+ # Symbol location - only available for public+ decls
114
+
115
+ def init_location(loc_hash)
116
+ self.location = {}
117
+ location[:filename] = loc_hash[:uri].sub(%r{^file://}, '')
118
+ location[:line] = loc_hash[:position][:line]
119
+ location[:character] = loc_hash[:position][:character]
120
+ end
121
+
122
+ # Generic constraints: in one or both of two places.
123
+ # There can be duplicates; these are removed by `Constraint`.
124
+ def init_constraints(hash, raw_decl)
125
+ raw_constraints = %i[swiftGenerics swiftExtension].flat_map do |key|
126
+ next [] unless container = hash[key]
127
+
128
+ container[:constraints] || []
129
+ end
130
+
131
+ constraints =
132
+ Constraint.new_list_for_symbol(raw_constraints, path_components)
133
+ if raw_decl =~ / where (.*)$/
134
+ constraints +=
135
+ Constraint.new_list_from_declaration(Regexp.last_match[1])
136
+ end
137
+
138
+ self.constraints = constraints.sort.uniq
139
+ end
140
+
141
+ # Generic type params
142
+ def init_generic_type_params(hash)
143
+ self.generic_type_params = Set.new(
144
+ if (generics = hash[:swiftGenerics]) &&
145
+ (parameters = generics[:parameters])
146
+ parameters.map { |p| p[:name] }
147
+ else
148
+ []
149
+ end,
150
+ )
151
+ end
152
+
153
+ def init_doc_comments(comments_hash)
154
+ self.doc_comments = comments_hash[:lines]
155
+ .map { |l| l[:text] }
156
+ .join("\n")
157
+ end
158
+
159
+ # Availability
160
+ # Re-encode this as Swift. Should really teach Jazzy about these,
161
+ # could maybe then do something smarter here.
162
+ def init_availability(avail_hash_list)
163
+ self.availability = avail_hash_list.map do |avail|
164
+ str = '@available('
165
+ if avail[:isUnconditionallyDeprecated]
166
+ str += '*, deprecated'
167
+ elsif domain = avail[:domain]
168
+ str += domain
169
+ %i[introduced deprecated obsoleted].each do |event|
170
+ if version = avail[event]
171
+ str += ", #{event}: #{decode_version(version)}"
172
+ end
173
+ end
174
+ else
175
+ warn "Found confusing availability: #{avail}"
176
+ next nil
177
+ end
178
+
179
+ str += ", message: \"#{avail[:message]}\"" if avail[:message]
180
+ str += ", renamed: \"#{avail[:renamed]}\"" if avail[:renamed]
181
+
182
+ str + ')'
183
+ end.compact
184
+ end
185
+
186
+ def decode_version(hash)
187
+ str = hash[:major].to_s
188
+ str += ".#{hash[:minor]}" if hash[:minor]
189
+ str += ".#{hash[:patch]}" if hash[:patch]
190
+ str
191
+ end
192
+
193
+ # Sort order
194
+ include Comparable
195
+
196
+ def <=>(other)
197
+ # Things with location: order by file/line/column
198
+ # (pls tell what wheel i am reinventing :/)
199
+ if location && other_loc = other.location
200
+ if location[:filename] == other_loc[:filename]
201
+ if location[:line] == other_loc[:line]
202
+ return location[:character] <=> other_loc[:character]
203
+ end
204
+
205
+ return location[:line] <=> other_loc[:line]
206
+ end
207
+ return location[:filename] <=> other_loc[:filename]
208
+ end
209
+
210
+ # Things with a location before things without a location
211
+ return +1 if location.nil? && other.location
212
+ return -1 if location && other.location.nil?
213
+
214
+ # Things without a location: by name and then USR
215
+ return usr <=> other.usr if name == other.name
216
+
217
+ name <=> other.name
218
+ end
219
+ end
220
+ end
221
+ end
222
+ # rubocop:enable Metrics/ClassLength
@@ -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 } /* Comment */
5
- .err { color: #a61717; background-color: #e3d2d2 } /* Error */
6
- .k { color: #000000; font-weight: bold } /* Keyword */
7
- .o { color: #000000; font-weight: bold } /* Operator */
8
- .cm { color: #999988; font-style: italic } /* Comment.Multiline */
9
- .cp { color: #999999; font-weight: bold } /* Comment.Preproc */
10
- .c1 { color: #999988; font-style: italic } /* Comment.Single */
11
- .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */
12
- .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
13
- .gd .x { color: #000000; background-color: #ffaaaa } /* Generic.Deleted.Specific */
14
- .ge { color: #000000; font-style: italic } /* Generic.Emph */
15
- .gr { color: #aa0000 } /* Generic.Error */
16
- .gh { color: #999999 } /* Generic.Heading */
17
- .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
18
- .gi .x { color: #000000; background-color: #aaffaa } /* Generic.Inserted.Specific */
19
- .go { color: #888888 } /* Generic.Output */
20
- .gp { color: #555555 } /* Generic.Prompt */
21
- .gs { font-weight: bold } /* Generic.Strong */
22
- .gu { color: #aaaaaa } /* Generic.Subheading */
23
- .gt { color: #aa0000 } /* Generic.Traceback */
24
- .kc { color: #000000; font-weight: bold } /* Keyword.Constant */
25
- .kd { color: #000000; font-weight: bold } /* Keyword.Declaration */
26
- .kp { color: #000000; font-weight: bold } /* Keyword.Pseudo */
27
- .kr { color: #000000; font-weight: bold } /* Keyword.Reserved */
28
- .kt { color: #445588; } /* Keyword.Type */
29
- .m { color: #009999 } /* Literal.Number */
30
- .s { color: #d14 } /* Literal.String */
31
- .na { color: #008080 } /* Name.Attribute */
32
- .nb { color: #0086B3 } /* Name.Builtin */
33
- .nc { color: #445588; font-weight: bold } /* Name.Class */
34
- .no { color: #008080 } /* Name.Constant */
35
- .ni { color: #800080 } /* Name.Entity */
36
- .ne { color: #990000; font-weight: bold } /* Name.Exception */
37
- .nf { color: #990000; } /* Name.Function */
38
- .nn { color: #555555 } /* Name.Namespace */
39
- .nt { color: #000080 } /* Name.Tag */
40
- .nv { color: #008080 } /* Name.Variable */
41
- .ow { color: #000000; font-weight: bold } /* Operator.Word */
42
- .w { color: #bbbbbb } /* Text.Whitespace */
43
- .mf { color: #009999 } /* Literal.Number.Float */
44
- .mh { color: #009999 } /* Literal.Number.Hex */
45
- .mi { color: #009999 } /* Literal.Number.Integer */
46
- .mo { color: #009999 } /* Literal.Number.Oct */
47
- .sb { color: #d14 } /* Literal.String.Backtick */
48
- .sc { color: #d14 } /* Literal.String.Char */
49
- .sd { color: #d14 } /* Literal.String.Doc */
50
- .s2 { color: #d14 } /* Literal.String.Double */
51
- .se { color: #d14 } /* Literal.String.Escape */
52
- .sh { color: #d14 } /* Literal.String.Heredoc */
53
- .si { color: #d14 } /* Literal.String.Interpol */
54
- .sx { color: #d14 } /* Literal.String.Other */
55
- .sr { color: #009926 } /* Literal.String.Regex */
56
- .s1 { color: #d14 } /* Literal.String.Single */
57
- .ss { color: #990073 } /* Literal.String.Symbol */
58
- .bp { color: #999999 } /* Name.Builtin.Pseudo */
59
- .vc { color: #008080 } /* Name.Variable.Class */
60
- .vg { color: #008080 } /* Name.Variable.Global */
61
- .vi { color: #008080 } /* Name.Variable.Instance */
62
- .il { color: #009999 } /* Literal.Number.Integer.Long */
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
  }