Commit Graph

84 Commits

Author SHA1 Message Date
Bassam Khouri d3b39dafa0 Improve build system inferrence
SwiftPM PR #9985 introduce files in the scratch path whose contents
indicate which build system was used to build artifact for a given build
configuration.  if this file exist, use it's contents to infer the build
system. Otherwise, fallback to the existing behaviour.

Fixes: #2576
2026-04-26 17:21:58 -04:00
Rintaro Ishizaki 0a432b94d2 [SwiftPM] Ignore file events in scratch directory
Binary targets backed by remote `.artifactbundleindex` URLs cause
SwiftPM to re-extract the artifact bundle into the scratch directory
on every package load. The resulting file-change events (delete +
create) for the extracted files triggered another reload, causing an
infinite loop.

Add `isInScratchDirectory` to `fileEventShouldTriggerPackageReload`
to filter out events before the build-settings check. It covers
both the configured scratch directory and the default `.build/`
directory (which receives regular `swift build` output even when
a custom scratch path is configured).

Also add tests using local zip-based binary targets to cover both
the default and custom-scratch-path scenarios. Local zips are used
in the tests to avoid a network dependency; they exercise the same
`isInScratchDirectory` code path even though the infinite loop in
practice requires a remote `.artifactbundleindex` target (where
SwiftPM's checksum mismatch causes re-extraction on every load).

https://github.com/swiftlang/sourcekit-lsp/issues/2615
2026-04-22 10:55:45 -07:00
Gabe Braden 61eb1d6aad Added forceResolvedVersions option 2026-04-17 16:57:51 -04:00
Alex Hoppen b4fafb64b3 Fix build warnings
Fix all build warnings except those caused by using old DocC request/response types, which are a little harder to resolve.
2026-04-12 16:11:11 +10:00
Alex Hoppen 93872a0f08 Merge pull request #2574 from ahoppen/implicittargets
Fix build failure caused by `BuildTargetPrepareRequest` changing its return type
2026-04-09 06:55:07 +10:00
Alex Hoppen 08dfe2993c Merge pull request #2593 from ahoppen/simplify-sibling-fallback 2026-04-08 05:55:33 +10:00
Alex Hoppen d5691db255 Fix build failure caused by BuildTargetPrepareRequest changing its return type
API-break caused by swiftlang/swift-tools-protocols#34.
2026-04-07 10:26:45 +10:00
Alex Hoppen afac106704 Pass pluginConfiguration to SourceKitLSPAPI.BuildDescription initializer
To stage in https://github.com/swiftlang/swift-package-manager/pull/9583.
2026-04-07 06:57:40 +10:00
Rintaro Ishizaki 309e3969a3 Fix build failure with SOURCEKIT_LSP_NO_SWIFTPM_DEPENDENCY 2026-04-06 18:34:37 +09:00
Alex Hoppen 8deea936ab Simplify fallbackBuildSettingsInferredFromSiblingFile
Address https://github.com/swiftlang/sourcekit-lsp/pull/2412#discussion_r2942800470
2026-04-04 08:04:01 +07:00
Alex Hoppen 653db45842 Merge pull request #2590 from ahoppen/plugin-args-prep
Start passing `pluginConfiguration` to `BuildDescription` initializer in SwiftPMBuildServer
2026-04-03 13:33:58 +02:00
Kavon Farvardin e45119ea18 Merge pull request #2416 from ahoppen/any-error
Allow `QueueBasedMessageHandler.handle` to return `any Error` instead of `ResponseError`
2026-04-02 08:55:26 -07:00
Alex Hoppen 16176fa854 Start passing pluginConfiguration to BuildDescription initializer in SwiftPMBuildServer
To stage in https://github.com/swiftlang/swift-package-manager/pull/9583 because SwiftPM doesn’t support cross-PR testing.
2026-04-02 13:46:33 +02:00
Owen Voorhees 8b352cce0a Merge pull request #2577 from owenv/reviewfeedback
Address review feedback from https://github.com/swiftlang/sourcekit-lsp/pull/2561
2026-03-31 09:14:25 -07:00
Owen Voorhees bab011f8ba Address review feedback from https://github.com/swiftlang/sourcekit-lsp/pull/2561 2026-03-30 19:44:13 -07:00
Alex Hoppen 9d7e7f3c30 Provide semantic functionality in copy destinations
If we have a source item `include/Test.h` that gets copied to `build/Test.h`, we currently don’t provide any semantic functionality for `build/Test.h`. Improve the build settings fallback logic to construct fallback build settings for `build/Test.h` based on `include/Test.h`.
2026-03-23 17:23:54 +01:00
Alex Hoppen 7afb68a02e Merge pull request #2564 from ahoppen/pass-sdk-swiftpm
Add SourceKit-LSP configuration option to pass `--sdk` to the SwiftPMBuildServer
2026-03-23 17:20:38 +01:00
Alex Hoppen dfde91bdde Merge pull request #2413 from ahoppen/check-if-original-exists
Only adjust location for copied files if the original file exists
2026-03-23 11:52:32 +01:00
Alex Hoppen d803a4b757 Add SourceKit-LSP configuration option to pass --sdk to the SwiftPMBuildServer 2026-03-23 11:34:28 +01:00
Owen Voorhees 12c6a983c3 Merge pull request #2561 from owenv/owenv/buildsysteminference
When background indexing is disabled, attempt to infer the SwiftPM build system
2026-03-20 09:07:36 -07:00
Owen Voorhees 7e853de0ce When background indexing is disabled, attempt to infer the SwiftPM build system 2026-03-18 18:19:25 -07:00
Alex Hoppen 8ee7f9a63b Only adjust location for copied files if the original file exists
If the original file does not exist, it is preferable to jump to a file generated by the build system instead of trying to jump to a file that the editor can’t open. This will become important when using the copied file logic to jump to files in `.build/checkouts` instead of `.build/index-build/checkouts` in a follow-up PR.
2026-03-16 08:27:12 +01:00
Owen Voorhees 8cb9276cc6 Explicitly pass --build-system native when preparing using the builtin SwiftPMBuildServer 2026-03-15 19:19:13 -07:00
Alex Hoppen f21da6b574 Merge pull request #2415 from ahoppen/main-files-provider-nil
Do not log fault if `BuildServermanager.mainFilesProvider` is `nil`
2026-01-16 07:41:59 +01:00
Alex Hoppen a008e516e5 Allow QueueBasedMessageHandler.handle to return any Error instead of ResponseError
Update for the API changed in https://github.com/swiftlang/swift-tools-protocols/pull/33.
2026-01-04 08:44:11 +01:00
Alex Hoppen 66398cc2f9 Do not log fault if BuildServermanager.mainFilesProvider is nil
It’s perfectly fine for `mainFilesProvider` to be `nil` if we don’t have an index. We shouldn’t log a fault for that.
2026-01-04 07:46:45 +01:00
Alex Hoppen 4029dd5449 Use for loops to accumulate SourceItem elements in SwiftPMBuildServer
This seems cleaner than having multiple map calls that then get concatenated.
2026-01-03 19:59:53 +01:00
Alex Hoppen 2aea93dac8 Merge pull request #2385 from loveucifer/feature/file-mapping-all-requests
Extend copied file mapping to all LSP requests returning locations
2026-01-03 19:59:29 +01:00
loveucifer 29b1f4c449 few more fixes 2025-12-19 19:52:17 +05:30
loveucifer 21adc24144 some more fixes 2025-12-17 19:57:52 +05:30
Ben Barham 538e5927c5 Merge pull request #2371 from award999/workspace-playgrounds
`workspace/playgrounds` request
2025-12-13 15:40:29 +10:00
Owen Voorhees 260b4df07a Allow opting in to using the new SwiftPM BSP when opening a package 2025-12-10 13:17:25 -08:00
loveucifer cae01c623d Apply code review fixes for copied file handling
- Remove async from workspaceEditAdjustedForCopiedFiles
- Refactor to use uriAdjustedForCopiedFiles helper
- Update dictionary update logic with +=
- Adjust LocationLink creation to use adjusted ranges
- Ensure selectionRange adjustment in prepareCallHierarchy
- Provide default WorkspaceEdit in ClangLanguageService
- Revert asyncMap to map and remove await in SourceKitLSPServer
- Chain workspace and index retrieval in incomingCalls
- Use indexToLSPCallHierarchyItem and shared helper for CallHierarchyItem
- Fix indentation and remove duplicated detail setting
- Use shared helper for TypeHierarchyItem
- Remove .sort() from expected array in tests
- Enable testFindImplementationInCopiedHeader
- Add await for actor-isolated BuildServerManager calls
2025-12-10 23:47:52 +05:30
loveucifer 70d900e799 Extend copied file mapping to all LSP requests returning locations
This addresses issue #2276 by ensuring that all LSP requests that return source file locations
map copied header files back to their original locations, not just jump-to-definition.

Previously, only the definition request applied this mapping. Now, the following requests
also adjust locations for copied files:
- textDocument/references
- textDocument/implementation
- workspace/symbol
- callHierarchy/prepare
- callHierarchy/incomingCalls
- callHierarchy/outgoingCalls
- typeHierarchy/prepare
- typeHierarchy/supertypes
- typeHierarchy/subtypes

This provides consistent navigation behavior, ensuring users are always taken to the original
source files instead of build artifacts when possible.
2025-12-09 12:52:12 +05:30
Adam Ward 158529270c Only scan tests if part of a test target 2025-12-08 15:16:36 -05:00
Adam Ward 308375a135 Move syntactic index back to Workspace 2025-12-08 15:16:36 -05:00
Adam Ward 9602433d2a Add new workspace/playgrounds request 2025-12-08 15:16:36 -05:00
Ben Barham 9c145fd9a2 Merge pull request #2375 from bnbarham/pass-toolset-through
Pass toolsets through to preparation for the SwiftPM build server
2025-12-04 07:46:36 +10:00
Ben Barham 8ac9cd640d Resolve /usr/bin/* shims on macOS
CMake was previously doing this itself before 4.0, but seems to be
inserting `/usr/bin/*` now. Resolve the `/usr/bin` trampoline ourselves
in a similar fashion to swiftly (but with xcrun).

Resolves rdar://163462990.
2025-12-03 12:37:07 +10:00
Ben Barham 9952a11f4b Pass toolsets through to preparation for the SwiftPM build server
Also adds some logging to the synchronize request so that it's obvious
when background indexing is being skipped.

Fixes #2373
Resolves rdar://165519940
2025-12-03 10:19:49 +10:00
Anthony Latsis d1b9c27b95 Merge pull request #2366 from AnthonyLatsis/jepa
Enable some Swift 7 mode features
2025-12-02 17:37:01 +00:00
Anthony Latsis 6b19657739 Enable ExistentialAny 2025-12-02 12:27:27 +00:00
Alex Hoppen 99f2bb3915 Merge pull request #2364 from ahoppen/no-optional-map
Don’t use `Optional.map` or `Optional.flatMap`
2025-12-02 00:01:23 +01:00
Alex Hoppen 0e061c5c10 Merge pull request #2363 from ahoppen/preparation-status-trailing-slash
Fix issue that caused the target preparation status to not be cleared when workspace root did not have trailing slash
2025-11-21 06:08:01 +01:00
Alex Hoppen f9f13a4105 Don’t use Optional.map or Optional.flatMap
Replace usages of `Optional.map` and `Optional.flatMap` by if expressions or other expressions.

I personally find `Optional.map` to be hard to read because `map` implies mapping a collection to me. Usually the alternative constructs seem clearer to me.
2025-11-20 09:47:21 +01:00
Alex Hoppen 05b290ea9d Fix issue that caused the target preparation status to not be cleared when workspace root did not have trailing slash
If a workspace was opened as `/path/to/workspace` instead of `/path/to/workspace/` (notice the trailing slash), the check for `url.deletingLastPathComponent() == self.projectRoot` failed because deleting the last path component always produces a URL with a trailing slash and URL considers two path different if they mismatch in their trailing slash usage.

Use `DocumentURI` for equality checking, which is a little more lenient with declaring equality, including with regard to trailing slashes, and whose equality definition aligns better with what we want in SourceKit-LSP.

I searched for other usages of `==` between URLs and there doesn’t seem to be any similar issues.
2025-11-20 09:21:47 +01:00
Ben Barham b3cb43fb74 Ensure the string passed to PathIsRelativeW is null terminated
`CompilationDatabaseTests` have been flakey on Windows since
https://github.com/swiftlang/sourcekit-lsp/pull/2334. This didn't really
introduce the failure though - it just added tests that now catch it.

The underlying cause is that `filename.isAbsolutePath` sometimes returns
`true` for a relative path, which then causes the CWD to be prepended
instead of the given `compileCommandsDirectory`.

`PathIsRelativeW` requires a null terminated string, so presumably we
were hitting junk after the initial path that sometimes turned it into
an absolute path. From the Windows docs:
> A pointer to a null-terminated string of maximum length MAX_PATH that
contains the path to search.

Fixes #2360
Resolves rdar://165006835
2025-11-20 13:43:49 +10:00
Owen Voorhees f04b971726 Adopt swift-tools-protocols 2025-10-31 14:11:11 -07:00
Alex Hoppen c34d9e20fe Interpret the working directories in compile_commands.json relative to the directory that contains compile_commands.json
Fixes #1908
2025-10-30 08:38:08 +01:00
Alex Hoppen 76847dbf27 Do not try to infer build settings from a sibling file if determining the target timed out 2025-10-16 07:44:54 +02:00