Skip to content

Dummy PR to review BSP migration changes #1679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 79 commits into from

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Sep 16, 2024

I merged a bunch of changes to the interaction of SourceKit-LSP with the build systems over the last week without code review and would like to use this PR to consolidate feedback

This PR shows all changes made to main between 765c2c0 and 6e99e34.

The way I would suggest to review these changes would be to review the BuildServerProtocol and BuildSystemIntegration modules in their current state on main because they have changed too much for it to make sense to look at diffs. Afterwards, use this PR to review all changes to files that are not in the BuildServerProtocol or BuildSystemIntegration module, which should be mostly (but not exclusively) mechanical. I would suggest reading the files in the following logical ordering.

  • BuildServerProtocol
    • The BuildServerProtocol folder
    • Contributor Documentation/BSP Extensions.md
  • Misc
    • BuildTargetIdentifierExtensions.swift
    • FileBuildSettings.swift
    • Language+InferredFromFileExtension.swift
    • MainFilesProvider.swift (didn’t change, so no real review necessary)
    • PathPrefixMapping.swift (didn’t change, so no real review necessary)
    • BuildSystemTestHooks.swift
  • Fallback build settings
    • FallbackBuildSettings.swift
  • BuildSystemManager
    • BuildSystemManagerDelegate.swift
    • BuildSystemMessageDependencyTracker.swift
    • BuildSettingsLogger.swift (didn’t change, so no real review necessary)
    • BuildSystemManager.swift
  • Build System Adapter
    • BuiltInBuildSystemAdapter.swift
    • BuiltInBuildSystem.swift
    • QueueBasedMessageHandler.swift
  • Compile Commands build system
    • CompilationDatabase.swift
    • SplitShellCommand.swift (didn’t change, so no real review necessary)
    • CompilationDatabaseBuildSystem.swift
  • BuildServerBuildSystem
    • BuildServerBuildSystem.swift
  • SwiftPM build system
    • PrefixMessageWithTaskEmoji.swift
    • SwiftPMBuildSystem.swift
  • Test Build System
    • TestBuildSystem.swift
  • Use this PR to review changes to all files that are not in the BuildServerProtocol or BuildSystemIntegration modules

…n `BuildSystem` to a type that implements BSP
…orkspace creation

This allows us to create the build system from a `BuiltInBuildSystemAdapter` when it receives an `InitializeRequest`, which will be done in a follow-up commit.
This way we create the `BuiltInBuildSystem` at the same time that we create the `BuildSystemManager`, which gets us one step closer to creating the `BuiltInBuildSystem` from the `BuiltInBuildSystemAdapter`.
This moves the creation another step closer to creating the `BuiltInBuildSystem` inside `BuiltInBuildSystemAdapter`.
This finalizes the move of `BuiltInBuildSystem` creation into `BuiltInBuildSystemAdapter` and means that we can set the message handler of the `BuiltInBuildSystem` during initialization instead of using a setter method.
Start migration of the communication between SourceKit-LSP and build systems to happen via the Build Server Protocol (BSP)
Create `BuiltInBuildSystem` in `BuildSystemAdapter`
…dSystemAdapterDelegate`

This was causing memory leaks.
Fix retain cycle between `BuiltInBuildSystemAdapter` and `BuiltInBuildSystemAdapterDelegate`
…s to LSP requests"

This reverts commit b2c17c7.

The workaround isn’t needed anymore because we have a proper fix in the VS Code extension: swiftlang/vscode-swift#1026
`Workspace` is responsible for creating the `BuildSystemManager` and responds to most of the delegate calls. It should thus also be the delegate of `BuildSystemManager`.
Use BSP requests to get build settings of a source file
Make `Workspace` the delegate of a `BuildSystemManager`
Allow overriding the timeout duration for tests
This was only really used for the legacy BSP integration, which we are phasing out in favor of the new `SourceKitOptions` request.
Migrate `fileHandlingCapability` and `prepare` to BSP and remove `registerForChangeNotifications`
Revert "Add an extra percent encoding layer when encoding DocumentURIs to LSP requests"
Migrate getting the list of all source files to BSP
…the build system

The implementation of which file’s dependencies have been updated is common across all build systems and thus build systems shouldn’t need to implement this logic. This also allows us to remove `BuildSystemDelegate`.
…ns between the build system and `BuildSystemManager`
`buildTarget/inverseSources` is not required to be implemented by BSP servers and we have almost all information needed for it in `BuildSystemManager`.

This also makes sure that `buildTarget/sources` and `buildTarget/inverseSources` actually match each other. Before this change, we had source files like `Package.swift` for which we returned a target from `buildTarget/inverseSources` but that weren’t part of that target’s sources retrieved using `buildTarget/sources`.
This was equivalent to `buildTargetsDidChange`
Clean-up of the build system integration
Copy link
Contributor

@hamishknight hamishknight left a comment

Choose a reason for hiding this comment

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

LGTM, just some minor nits

Comment on lines +932 to +935
let workspace = try await self.createWorkspace(
workspaceFolder: workspaceFolder.uri,
buildSystemKind: determineBuildSystem(forWorkspaceFolder: workspaceFolder.uri, options: self.options)
)
Copy link
Contributor

Choose a reason for hiding this comment

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

This pattern is repeated a few times, would it be worth factoring out a createWorkspace overload that looks like the old one where it just takes the workspace path?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. Created a function for it.

@ahoppen
Copy link
Member Author

ahoppen commented Nov 13, 2024

Addressing the review comments here: #1817

@ahoppen ahoppen closed this Nov 13, 2024
@ahoppen ahoppen deleted the ahoppen/bsp-migration-head branch November 13, 2024 18:33
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.

2 participants