Skip to content

Commit d0eb2f7

Browse files
committed
[Macros] Add a plugin message to clear cached syntax
1 parent 65cf28b commit d0eb2f7

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Sources/SwiftCompilerPluginMessageHandling/CompilerPluginMessageHandler.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ public class CompilerPluginMessageHandler<Provider: PluginProvider> {
195195
)
196196
}
197197
return .loadPluginLibraryResult(loaded: diags.isEmpty, diagnostics: diags)
198+
199+
case .clearCache:
200+
syntaxRegistry.clear()
201+
return .clearCacheResult
198202
}
199203
}
200204
}

Sources/SwiftCompilerPluginMessageHandling/PluginMessages.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
// NOTE: Types in this file should be self-contained and should not depend on any non-stdlib types.
1414

15+
private var _MESSAGE_PROTOCOL_VERSION_NUMBER: Int { 8 } // Added 'clearCache'.
16+
1517
@_spi(PluginMessage)
1618
public enum HostToPluginMessage: Codable {
1719
/// Send capability of the host, and get capability of the plugin.
@@ -48,6 +50,9 @@ public enum HostToPluginMessage: Codable {
4850
libraryPath: String,
4951
moduleName: String
5052
)
53+
54+
/// Signal to clear any caches.
55+
case clearCache
5156
}
5257

5358
@_spi(PluginMessage)
@@ -78,11 +83,13 @@ public enum PluginToHostMessage: Codable {
7883
loaded: Bool,
7984
diagnostics: [PluginMessage.Diagnostic]
8085
)
86+
87+
case clearCacheResult
8188
}
8289

8390
@_spi(PluginMessage)
8491
public enum PluginMessage {
85-
public static var PROTOCOL_VERSION_NUMBER: Int { 7 } // Pass extension protocol list
92+
public static var PROTOCOL_VERSION_NUMBER: Int { _MESSAGE_PROTOCOL_VERSION_NUMBER }
8693

8794
public struct HostCapability: Codable {
8895
var protocolVersion: Int

0 commit comments

Comments
 (0)