Skip to content

Symbol completion for Package.swift from SwiftPM project in a subfolder doesn't work #1210

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
adam-fowler opened this issue May 1, 2024 · 4 comments · Fixed by #1232
Closed

Comments

@adam-fowler
Copy link
Contributor

adam-fowler commented May 1, 2024

If you have a SwiftPM project in a subfolder of a VSCode workspace, SourceKit-LSP does not provide symbol completion, hover documentation for the Package.swift file even though a workspace/didChangeWorkspaceFolders request that adds the subfolder has been sent.

See swiftlang/vscode-swift#768

@ahoppen
Copy link
Member

ahoppen commented May 1, 2024

Synced to Apple’s issue tracker as rdar://127351614

@svanimpe
Copy link

svanimpe commented May 4, 2024

I'm not sure if this is related, but in one of my projects, I keep getting a "No such module" error from SourceKit in a regular file, not Package.Swift. One of the Code Helper processes also spins up to 100% CPU.

This is using a 6.0 snapshot. With 5.9, everything is fine.

@ahoppen
Copy link
Member

ahoppen commented May 4, 2024

I'm not sure if this is related, but in one of my projects, I keep getting a "No such module" error from SourceKit in a regular file, not Package.Swift. One of the Code Helper processes also spins up to 100% CPU.

This is using a 6.0 snapshot. With 5.9, everything is fine.

Could you file a separate issue for this? It seems like a different issue to me. Some initial thoughts:

Did you build your project with the Swift 6.0 snapshot as well? If you build your project using a different toolchain than the one that contains your sourcekit-lsp, SourceKit isn’t able to read your Swift modules, which might cause the issue.

@svanimpe
Copy link

svanimpe commented May 4, 2024

@ahoppen I've opened #1223

ahoppen added a commit to ahoppen/sourcekit-lsp that referenced this issue May 7, 2024
…ildSystem` has build settings for

Previously, `SwiftPMBuildSystem` would report `.unhandled` as the file handling capability for `Package.swift`. In single workspace-folder setups, this was not an issue because we would always default to using the build system of the first/only workspace folder, which was the only `SwiftPMBuildSystem` and then returned compiler arguments despite saying that it couldn’t handle `Package.swift`.

This, however, breaks if you have a setup with multi workspace folders, where we can’t rely on the first workspace folder being able to provide build settings for the package manifest.

To fix this, report `.handled` file handling capability for all files that `SwiftPMBuildSystem` can compute build settings for.

Fixes swiftlang#1210
rdar://127351614
plemarquand added a commit to plemarquand/sourcekit-lsp that referenced this issue Jul 2, 2024
In a project with multiple folders each containing a Package.swift, the
`bestWorkspace` found in `workspaceForDocument(uri:)` was always the
first one encountered.

`fileHandlingCapability(for:)` checks if there are configured targets
for the Package.swift and if there are, the workspace is chosen since
the Package.swift is determined to be part of the workspace. However the
check in `configuredTargets(for:)` always returned a target for any
`Package.swift`, even if that `Package.swift` was not part of the
workspace associated with the BuildSystem.

Ultimately this manifested as code completion not working in all but one
of the Package.swift files in a multi workspace project.

Some work was done in swiftlang#1210 to address swiftlang/vscode-swift#768, which
is where this issue originated from. However while verifying
swiftlang/vscode-swift#768 I found that swiftlang#1210 didn't fully address code
completion of `Package.swift` files in multi workspace projects.
plemarquand added a commit to plemarquand/sourcekit-lsp that referenced this issue Jul 2, 2024
In a project with multiple folders each containing a Package.swift, the
`bestWorkspace` found in `workspaceForDocument(uri:)` was always the
first one encountered.

`fileHandlingCapability(for:)` checks if there are configured targets
for the Package.swift and if there are, the workspace is chosen since
the Package.swift is determined to be part of the workspace. However the
check in `configuredTargets(for:)` always returned a target for any
`Package.swift`, even if that `Package.swift` was not part of the
workspace associated with the BuildSystem.

Ultimately this manifested as code completion not working in all but one
of the Package.swift files in a multi workspace project.

Some work was done in swiftlang#1210 to address swiftlang/vscode-swift#768, which
is where this issue originated from. However while verifying
swiftlang/vscode-swift#768 I found that swiftlang#1210 didn't fully address code
completion of `Package.swift` files in multi workspace projects.
plemarquand added a commit to plemarquand/sourcekit-lsp that referenced this issue Jul 3, 2024
In a project with multiple folders each containing a Package.swift, the
`bestWorkspace` found in `workspaceForDocument(uri:)` was always the
first one encountered.

`fileHandlingCapability(for:)` checks if there are configured targets
for the Package.swift and if there are, the workspace is chosen since
the Package.swift is determined to be part of the workspace. However the
check in `configuredTargets(for:)` always returned a target for any
`Package.swift`, even if that `Package.swift` was not part of the
workspace associated with the BuildSystem.

Ultimately this manifested as code completion not working in all but one
of the Package.swift files in a multi workspace project.

Some work was done in swiftlang#1210 to address swiftlang/vscode-swift#768, which
is where this issue originated from. However while verifying
swiftlang/vscode-swift#768 I found that swiftlang#1210 didn't fully address code
completion of `Package.swift` files in multi workspace projects.
plemarquand added a commit to plemarquand/sourcekit-lsp that referenced this issue Jul 3, 2024
In a project with multiple folders each containing a Package.swift, the
`bestWorkspace` found in `workspaceForDocument(uri:)` was always the
first one encountered.

`fileHandlingCapability(for:)` checks if there are configured targets
for the Package.swift and if there are, the workspace is chosen since
the Package.swift is determined to be part of the workspace. However the
check in `configuredTargets(for:)` always returned a target for any
`Package.swift`, even if that `Package.swift` was not part of the
workspace associated with the BuildSystem.

Ultimately this manifested as code completion not working in all but one
of the Package.swift files in a multi workspace project.

Some work was done in swiftlang#1210 to address swiftlang/vscode-swift#768, which
is where this issue originated from. However while verifying
swiftlang/vscode-swift#768 I found that swiftlang#1210 didn't fully address code
completion of `Package.swift` files in multi workspace projects.
plemarquand added a commit to plemarquand/sourcekit-lsp that referenced this issue Jul 16, 2024
In a project with multiple folders each containing a Package.swift, the
`bestWorkspace` found in `workspaceForDocument(uri:)` was always the
first one encountered.

`fileHandlingCapability(for:)` checks if there are configured targets
for the Package.swift and if there are, the workspace is chosen since
the Package.swift is determined to be part of the workspace. However the
check in `configuredTargets(for:)` always returned a target for any
`Package.swift`, even if that `Package.swift` was not part of the
workspace associated with the BuildSystem.

Ultimately this manifested as code completion not working in all but one
of the Package.swift files in a multi workspace project.

Some work was done in swiftlang#1210 to address swiftlang/vscode-swift#768, which
is where this issue originated from. However while verifying
swiftlang/vscode-swift#768 I found that swiftlang#1210 didn't fully address code
completion of `Package.swift` files in multi workspace projects.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants