10
10
//
11
11
//===----------------------------------------------------------------------===//
12
12
13
- // NOTE: This file should be synced between swift and swift-syntax repository.
14
13
// NOTE: Types in this file should be self-contained and should not depend on any non-stdlib types.
15
14
16
- internal enum HostToPluginMessage : Codable {
15
+ @ _spi ( PluginMessage ) public enum HostToPluginMessage : Codable {
17
16
/// Send capability of the host, and get capability of the plugin.
18
17
case getCapability(
19
18
capability: PluginMessage . HostCapability ?
@@ -47,7 +46,7 @@ internal enum HostToPluginMessage: Codable {
47
46
)
48
47
}
49
48
50
- internal enum PluginToHostMessage : Codable {
49
+ @ _spi ( PluginMessage ) public enum PluginToHostMessage : Codable {
51
50
case getCapabilityResult(
52
51
capability: PluginMessage . PluginCapability
53
52
)
@@ -76,30 +75,45 @@ internal enum PluginToHostMessage: Codable {
76
75
)
77
76
}
78
77
79
- /*namespace*/ internal enum PluginMessage {
80
- static var PROTOCOL_VERSION_NUMBER : Int { 6 } // Added 'expandMacroResult'.
78
+ @ _spi ( PluginMessage ) public enum PluginMessage {
79
+ public static var PROTOCOL_VERSION_NUMBER : Int { 6 } // Added 'expandMacroResult'.
81
80
82
- struct HostCapability : Codable {
81
+ public struct HostCapability : Codable {
83
82
var protocolVersion : Int
83
+
84
+ public init ( protocolVersion: Int ) {
85
+ self . protocolVersion = protocolVersion
86
+ }
84
87
}
85
88
86
- struct PluginCapability : Codable {
87
- var protocolVersion : Int
89
+ public struct PluginCapability : Codable {
90
+ public var protocolVersion : Int
88
91
89
92
/// Optional features this plugin provides.
90
93
/// * 'load-plugin-library': 'loadPluginLibrary' message is implemented.
91
- var features : [ String ] ?
94
+ public var features : [ String ] ?
95
+
96
+ public init ( protocolVersion: Int , features: [ String ] ? = nil ) {
97
+ self . protocolVersion = protocolVersion
98
+ self . features = features
99
+ }
92
100
}
93
101
94
- struct MacroReference : Codable {
95
- var moduleName : String
96
- var typeName : String
102
+ public struct MacroReference : Codable {
103
+ public var moduleName : String
104
+ public var typeName : String
97
105
98
106
// The name of 'macro' declaration the client is using.
99
- var name : String
107
+ public var name : String
108
+
109
+ public init ( moduleName: String , typeName: String , name: String ) {
110
+ self . moduleName = moduleName
111
+ self . typeName = typeName
112
+ self . name = name
113
+ }
100
114
}
101
115
102
- enum MacroRole : String , Codable {
116
+ public enum MacroRole : String , Codable {
103
117
case expression
104
118
case declaration
105
119
case accessor
@@ -111,79 +125,128 @@ internal enum PluginToHostMessage: Codable {
111
125
case `extension`
112
126
}
113
127
114
- struct SourceLocation : Codable {
128
+ public struct SourceLocation : Codable {
115
129
/// A file ID consisting of the module name and file name (without full path),
116
130
/// as would be generated by the macro expansion `#fileID`.
117
- var fileID : String
131
+ public var fileID : String
118
132
119
133
/// A full path name as would be generated by the macro expansion `#filePath`,
120
134
/// e.g., `/home/taylor/alison.swift`.
121
- var fileName : String
135
+ public var fileName : String
122
136
123
137
/// UTF-8 offset of the location in the file.
124
- var offset : Int
138
+ public var offset : Int
139
+
140
+ public var line : Int
141
+ public var column : Int
125
142
126
- var line : Int
127
- var column : Int
143
+ public init ( fileID: String , fileName: String , offset: Int , line: Int , column: Int ) {
144
+ self . fileID = fileID
145
+ self . fileName = fileName
146
+ self . offset = offset
147
+ self . line = line
148
+ self . column = column
149
+ }
128
150
}
129
151
130
- struct Diagnostic : Codable {
131
- enum Severity : String , Codable {
152
+ public struct Diagnostic : Codable {
153
+ public enum Severity : String , Codable {
132
154
case error
133
155
case warning
134
156
case note
135
157
}
136
- struct Position : Codable {
137
- var fileName : String
158
+ public struct Position : Codable {
159
+ public var fileName : String
138
160
/// UTF-8 offset in the file.
139
- var offset : Int
161
+ public var offset : Int
140
162
141
- static var invalid : Self {
163
+ public init ( fileName: String , offset: Int ) {
164
+ self . fileName = fileName
165
+ self . offset = offset
166
+ }
167
+
168
+ public static var invalid : Self {
142
169
. init( fileName: " " , offset: 0 )
143
170
}
144
171
}
145
- struct PositionRange : Codable {
146
- var fileName : String
172
+ public struct PositionRange : Codable {
173
+ public var fileName : String
147
174
/// UTF-8 offset of the start of the range in the file.
148
- var startOffset : Int
175
+ public var startOffset : Int
149
176
/// UTF-8 offset of the end of the range in the file.
150
- var endOffset : Int
177
+ public var endOffset : Int
178
+
179
+ public init ( fileName: String , startOffset: Int , endOffset: Int ) {
180
+ self . fileName = fileName
181
+ self . startOffset = startOffset
182
+ self . endOffset = endOffset
183
+ }
151
184
152
- static var invalid : Self {
185
+ public static var invalid : Self {
153
186
. init( fileName: " " , startOffset: 0 , endOffset: 0 )
154
187
}
155
188
}
156
- struct Note : Codable {
157
- var position : Position
158
- var message : String
189
+ public struct Note : Codable {
190
+ public var position : Position
191
+ public var message : String
192
+
193
+ public init ( position: Position , message: String ) {
194
+ self . position = position
195
+ self . message = message
196
+ }
159
197
}
160
- struct FixIt : Codable {
161
- struct Change : Codable {
162
- var range : PositionRange
163
- var newText : String
198
+ public struct FixIt : Codable {
199
+ public struct Change : Codable {
200
+ public var range : PositionRange
201
+ public var newText : String
202
+
203
+ internal init ( range: PositionRange , newText: String ) {
204
+ self . range = range
205
+ self . newText = newText
206
+ }
207
+ }
208
+ public var message : String
209
+ public var changes : [ Change ]
210
+
211
+ internal init ( message: String , changes: [ Change ] ) {
212
+ self . message = message
213
+ self . changes = changes
164
214
}
165
- var message : String
166
- var changes : [ Change ]
167
215
}
168
- var message : String
169
- var severity : Severity
170
- var position : Position
171
- var highlights : [ PositionRange ]
172
- var notes : [ Note ]
173
- var fixIts : [ FixIt ]
216
+ public var message : String
217
+ public var severity : Severity
218
+ public var position : Position
219
+ public var highlights : [ PositionRange ]
220
+ public var notes : [ Note ]
221
+ public var fixIts : [ FixIt ]
222
+
223
+ internal init ( message: String , severity: Severity , position: Position , highlights: [ PositionRange ] , notes: [ Note ] , fixIts: [ FixIt ] ) {
224
+ self . message = message
225
+ self . severity = severity
226
+ self . position = position
227
+ self . highlights = highlights
228
+ self . notes = notes
229
+ self . fixIts = fixIts
230
+ }
174
231
}
175
232
176
- struct Syntax : Codable {
177
- enum Kind : String , Codable {
233
+ public struct Syntax : Codable {
234
+ public enum Kind : String , Codable {
178
235
case declaration
179
236
case statement
180
237
case expression
181
238
case type
182
239
case pattern
183
240
case attribute
184
241
}
185
- var kind : Kind
186
- var source : String
187
- var location : SourceLocation
242
+ public var kind : Kind
243
+ public var source : String
244
+ public var location : SourceLocation
245
+
246
+ public init ( kind: Kind , source: String , location: SourceLocation ) {
247
+ self . kind = kind
248
+ self . source = source
249
+ self . location = location
250
+ }
188
251
}
189
252
}
0 commit comments