@@ -65,7 +65,7 @@ struct SourceKitLSP: AsyncParsableCommand {
6565 name: [ . customLong( " configuration " ) ] ,
6666 help: " Build with configuration [debug|release] "
6767 )
68- var buildConfiguration = BuildConfiguration . debug
68+ var buildConfiguration : BuildConfiguration ?
6969
7070 @Option (
7171 name: [ . long, . customLong( " build-path " ) ] ,
@@ -78,42 +78,42 @@ struct SourceKitLSP: AsyncParsableCommand {
7878 parsing: . unconditionalSingleValue,
7979 help: " Pass flag through to all C compiler invocations "
8080 )
81- var buildFlagsCc = [ String ] ( )
81+ var buildFlagsCc : [ String ] = [ ]
8282
8383 @Option (
8484 name: . customLong( " Xcxx " , withSingleDash: true ) ,
8585 parsing: . unconditionalSingleValue,
8686 help: " Pass flag through to all C++ compiler invocations "
8787 )
88- var buildFlagsCxx = [ String ] ( )
88+ var buildFlagsCxx : [ String ] = [ ]
8989
9090 @Option (
9191 name: . customLong( " Xlinker " , withSingleDash: true ) ,
9292 parsing: . unconditionalSingleValue,
9393 help: " Pass flag through to all linker invocations "
9494 )
95- var buildFlagsLinker = [ String ] ( )
95+ var buildFlagsLinker : [ String ] = [ ]
9696
9797 @Option (
9898 name: . customLong( " Xswiftc " , withSingleDash: true ) ,
9999 parsing: . unconditionalSingleValue,
100100 help: " Pass flag through to all Swift compiler invocations "
101101 )
102- var buildFlagsSwift = [ String ] ( )
102+ var buildFlagsSwift : [ String ] = [ ]
103103
104104 @Option (
105105 name: . customLong( " Xclangd " , withSingleDash: true ) ,
106106 parsing: . unconditionalSingleValue,
107107 help: " Pass options to clangd command-line "
108108 )
109- var clangdOptions = [ String ] ( )
109+ var clangdOptions : [ String ] = [ ]
110110
111111 @Option (
112112 name: . customLong( " index-prefix-map " , withSingleDash: true ) ,
113113 parsing: . unconditionalSingleValue,
114114 help: " Override the prefix map from the build system, values of form 'remote=local' "
115115 )
116- var indexPrefixMappings = [ PathPrefixMapping ] ( )
116+ var indexPrefixMappings : [ PathPrefixMapping ] = [ ]
117117
118118 @Option (
119119 help: " Override default workspace type selection; one of 'swiftPM', 'compilationDatabase', or 'buildServer' "
@@ -126,7 +126,7 @@ struct SourceKitLSP: AsyncParsableCommand {
126126 help:
127127 " Specify a relative path where sourcekit-lsp should search for `compile_commands.json` or `compile_flags.txt` relative to the root of a workspace. Multiple search paths may be specified by repeating this option. "
128128 )
129- var compilationDatabaseSearchPaths = [ String ] ( )
129+ var compilationDatabaseSearchPaths : [ String ] = [ ]
130130
131131 @Option (
132132 help: " Specify the directory where generated files will be stored "
@@ -148,29 +148,29 @@ struct SourceKitLSP: AsyncParsableCommand {
148148 swiftPM: SourceKitLSPOptions . SwiftPMOptions (
149149 configuration: buildConfiguration,
150150 scratchPath: scratchPath,
151- cCompilerFlags: buildFlagsCc,
152- cxxCompilerFlags: buildFlagsCxx,
153- swiftCompilerFlags: buildFlagsSwift,
154- linkerFlags: buildFlagsLinker
151+ cCompilerFlags: buildFlagsCc. nilIfEmpty ,
152+ cxxCompilerFlags: buildFlagsCxx. nilIfEmpty ,
153+ swiftCompilerFlags: buildFlagsSwift. nilIfEmpty ,
154+ linkerFlags: buildFlagsLinker. nilIfEmpty
155155 ) ,
156156 fallbackBuildSystem: SourceKitLSPOptions . FallbackBuildSystemOptions (
157- cCompilerFlags: buildFlagsCc,
158- cxxCompilerFlags: buildFlagsCxx,
159- swiftCompilerFlags: buildFlagsSwift
157+ cCompilerFlags: buildFlagsCc. nilIfEmpty,
158+ cxxCompilerFlags: buildFlagsCxx. nilIfEmpty,
159+ swiftCompilerFlags: buildFlagsSwift. nilIfEmpty
160+ ) ,
161+ compilationDatabase: SourceKitLSPOptions . CompilationDatabaseOptions (
162+ searchPaths: compilationDatabaseSearchPaths. nilIfEmpty
160163 ) ,
161- compilationDatabase: SourceKitLSPOptions . CompilationDatabaseOptions ( searchPaths: compilationDatabaseSearchPaths) ,
162164 clangdOptions: clangdOptions,
163165 index: SourceKitLSPOptions . IndexOptions (
164166 indexPrefixMap: [ String: String] (
165167 indexPrefixMappings. map { ( $0. original, $0. replacement) } ,
166168 uniquingKeysWith: { lhs, rhs in rhs }
167- ) ,
168- maxCoresPercentageToUseForBackgroundIndexing: nil ,
169- updateIndexStoreTimeout: nil
169+ ) . nilIfEmpty
170170 ) ,
171171 defaultWorkspaceType: defaultWorkspaceType,
172172 generatedFilesPath: generatedFilesPath,
173- experimentalFeatures: Set ( experimentalFeatures. compactMap ( ExperimentalFeature . init) )
173+ experimentalFeatures: Set ( experimentalFeatures. compactMap ( ExperimentalFeature . init) ) . nilIfEmpty
174174 )
175175 }
176176
@@ -315,3 +315,12 @@ struct SourceKitLSP: AsyncParsableCommand {
315315 }
316316 }
317317}
318+
319+ private extension Collection {
320+ var nilIfEmpty : Self ? {
321+ if self . isEmpty {
322+ return nil
323+ }
324+ return self
325+ }
326+ }
0 commit comments