Skip to content

Launch Swift extension if workspace has buildServer.json or compile_flags.txt #1087

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
ahoppen opened this issue Sep 20, 2024 · 7 comments
Closed
Labels
sourcekit-lsp SourceKit-LSP issue

Comments

@ahoppen
Copy link
Member

ahoppen commented Sep 20, 2024

The VS Code extension currently check for the presence of Package.swift or compile_commands.json in isValidWorkspaceFolder. SourcKit-LSP can also handle compile_flags.txt (https://clang.llvm.org/docs/JSONCompilationDatabase.html#alternatives) or files that specify a build server by having buildServer.json in their project root. Such projects should also be considered valid workspaces, I think.

@aelam
Copy link
Contributor

aelam commented Nov 22, 2024

@ahoppen
if bsp is enabled i.e. buildServer.json
should some bsp request be sent from the client?

@ahoppen
Copy link
Member Author

ahoppen commented Dec 3, 2024

If buildServer.json exists in the workspace root, SourceKit-LSP will launch the BSP server and send the initialize request to it. I don’t know what you mean by client here. The editor should not send any request to the BSP server.

@aelam
Copy link
Contributor

aelam commented Dec 3, 2024

@ahoppen
Thanks for replying.

I checked the xcode-build-server, only build/initialize and build/initialized are sent.
I'm wondering how workspace/buildTargets is sent. is it sent from client. (i.e. vscode-swift if it supports bsp)

plemarquand added a commit to plemarquand/vscode-swift that referenced this issue Dec 3, 2024
SourceKit-LSP can handle projects configured with the paired down clang
`compile_flags.txt` configuration file, as well as projects configured
with the Build Server Protocol's `buildServer.json`.

Activate the extension if the folder added to the workspace contains
either of these files in the root.

Issue: swiftlang#1087
plemarquand added a commit to plemarquand/vscode-swift that referenced this issue Dec 3, 2024
SourceKit-LSP can handle projects configured with the paired down clang
`compile_flags.txt` configuration file, as well as projects configured
with the Build Server Protocol's `buildServer.json`.

Activate the extension if the folder added to the workspace contains
either of these files in the root.

Issue: swiftlang#1087
@award999 award999 moved this from Backlog to In Progress in Swift Extension for Visual Studio Code Dec 3, 2024
@ahoppen
Copy link
Member Author

ahoppen commented Dec 3, 2024

This is because we changed the BSP integration between 6.0 and 6.1 (https://forums.swift.org/t/extending-functionality-of-build-server-protocol-with-sourcekit-lsp/74400 has the details). xcode-build-server is still using the old integration that uses textDocument/registerForChanges and build/sourceKitOptionsChanged instead of workspace/buildTargets, to the best of my knowledge. If the BSP server returns data.sourceKitOptionsProvider: true in the initialize request, we switch to the “new” integration using workspace/buildTargets. https://github.com/swiftlang/sourcekit-lsp/blob/main/Contributor%20Documentation/Implementing%20a%20BSP%20server.md has the details on how to implement a BSP server for SourceKit-LSP.

@aelam
Copy link
Contributor

aelam commented Dec 3, 2024

Thank you for your detailed explanation!

Initially, I assumed the client would send a workspace/buildTargets request.

If the BSP server returns data.sourceKitOptionsProvider: true in the initialize request, we switch to the “new” integration using workspace/buildTargets.

I am aware of the newer APIs, such as workspace/buildTargets. Following the guidance from the SourceKit-LSP documentation and reviewing the sourcekit-lsp codebase, I added data.sourceKitOptionsProvider: true here:
BuildInitializeRequest.swift#L92C25-L92C49.

However, I haven't observed any changes.
It seems the workspace/buildTargets request will never be triggered.

Currently, all I receive are these three messages:

  • build/initialize
  • build/initialized
  • textDocument/registerForChanges (open/close file)

Would you know more details about how this works or if additional configuration is required?

@ahoppen
Copy link
Member Author

ahoppen commented Dec 4, 2024

Are you using SourceKit-LSP from Swift 6.1? SourceKit-LSP from a 6.0 toolchain only has the “old” BSP integration.

Also, since this discussion is not really related to the original issue, let’s move it to the Swift Forums. Can you open a topic in the SourceKit-LSP category?

@award999 award999 moved this from In Progress to Needs Verification in Swift Extension for Visual Studio Code Dec 6, 2024
@award999 award999 moved this from Needs Verification to In Progress in Swift Extension for Visual Studio Code Dec 6, 2024
award999 pushed a commit that referenced this issue Dec 6, 2024
…ent (#1240)

SourceKit-LSP can handle projects configured with the paired down clang
`compile_flags.txt` configuration file, as well as projects configured
with the Build Server Protocol's `buildServer.json`.

Activate the extension if the folder added to the workspace contains
either of these files in the root.

Issue: #1087
@award999 award999 added the needs verification Issue has been fixed, but requires verification before closing label Dec 6, 2024
@award999 award999 moved this from In Progress to Needs Verification in Swift Extension for Visual Studio Code Dec 6, 2024
@award999 award999 removed the needs verification Issue has been fixed, but requires verification before closing label Dec 6, 2024
@award999
Copy link
Contributor

award999 commented Dec 6, 2024

Verified with c047d4e

@award999 award999 closed this as completed Dec 6, 2024
@award999 award999 moved this from Needs Verification to Done in Swift Extension for Visual Studio Code Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sourcekit-lsp SourceKit-LSP issue
Projects
Development

No branches or pull requests

4 participants