Skip to content

Commit 7b497f0

Browse files
committed
prevent global funcs/vars from showing up in the sidebar
1 parent 8e73296 commit 7b497f0

19 files changed

+153
-58
lines changed

Sources/UnidocAnalysis/SearchIndex.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ extension SearchIndex
3838
{
3939
static
4040
func nouns(id:ID,
41-
from trees:__shared [Volume.NounTree],
41+
from trees:__shared [Volume.TypeTree],
4242
for modules:__shared [Unidoc.Scalar: ModuleIdentifier]) -> Self
4343
{
4444
let json:JSON = .array
4545
{
46-
for tree:Volume.NounTree in trees
46+
for tree:Volume.TypeTree in trees
4747
{
4848
guard let culture:ModuleIdentifier = modules[tree.id]
4949
else

Sources/UnidocAnalysis/Volume (ext).swift

Lines changed: 73 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ extension Volume
3030
return .init(id: self.names.package, lines: lines)
3131
}
3232
public
33-
func indexes() -> (SearchIndex<VolumeIdentifier>, [NounTree])
33+
func indexes() -> (SearchIndex<VolumeIdentifier>, [TypeTree])
3434
{
3535
var modules:[Unidoc.Scalar: ModuleIdentifier] = [:]
36+
var procs:[Unidoc.Scalar: [Shoot]] = [:]
3637
var types:Types = .init()
3738

3839
for master:Master in self.masters
@@ -48,11 +49,15 @@ extension Volume
4849
case .decl(let master):
4950
switch master.phylum
5051
{
51-
case .actor, .class, .struct, .enum, .protocol,
52-
.func(nil), .var(nil):
52+
case .actor, .class, .struct, .enum, .protocol:
5353
types[master.culture, master.id] = .init(
5454
shoot: master.shoot,
5555
scope: master.scope.last)
56+
57+
case .func(nil), .var(nil):
58+
// Global procedures show up in search, but not in the type tree.
59+
procs[master.culture, default: []].append(master.shoot)
60+
5661
case _:
5762
continue
5863
}
@@ -62,11 +67,71 @@ extension Volume
6267
}
6368
}
6469

65-
let nounTrees:[NounTree] = types.trees()
66-
let nounMap:SearchIndex<VolumeIdentifier> = .nouns(id: self.id,
67-
from: nounTrees,
68-
for: modules)
70+
let trees:[TypeTree] = types.trees()
71+
72+
let json:JSON = .array
73+
{
74+
for tree:TypeTree in trees
75+
{
76+
guard let culture:ModuleIdentifier = modules[tree.id]
77+
else
78+
{
79+
continue
80+
}
81+
82+
$0[+, Any.self]
83+
{
84+
$0["c"] = "\(culture)"
85+
$0["n"]
86+
{
87+
for row:Noun in tree.rows where row.same != nil
88+
{
89+
$0[+, Any.self]
90+
{
91+
$0["s"] = row.shoot.stem.rawValue
92+
$0["h"] = row.shoot.hash?.value
93+
}
94+
}
95+
for shoot:Shoot in procs.removeValue(forKey: tree.id) ?? []
96+
{
97+
$0[+, Any.self]
98+
{
99+
$0["s"] = shoot.stem.rawValue
100+
$0["h"] = shoot.hash?.value
101+
}
102+
}
103+
}
104+
}
105+
}
106+
for (culture, procs):(Unidoc.Scalar, [Shoot]) in
107+
procs.sorted(by: { $0.key < $1.key })
108+
{
109+
guard let culture:ModuleIdentifier = modules[culture]
110+
else
111+
{
112+
continue
113+
}
114+
115+
$0[+, Any.self]
116+
{
117+
$0["c"] = "\(culture)"
118+
$0["n"]
119+
{
120+
for shoot:Shoot in procs
121+
{
122+
$0[+, Any.self]
123+
{
124+
$0["s"] = shoot.stem.rawValue
125+
$0["h"] = shoot.hash?.value
126+
}
127+
}
128+
}
129+
}
130+
}
131+
}
132+
133+
let index:SearchIndex<VolumeIdentifier> = .init(id: self.id, json: json)
69134

70-
return (nounMap, nounTrees)
135+
return (index, trees)
71136
}
72137
}

Sources/UnidocAnalysis/Volume.NounTree.Table.swift renamed to Sources/UnidocAnalysis/Volume.TypeTree.Table.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import BSONEncoding
33
import FNV1
44
import UnidocRecords
55

6-
extension Volume.NounTree
6+
extension Volume.TypeTree
77
{
88
/// A somewhat more-efficient representation for serializing an array of ``Row``s.
99
@frozen @usableFromInline internal
@@ -19,7 +19,7 @@ extension Volume.NounTree
1919
}
2020
}
2121
}
22-
extension Volume.NounTree.Table:BSONEncodable
22+
extension Volume.TypeTree.Table:BSONEncodable
2323
{
2424
@usableFromInline internal
2525
func encode(to field:inout BSON.Field)
@@ -36,7 +36,7 @@ extension Volume.NounTree.Table:BSONEncodable
3636
BSON.BinaryView<[UInt8]>.init(subtype: .generic, slice: buffer).encode(to: &field)
3737
}
3838
}
39-
extension Volume.NounTree.Table:BSONDecodable, BSONBinaryViewDecodable
39+
extension Volume.TypeTree.Table:BSONDecodable, BSONBinaryViewDecodable
4040
{
4141
@inlinable internal
4242
init<Bytes>(bson:BSON.BinaryView<Bytes>) throws

Sources/UnidocAnalysis/Volume.NounTree.swift renamed to Sources/UnidocAnalysis/Volume.TypeTree.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import UnidocRecords
66
extension Volume
77
{
88
@frozen public
9-
struct NounTree:Identifiable, Equatable, Sendable
9+
struct TypeTree:Identifiable, Equatable, Sendable
1010
{
1111
public
1212
let id:Unidoc.Scalar
@@ -21,7 +21,7 @@ extension Volume
2121
}
2222
}
2323
}
24-
extension Volume.NounTree
24+
extension Volume.TypeTree
2525
{
2626
@inlinable internal
2727
init(id:Unidoc.Scalar, table:Table)
@@ -31,7 +31,7 @@ extension Volume.NounTree
3131

3232
var table:Table { .init(rows: self.rows) }
3333
}
34-
extension Volume.NounTree
34+
extension Volume.TypeTree
3535
{
3636
public
3737
enum CodingKey:String
@@ -40,7 +40,7 @@ extension Volume.NounTree
4040
case table = "T"
4141
}
4242
}
43-
extension Volume.NounTree:BSONDocumentEncodable
43+
extension Volume.TypeTree:BSONDocumentEncodable
4444
{
4545
public
4646
func encode(to bson:inout BSON.DocumentEncoder<CodingKey>)
@@ -49,7 +49,7 @@ extension Volume.NounTree:BSONDocumentEncodable
4949
bson[.table] = self.table
5050
}
5151
}
52-
extension Volume.NounTree:BSONDocumentDecodable
52+
extension Volume.TypeTree:BSONDocumentDecodable
5353
{
5454
@inlinable public
5555
init(bson:BSON.DocumentDecoder<CodingKey, some RandomAccessCollection<UInt8>>) throws

Sources/UnidocAnalysis/Volume.Types.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ extension Volume.Types
3232
}
3333
}
3434

35-
func trees() -> [Volume.NounTree]
35+
func trees() -> [Volume.TypeTree]
3636
{
3737
self.cultures.map
3838
{

Sources/UnidocAnalysisTests/Main.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ enum Main:SyncTests
99
static
1010
func run(tests:Tests)
1111
{
12-
if let tests:TestGroup = tests / "NounTree" / "Sorting"
12+
if let tests:TestGroup = tests / "TypeTree" / "Sorting"
1313
{
1414
enum swift
1515
{
@@ -135,8 +135,8 @@ enum Main:SyncTests
135135
latest: true,
136136
patch: nil))
137137

138-
let (_, trees):(_, [Volume.NounTree]) = records.indexes()
139-
if let tree:Volume.NounTree = tests.expect(value: trees.first { $0.id == culture })
138+
let (_, trees):(_, [Volume.TypeTree]) = records.indexes()
139+
if let tree:Volume.TypeTree = tests.expect(value: trees.first { $0.id == culture })
140140
{
141141
tests.expect(tree ==? .init(id: culture, rows:
142142
[
@@ -152,23 +152,23 @@ enum Main:SyncTests
152152
]))
153153
}
154154
}
155-
if let tests:TestGroup = tests / "NounTree" / "RoundTripping"
155+
if let tests:TestGroup = tests / "TypeTree" / "RoundTripping"
156156
{
157157
let id:Unidoc.Scalar = .init(package: 1, version: 2, citizen: 3)
158158

159159
if let tests:TestGroup = tests / "Empty",
160-
tests.roundtrip(Volume.NounTree.init(id: id, rows: []))
160+
tests.roundtrip(Volume.TypeTree.init(id: id, rows: []))
161161
{
162162
}
163163
if let tests:TestGroup = tests / "One",
164-
tests.roundtrip(Volume.NounTree.init(id: id, rows:
164+
tests.roundtrip(Volume.TypeTree.init(id: id, rows:
165165
[
166166
.init(stem: "CryptoKit BTC"),
167167
]))
168168
{
169169
}
170170
if let tests:TestGroup = tests / "Many",
171-
tests.roundtrip(Volume.NounTree.init(id: id, rows:
171+
tests.roundtrip(Volume.TypeTree.init(id: id, rows:
172172
[
173173
.init(stem: "CryptoKit BTC"),
174174
.init(stem: "CryptoKit ETH"),
@@ -178,7 +178,7 @@ enum Main:SyncTests
178178
{
179179
}
180180
if let tests:TestGroup = tests / "Hashed",
181-
tests.roundtrip(Volume.NounTree.init(id: id, rows:
181+
tests.roundtrip(Volume.TypeTree.init(id: id, rows:
182182
[
183183
.init(stem: "CryptoKit BTC"),
184184
.init(stem: "CryptoKit ETH"),
@@ -192,7 +192,7 @@ enum Main:SyncTests
192192
{
193193
}
194194
if let tests:TestGroup = tests / "Races",
195-
tests.roundtrip(Volume.NounTree.init(id: id, rows:
195+
tests.roundtrip(Volume.TypeTree.init(id: id, rows:
196196
[
197197
.init(stem: "CryptoKit ETH Classic\tinit(_:)",
198198
hash: .init(hashing: "the’ir"),

Sources/UnidocDatabase/Database/Database.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ extension Database
226226
func push(_ volume:__owned Volume,
227227
with session:__shared Mongo.Session) async throws
228228
{
229-
let (index, trees):(SearchIndex<VolumeIdentifier>, [Volume.NounTree]) = volume.indexes()
229+
let (index, trees):(SearchIndex<VolumeIdentifier>, [Volume.TypeTree]) = volume.indexes()
230230

231231
try await self.masters.insert(volume.masters, with: session)
232232
try await self.names.insert(volume.names, with: session)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Sources
2+
3+
extension DynamicContext.SortPriority
4+
{
5+
enum Constructor:Equatable, Comparable
6+
{
7+
/// Enumeration cases sort by their declaration order. Because it is impossible for
8+
/// them to appear in a different file than the enum’s declaration, we can simply use
9+
/// the source position of the case declaration.
10+
case `case`(SourcePosition)
11+
case initializer
12+
case `var`
13+
case `subscript`
14+
case `func`
15+
}
16+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
extension DynamicContext.SortPriority
2+
{
3+
enum Member:Equatable, Comparable
4+
{
5+
case `var`
6+
case `subscript`
7+
case `operator`
8+
case `func`
9+
}
10+
}

Sources/UnidocLinker/Groups/DynamicContext.SortPriority.Phylum.swift

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,14 @@ extension DynamicContext.SortPriority
1414
/// Enumeration cases sort by their declaration order. Because it is impossible for
1515
/// them to appear in a different file than the enum’s declaration, we can simply use
1616
/// the source position of the case declaration.
17-
case `case`(SourcePosition)
18-
case initializer
19-
case deinitializer
17+
case constructor(Constructor)
18+
case `class`(Member)
19+
case destructor
20+
case instance(Member)
2021

2122
case `protocol`
2223
case type
2324
case `typealias`
24-
25-
case `subscript`(Unidoc.Decl.Objectivity)
26-
case `operator`
27-
case property(Unidoc.Decl.Objectivity)
28-
case method(Unidoc.Decl.Objectivity)
2925
}
3026
}
3127
extension DynamicContext.SortPriority.Phylum
@@ -37,21 +33,29 @@ extension DynamicContext.SortPriority.Phylum
3733
case .var(nil): self = .var
3834
case .func(nil): self = .func
3935
case .associatedtype: self = .associatedtype
40-
case .case: self = .case(position ?? .zero)
41-
case .initializer: self = .initializer
42-
case .deinitializer: self = .deinitializer
43-
case .protocol: self = .protocol
4436

37+
case .case: self = .constructor(.case(position ?? .zero))
38+
case .initializer: self = .constructor(.initializer)
39+
case .var(.static): self = .constructor(.var)
40+
case .subscript(.static): self = .constructor(.subscript)
41+
case .func(.static): self = .constructor(.func)
42+
43+
case .var(.class): self = .class(.var)
44+
case .subscript(.class): self = .class(.subscript)
45+
case .func(.class): self = .class(.func)
46+
case .deinitializer: self = .destructor
47+
48+
case .var(.instance): self = .instance(.var)
49+
case .subscript(.instance): self = .instance(.subscript)
50+
case .operator: self = .instance(.operator)
51+
case .func(.instance): self = .instance(.func)
52+
53+
case .protocol: self = .protocol
4554
case .actor,
4655
.class,
4756
.enum,
4857
.struct: self = .type
49-
5058
case .typealias: self = .typealias
51-
case .subscript(let objectivity): self = .subscript(objectivity)
52-
case .operator: self = .operator
53-
case .var(let objectivity?): self = .property(objectivity)
54-
case .func(let objectivity?): self = .method(objectivity)
5559
}
5660
}
5761
}

0 commit comments

Comments
 (0)