Skip to content

Conversation

owenv
Copy link
Collaborator

@owenv owenv commented Sep 8, 2025

SWBBuildServer implements BSP message handling and is intended to back a higher level BSP which manages the project model and generates PIF and a build request (SwiftPM).

As part of this change, many of the core BSP types are vendored into the new SWBBuildServerProtocol target from SourceKitLSP with minor modifications. The only significant changes to that code are:

  • Replacing some use of atomics with SWBMutex to cut dependencies on C atomics shims since the deployment target is not yet high enough to adopt the atomics in Synchronization
  • Removing use of the sourcekit-lsp logging mechanism

The new code in this PR is largely in SWBBuildServer and SWBBuildServerTests

@owenv
Copy link
Collaborator Author

owenv commented Sep 8, 2025

@swift-ci test

@owenv
Copy link
Collaborator Author

owenv commented Sep 8, 2025

@swift-ci test

@owenv
Copy link
Collaborator Author

owenv commented Sep 8, 2025

@swift-ci test

@owenv
Copy link
Collaborator Author

owenv commented Sep 8, 2025

@swift-ci test

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some drive-by comments.

}
state = .running
case is OnWatchedFilesDidChangeNotification:
guard state == .running else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think there’s any harm in handling file change notifications while the server is initializing, right? I would log an error if we are in the wrong state but still continue handling it, just makes the BSP server more resilient for badly behaving clients.

if !(request.params is InitializeBuildRequest) {
let state = self.state
guard state == .running else {
await request.reply { throw ResponseError.unknown("Request received while the build server is \(state.description)") }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly here, if we are in the waitingForInitializationNotification state, we should be able to handle those requests, I would personally try and make the BSP server handle requests even if they don’t quite come in the right order.

baseDirectory: nil,
tags: tags,
capabilities: BuildTargetCapabilities(),
languageIds: [.c, .cpp, .objective_c, .objective_cpp, .swift],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there was an easy way to tell which languages are present in the target, it would be nice to only report those but if not, it’s fine. SourceKit-LSP doesn’t end up caring about this. I’d just add a comment explaining why we return all languages here.

Related, worth reporting Metal as well?

import Foundation

/// Wraps a `SWBBuildServiceSession` to expose Build Server Protocol functionality.
public actor SWBBuildServer: QueueBasedMessageHandler {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a nested type that conforms to QueueBasedMessageHandler instead? I don't think clients should be calling didReceive, handle, etc., on this.

Probably also allows SWBBuildServerProtocol to become an internal import?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At a minimum we need to expose a type with a MessageHandler conformance so we can hand it off to a connection object like we do in the tests

@owenv
Copy link
Collaborator Author

owenv commented Sep 9, 2025

@ahoppen did a first pass through your feedback, thanks. I'm waiting to address the rest until I've had more time to think about the logging strategy

@ahoppen
Copy link
Member

ahoppen commented Sep 9, 2025

did a first pass through your feedback, thanks. I'm waiting to address the rest until I've had more time to think about the logging strategy

Thanks. There was nothing blocking in my comments. Mostly just thoughts on how things could be improved.

SWBBuildServer implements BSP message handling and is intended to back a higher level BSP which manages the project model and generates PIF and a build request (SwiftPM).

As part of this change, many of the core BSP types are vendored into the new SWBBuildServerProtocol target from SourceKitLSP with minor modifications.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants