Skip to content

Commit c286711

Browse files
authored
Better identify Swift default implementations (#1423)
1 parent b6365b4 commit c286711

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
[John Fairhurst](https://github.com/johnfairh)
2121
[#1414](https://github.com/realm/jazzy/issues/1414)
2222

23+
* Better identify default implementations.
24+
[John Fairhurst](https://github.com/johnfairh)
25+
[#1420](https://github.com/realm/jazzy/issues/1420)
26+
2327
## 0.15.3
2428

2529
##### Breaking

lib/jazzy/source_declaration.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,21 @@ def declaration_note
256256
notes.join(', ').upcase_first unless notes.empty?
257257
end
258258

259+
# For matching where `Self` is equivalent without considering
260+
# constraints
261+
def simplified_typename
262+
typename&.gsub(/<Self .*?>/, '<Self>')
263+
end
264+
265+
# Is the candidate `SourceDeclaration` probably a default
266+
# implementation of this declaration?
267+
def default_implementation?(candidate)
268+
name == candidate.name &&
269+
type == candidate.type &&
270+
simplified_typename == candidate.simplified_typename &&
271+
async == candidate.async
272+
end
273+
259274
def readme?
260275
false
261276
end

lib/jazzy/sourcekitten.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -856,9 +856,7 @@ def self.mark_and_merge_protocol_extensions(protocol, extensions)
856856
extensions.each do |ext|
857857
ext.children = ext.children.select do |ext_member|
858858
proto_member = protocol.children.find do |p|
859-
p.name == ext_member.name &&
860-
p.type == ext_member.type &&
861-
p.async == ext_member.async
859+
p.default_implementation?(ext_member)
862860
end
863861

864862
# Extension-only method, keep.

0 commit comments

Comments
 (0)