Skip to content

Commit a79973b

Browse files
committed
Hide on-type-formatting behind an experimental feature flag
1 parent fd22b32 commit a79973b

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

Documentation/Configuration File.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@ The structure of the file is currently not guaranteed to be stable. Options may
5151
- `noLazy`: Prepare a target without generating object files but do not do lazy type checking and function body skipping
5252
- `enabled`: Prepare a target without generating object files and the like
5353
- `cancelTextDocumentRequestsOnEditAndClose: bool`: Whether sending a `textDocument/didChange` or `textDocument/didClose` notification for a document should cancel all pending requests for that document.
54-
- `experimentalFeatures: string[]`: Experimental features to enable
54+
- `experimentalFeatures: string[]`: Experimental features to enable. Available options: on-type-formatting
5555
- `swiftPublishDiagnosticsDebounceDuration: double`: The time that `SwiftLanguageService` should wait after an edit before starting to compute diagnostics and sending a `PublishDiagnosticsNotification`.

Sources/SKOptions/ExperimentalFeatures.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
/// An experimental feature that can be enabled by passing `--experimental-feature` to `sourcekit-lsp` on the command
14-
/// line. The raw value of this feature is how it is named on the command line.
13+
/// An experimental feature that can be enabled by passing `--experimental-feature`
14+
/// to `sourcekit-lsp` on the command line or through the configuration file.
15+
/// The raw value of this feature is how it is named on the command line.
1516
public enum ExperimentalFeature: String, Codable, Sendable, CaseIterable {
16-
/* This is here to silence the errors when the enum doesn't have any cases */
17-
case exampleCase = "example-case"
17+
case onTypeFormatting = "on-type-formatting"
1818
}

Sources/SourceKitLSP/SourceKitLSPServer.swift

+10-5
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,8 @@ extension SourceKitLSPServer {
975975
let result = InitializeResult(
976976
capabilities: await self.serverCapabilities(
977977
for: req.capabilities,
978-
registry: self.capabilityRegistry!
978+
registry: self.capabilityRegistry!,
979+
options: options
979980
)
980981
)
981982
logger.logFullObjectInMultipleLogMessages(header: "Initialize response", AnyRequestType(request: req))
@@ -984,7 +985,8 @@ extension SourceKitLSPServer {
984985

985986
func serverCapabilities(
986987
for client: ClientCapabilities,
987-
registry: CapabilityRegistry
988+
registry: CapabilityRegistry,
989+
options: SourceKitLSPOptions
988990
) async -> ServerCapabilities {
989991
let completionOptions =
990992
await registry.clientHasDynamicCompletionRegistration
@@ -994,6 +996,11 @@ extension SourceKitLSPServer {
994996
triggerCharacters: [".", "("]
995997
)
996998

999+
let onTypeFormattingOptions =
1000+
options.hasExperimentalFeature(.onTypeFormatting)
1001+
? DocumentOnTypeFormattingOptions(triggerCharacters: ["\n", "\r\n", "\r", "{", "}", ";", ".", ":", "#"])
1002+
: nil
1003+
9971004
let foldingRangeOptions =
9981005
await registry.clientHasDynamicFoldingRangeRegistration
9991006
? nil
@@ -1043,9 +1050,7 @@ extension SourceKitLSPServer {
10431050
codeLensProvider: CodeLensOptions(),
10441051
documentFormattingProvider: .value(DocumentFormattingOptions(workDoneProgress: false)),
10451052
documentRangeFormattingProvider: .value(DocumentRangeFormattingOptions(workDoneProgress: false)),
1046-
documentOnTypeFormattingProvider: DocumentOnTypeFormattingOptions(triggerCharacters: [
1047-
"\n", "\r\n", "\r", "{", "}", ";", ".", ":", "#",
1048-
]),
1053+
documentOnTypeFormattingProvider: onTypeFormattingOptions,
10491054
renameProvider: .value(RenameOptions(prepareProvider: true)),
10501055
colorProvider: .bool(true),
10511056
foldingRangeProvider: foldingRangeOptions,

0 commit comments

Comments
 (0)