@@ -861,4 +861,68 @@ final class WorkspaceTests: XCTestCase {
861861 }
862862 XCTAssertEqual ( diagnostics. items. map ( \. message) , [ " Cannot convert value of type 'Int' to specified type 'String' " ] )
863863 }
864+
865+ func testOptionsInInitializeRequest( ) async throws {
866+ let project = try await SwiftPMTestProject (
867+ files: [
868+ " Test.swift " : """
869+ func test() {
870+ #if TEST
871+ let x: String = 1
872+ #endif
873+ }
874+ """
875+ ] ,
876+ initializationOptions: SourceKitLSPOptions (
877+ swiftPM: SourceKitLSPOptions . SwiftPMOptions ( swiftCompilerFlags: [ " -D " , " TEST " ] )
878+ ) . asLSPAny
879+ )
880+
881+ let ( uri, _) = try project. openDocument ( " Test.swift " )
882+ let diagnostics = try await project. testClient. send (
883+ DocumentDiagnosticsRequest ( textDocument: TextDocumentIdentifier ( uri) )
884+ )
885+ guard case . full( let diagnostics) = diagnostics else {
886+ XCTFail ( " Expected full diagnostics " )
887+ return
888+ }
889+ XCTAssertEqual ( diagnostics. items. map ( \. message) , [ " Cannot convert value of type 'Int' to specified type 'String' " ] )
890+ }
891+
892+ func testWorkspaceOptionsOverrideGlobalOptions( ) async throws {
893+ let project = try await SwiftPMTestProject (
894+ files: [
895+ " /.sourcekit-lsp/config.json " : """
896+ {
897+ " swiftPM " : {
898+ " swiftCompilerFlags " : [ " -D " , " TEST " ]
899+ }
900+ }
901+ """ ,
902+ " Test.swift " : """
903+ func test() {
904+ #if TEST
905+ let x: String = 1
906+ #endif
907+ #if OTHER
908+ let x: String = 1.0
909+ #endif
910+ }
911+ """ ,
912+ ] ,
913+ initializationOptions: SourceKitLSPOptions (
914+ swiftPM: SourceKitLSPOptions . SwiftPMOptions ( swiftCompilerFlags: [ " -D " , " OTHER " ] )
915+ ) . asLSPAny
916+ )
917+
918+ let ( uri, _) = try project. openDocument ( " Test.swift " )
919+ let diagnostics = try await project. testClient. send (
920+ DocumentDiagnosticsRequest ( textDocument: TextDocumentIdentifier ( uri) )
921+ )
922+ guard case . full( let diagnostics) = diagnostics else {
923+ XCTFail ( " Expected full diagnostics " )
924+ return
925+ }
926+ XCTAssertEqual ( diagnostics. items. map ( \. message) , [ " Cannot convert value of type 'Int' to specified type 'String' " ] )
927+ }
864928}
0 commit comments