Skip to content

Commit db6f05f

Browse files
authored
Merge pull request #130 from tayloraswift/snippet-support
Snippet support
2 parents fdf22cd + 31d46a1 commit db6f05f

File tree

253 files changed

+3748
-1946
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

253 files changed

+3748
-1946
lines changed

Package.resolved

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ let package:Package = .init(
9999
.package(url: "https://github.com/tayloraswift/swift-hash", .upToNextMinor(
100100
from: "0.5.0")),
101101
.package(url: "https://github.com/tayloraswift/swift-mongodb", .upToNextMinor(
102-
from: "0.12.0")),
102+
from: "0.12.1")),
103103
//.package(path: "../swift-mongodb"),
104104

105105
.package(url: "https://github.com/tayloraswift/swift-png", .upToNextMinor(
@@ -108,14 +108,17 @@ let package:Package = .init(
108108
.package(url: "https://github.com/apple/swift-atomics", .upToNextMinor(
109109
from: "1.2.0")),
110110

111+
.package(url: "https://github.com/apple/swift-collections.git", .upToNextMinor(
112+
from: "1.1.0")),
113+
111114
/// swift-nio has a low rate of breakage, and can be trusted with a major-only
112115
/// version requirement.
113116
.package(url: "https://github.com/apple/swift-nio",
114-
from: "2.62.0"),
117+
from: "2.63.0"),
115118
/// swift-nio-ssl has a low rate of breakage, and can be trusted with a
116119
/// major-only version requirement.
117120
.package(url: "https://github.com/apple/swift-nio-ssl",
118-
from: "2.25.0"),
121+
from: "2.26.0"),
119122

120123
.package(url: "https://github.com/apple/swift-nio-http2", .upToNextMinor(
121124
from: "1.29.0")),
@@ -127,7 +130,7 @@ let package:Package = .init(
127130
.package(url: "https://github.com/apple/swift-system", .upToNextMinor(
128131
from: "1.2.1")),
129132
.package(url: "https://github.com/apple/swift-syntax",
130-
exact: "509.0.2"),
133+
exact: "509.1.1"),
131134
],
132135
targets:
133136
[
@@ -320,6 +323,7 @@ let package:Package = .init(
320323
[
321324
.target(name: "MarkdownABI"),
322325
.target(name: "Signatures"),
326+
.target(name: "Snippets"),
323327
.target(name: "Symbols"),
324328

325329
.product(name: "SwiftIDEUtils", package: "swift-syntax"),
@@ -331,7 +335,10 @@ let package:Package = .init(
331335
.target(name: "Codelinks"),
332336
.target(name: "MarkdownAST"),
333337
.target(name: "Sources"),
338+
.target(name: "Snippets"),
334339
.target(name: "UnidocDiagnostics"),
340+
341+
.product(name: "OrderedCollections", package: "swift-collections"),
335342
]),
336343

337344
.target(name: "MD5", dependencies:
@@ -391,6 +398,11 @@ let package:Package = .init(
391398
.target(name: "DOM"),
392399
]),
393400

401+
.target(name: "Snippets", dependencies:
402+
[
403+
.target(name: "MarkdownABI"),
404+
]),
405+
394406
.target(name: "Sources"),
395407

396408
.target(name: "Swiftinit", dependencies:
@@ -460,9 +472,11 @@ let package:Package = .init(
460472
.target(name: "InlineArray"),
461473
.target(name: "InlineDictionary"),
462474
.target(name: "MarkdownParsing"),
475+
.target(name: "MarkdownRendering"),
463476
.target(name: "MarkdownSemantics"),
464477
.target(name: "SemanticVersions"),
465478
.target(name: "SHA1"),
479+
.target(name: "Snippets"),
466480
.target(name: "SymbolGraphCompiler"),
467481
.target(name: "SymbolGraphs"),
468482
.target(name: "Symbols"),
@@ -474,6 +488,12 @@ let package:Package = .init(
474488
[
475489
.target(name: "JSON"),
476490
.target(name: "LexicalPaths"),
491+
// This is the point where the symbol graph compiler becomes infected with a
492+
// (non-macro) SwiftSyntax dependency.
493+
//
494+
// This also means that the static symbol graph linker can freely use any
495+
// of the SwiftSyntax-powered plugins, since we have already paid for the
496+
// dependency.
477497
.target(name: "MarkdownPluginSwift"),
478498
.target(name: "Signatures"),
479499
.target(name: "Symbols"),

Sources/CodelinkResolution/CodelinkResolver.Scope.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ extension CodelinkResolver
66
struct Scope
77
{
88
public
9-
let namespace:Symbol.Module
9+
let namespace:Symbol.Module?
1010
public
1111
let imports:[Symbol.Module]
1212
public
1313
let path:[String]
1414

1515
@inlinable public
16-
init(namespace:Symbol.Module, imports:[Symbol.Module] = [], path:[String] = [])
16+
init(namespace:Symbol.Module?, imports:[Symbol.Module] = [], path:[String] = [])
1717
{
1818
self.namespace = namespace
1919
self.imports = imports

Sources/CodelinkResolution/CodelinkResolver.swift

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,22 @@ extension CodelinkResolver
2727
switch link.base
2828
{
2929
case .relative:
30-
for index:Int in
31-
(self.scope.path.startIndex ... self.scope.path.endIndex).reversed()
30+
if let namespace:Symbol.Module = self.scope.namespace
3231
{
33-
let overloads:Overloads = self.table.query(
34-
qualified: ["\(self.scope.namespace)"]
35-
+ self.scope.path[..<index]
36-
+ link.path.components,
37-
suffix: link.suffix)
38-
39-
guard overloads.isEmpty
40-
else
32+
for index:Int in
33+
(self.scope.path.startIndex ... self.scope.path.endIndex).reversed()
4134
{
42-
return overloads
35+
let overloads:Overloads = self.table.query(
36+
qualified: ["\(namespace)"]
37+
+ self.scope.path[..<index]
38+
+ link.path.components,
39+
suffix: link.suffix)
40+
41+
guard overloads.isEmpty
42+
else
43+
{
44+
return overloads
45+
}
4346
}
4447
}
4548
for namespace:Symbol.Module in self.scope.imports where

Sources/DoclinkResolution/DoclinkResolver.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ struct DoclinkResolver
66
public
77
let table:Table
88
public
9-
let scope:Scope
9+
let scope:Scope?
1010

1111
@inlinable public
12-
init(table:Table, scope:Scope)
12+
init(table:Table, scope:Scope?)
1313
{
1414
self.table = table
1515
self.scope = scope
@@ -20,11 +20,12 @@ extension DoclinkResolver
2020
public
2121
func resolve(_ link:Doclink) -> Int32?
2222
{
23-
if !link.absolute
23+
if !link.absolute,
24+
let scope:Scope = self.scope
2425
{
25-
for index:Int in self.scope.indices.reversed()
26+
for index:Int in scope.indices.reversed()
2627
{
27-
let path:DoclinkResolutionPath = .join(self.scope[...index] + link.path)
28+
let path:DoclinkResolutionPath = .join(scope[...index] + link.path)
2829
if let address:Int32 = self.table.entries[path]
2930
{
3031
return address

Sources/MarkdownABI/Encoding/MarkdownAttributeEncoder.swift renamed to Sources/MarkdownABI/Bytecode/Markdown.AttributeEncoder.swift

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1-
@frozen public
2-
struct MarkdownAttributeEncoder
1+
extension Markdown
32
{
4-
@usableFromInline internal
5-
var bytecode:MarkdownBytecode
6-
7-
@inlinable internal
8-
init(bytecode:MarkdownBytecode)
3+
@frozen public
4+
struct AttributeEncoder
95
{
10-
self.bytecode = bytecode
6+
@usableFromInline internal
7+
var bytecode:Bytecode
8+
9+
@inlinable internal
10+
init(bytecode:Bytecode)
11+
{
12+
self.bytecode = bytecode
13+
}
1114
}
1215
}
13-
extension MarkdownAttributeEncoder
16+
extension Markdown.AttributeEncoder
1417
{
1518
/// Serializes an empty attribute, if the assigned boolean is true.
1619
/// Does nothing if it is false. The getter always returns false.
1720
@inlinable public
18-
subscript(attribute:MarkdownBytecode.Attribute) -> Bool
21+
subscript(attribute:Markdown.Bytecode.Attribute) -> Bool
1922
{
2023
get
2124
{
@@ -27,7 +30,7 @@ extension MarkdownAttributeEncoder
2730
}
2831
}
2932
@inlinable public
30-
subscript(attribute:MarkdownBytecode.Attribute) -> String?
33+
subscript(attribute:Markdown.Bytecode.Attribute) -> String?
3134
{
3235
get
3336
{
@@ -43,7 +46,7 @@ extension MarkdownAttributeEncoder
4346
}
4447
}
4548
@inlinable public
46-
subscript(attribute:MarkdownBytecode.Attribute) -> Int?
49+
subscript(attribute:Markdown.Bytecode.Attribute) -> Int?
4750
{
4851
get
4952
{

Sources/MarkdownABI/Instructions/MarkdownBinaryDecoder.swift renamed to Sources/MarkdownABI/Bytecode/Markdown.BinaryDecoder.swift

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
@frozen public
2-
struct MarkdownBinaryDecoder
1+
extension Markdown
32
{
4-
@usableFromInline
5-
let bytes:[UInt8]
6-
@usableFromInline
7-
var index:Int
8-
9-
@inlinable internal
10-
init(bytes:[UInt8])
3+
@frozen public
4+
struct BinaryDecoder
115
{
12-
self.bytes = bytes
13-
self.index = bytes.startIndex
6+
@usableFromInline
7+
let bytes:[UInt8]
8+
@usableFromInline
9+
var index:Int
10+
11+
@inlinable internal
12+
init(bytes:[UInt8])
13+
{
14+
self.bytes = bytes
15+
self.index = bytes.startIndex
16+
}
1417
}
1518
}
16-
extension MarkdownBinaryDecoder
19+
extension Markdown.BinaryDecoder
1720
{
1821
@inlinable internal mutating
1922
func read() -> UInt8?
@@ -68,10 +71,10 @@ extension MarkdownBinaryDecoder
6871
self.read().flatMap(Instruction.init(rawValue:))
6972
}
7073
}
71-
extension MarkdownBinaryDecoder:IteratorProtocol
74+
extension Markdown.BinaryDecoder:IteratorProtocol
7275
{
7376
@inlinable public mutating
74-
func next() -> MarkdownInstruction?
77+
func next() -> Markdown.Instruction?
7578
{
7679
guard let byte:UInt8 = self.read()
7780
else
@@ -87,10 +90,10 @@ extension MarkdownBinaryDecoder:IteratorProtocol
8790
break
8891
}
8992

90-
switch MarkdownBytecode.Marker.init(rawValue: byte)
93+
switch Markdown.Bytecode.Marker.init(rawValue: byte)
9194
{
9295
case .push?:
93-
if let instruction:MarkdownBytecode.Context = self.read()
96+
if let instruction:Markdown.Bytecode.Context = self.read()
9497
{
9598
return .push(instruction)
9699
}
@@ -99,41 +102,41 @@ extension MarkdownBinaryDecoder:IteratorProtocol
99102
return .pop
100103

101104
case .attribute?:
102-
if let attribute:MarkdownBytecode.Attribute = self.read()
105+
if let attribute:Markdown.Bytecode.Attribute = self.read()
103106
{
104107
return .attribute(attribute)
105108
}
106109

107110
case .attribute8?:
108-
if let attribute:MarkdownBytecode.Attribute = self.read(),
111+
if let attribute:Markdown.Bytecode.Attribute = self.read(),
109112
let reference:Int = self.read(UInt8.self)
110113
{
111114
return .attribute(attribute, reference)
112115
}
113116

114117
case .attribute16?:
115-
if let attribute:MarkdownBytecode.Attribute = self.read(),
118+
if let attribute:Markdown.Bytecode.Attribute = self.read(),
116119
let reference:Int = self.read(UInt16.self)
117120
{
118121
return .attribute(attribute, reference)
119122
}
120123

121124
case .attribute32?:
122-
if let attribute:MarkdownBytecode.Attribute = self.read(),
125+
if let attribute:Markdown.Bytecode.Attribute = self.read(),
123126
let reference:Int = self.read(UInt32.self)
124127
{
125128
return .attribute(attribute, reference)
126129
}
127130

128131
case .attribute64?:
129-
if let attribute:MarkdownBytecode.Attribute = self.read(),
132+
if let attribute:Markdown.Bytecode.Attribute = self.read(),
130133
let reference:Int = self.read(UInt64.self)
131134
{
132135
return .attribute(attribute, reference)
133136
}
134137

135138
case .emit?:
136-
if let instruction:MarkdownBytecode.Emission = self.read()
139+
if let instruction:Markdown.Bytecode.Emission = self.read()
137140
{
138141
return .emit(instruction)
139142
}

0 commit comments

Comments
 (0)