99 Commits

Author SHA1 Message Date
Rintaro Ishizaki 25a8eb7758 Advertise experimental BSP client capabilities in build/initialize
Lets BSP servers know which SourceKit extension methods SourceKit-LSP
supports, so they can choose between the current sourcekit/-prefixed
names and the legacy names.
2026-06-22 11:16:39 -07:00
Rintaro Ishizaki 04118be02d Prefix SourceKit-LSP extension methods with sourcekit/
Rename all SourceKit-LSP–specific LSP and BSP extension requests and
notifications to use the `sourcekit/` prefix (e.g. `workspace/tests`
→ `sourcekit/workspace/tests`).

* Register the legacy name alias in `MessageRegistry` so incoming
  messages from existing clients are still dispatched correctly.
* Advertise both the new and legacy method names in the `experimental`
  capability dict so old clients can still discover the capabilities
  they know.
* Accept legacy names advertised by old clients in `CapabilityRegistry`.
* Use `LegacyNameFallbackConnection` to retry requests with the legacy
  method name when the peer returns `methodNotFound` for a
  `sourcekit/`-prefixed request. Used in:
  * `SourceKitLSPServer.client` (server→client) to keep old editors working
  * `ExternalBuildServerAdapter.connectionToBuildServer` (SourceKit-LSP→BSP)
    to keep old build servers working
2026-06-22 11:16:37 -07:00
Rintaro Ishizaki b9e4c67793 Delete SwiftExtensions duplicates of swift-tools-protocols APIs
Delete `Collection+Only.swift`, `Duration+Seconds.swift`,
`FileManagerExtensions.swift`, `PipeAsStringHandler.swift`, and
`URLExtensions.swift` from `Sources/SwiftExtensions/`. The same
APIs now live in swift-tools-protocols as `@_spi(SourceKitLSP)
public` declarations.

Update each call site to add `@_spi(SourceKitLSP) import
ToolsProtocolsSwiftExtensions` next to the existing
`import SwiftExtensions`. Add the
`_ToolsProtocolsSwiftExtensionsForPlugin` dependency and the
`ToolsProtocolsSwiftExtensions=_ToolsProtocolsSwiftExtensionsForPlugin`
module alias to the `SwiftSourceKitClientPlugin` target in both
`Package.swift` and the corresponding `CMakeLists.txt`.
2026-06-08 21:08:24 -07:00
Alex Hoppen ef86a32e96 Merge pull request #2672 from bripeticca/spm-api-traits
Fix spm API usage for appropriate trait configuration
2026-06-01 23:47:38 +02:00
Rintaro Ishizaki 13f842eb74 Bound task-scheduler shutdown wait and log process completion
Wrap each `task.waitToFinish()` in `TaskScheduler.shutDown()` with a
10s `withTimeout` so a stuck QueuedTask cannot block sourcekit-lsp's
shutdown indefinitely; on timeout, log the task description so the
offender is identifiable. The QueuedTask is already cancelled via
`task.cancel()` and continues winding down in the background.

Add debug logs after `Process.waitUntilExit()` returns and after
`Process.run` returns inside `prepare(singleTarget:)`, so a future
shutdown hang can be triaged: did the swift build process actually
exit, did `Process.run` propagate the result, or is the stall higher
up in the prepare chain.

Motivated by a recurring Windows CI hang in
BackgroundIndexingTests.testSymlinkedTargetReferringToSameSourceFile
where prepareForExit stalls for the full test timeout with no log
output during shutdown.
2026-05-28 21:45:23 -07:00
Bri Peticca cafbe12d95 Run formatter 2026-05-28 11:27:10 -04:00
Rintaro Ishizaki 99cac8f91d Update for the ThreadSafeBox.value setter removal 2026-05-27 14:36:56 -07:00
Bri Peticca da0c9a9ad9 Fix spm API usage for appropriate trait configuration
The `WorkspaceConfiguration.default` was being used to populate
the `Workspace`; there was an extra step here needed to assure that
we are propagating the trait configuration to the workspace.

The added test assures that non-default traits that are enabled are
indeed processed as enabled.
2026-05-27 12:57:16 -04:00
Rintaro Ishizaki a6c926fa34 Relax atomic memory orderings; switch semaphore to release/acquire
For ID counters and standalone flags (most sites), drop to .relaxed
since nothing reads other memory based on the atomic's value.

MultiEntrySemaphore.signaled is the exception: it is used as a
signal/wait primitive where waiters proceed to use state set up
before signal(). Use .releasing on store and .acquiring on load so
that pre-signal writes are visible to waiters that observe `true`.
.relaxed there would be incorrect on weakly-ordered architectures.
2026-05-21 11:16:17 -07:00
Rintaro Ishizaki 83de30d29f Migrate atomic call sites to Synchronization.Atomic and ThreadSafeBox
Replace AtomicBool/UInt8/UInt32/Int32 from
ToolsProtocolsSwiftExtensions with Synchronization.Atomic<T> where
the storage is a static, module-level let, or class stored property.
For local lets captured by @Sendable closures (where Atomic's
~Copyable nature prevents capture), use ThreadSafeBox<T> instead.
2026-05-21 10:58:34 -07:00
Rintaro Ishizaki f56a27b996 Fix build warnings 2026-05-18 18:04:44 -07:00
Alex Hoppen 0cacc26db3 Merge pull request #2591 from ahoppen/require-6.3
Require Swift 6.3
2026-05-18 15:27:18 +02:00
Rintaro Ishizaki 83afc9d1e1 Move CopiedFileMap LSP adjustments to extensions on LSP types
`CopiedFileMap` previously held methods like
`workspaceEditAdjustedForCopiedFiles`,
`callHierarchyItemAdjustedForCopiedFiles`, etc. that encoded knowledge
of high-level LSP message types into `BuildServerIntegration`.

Replace them with `adjusted(for:)` methods on each LSP type
(`Location`, `[Location]`, `LocationsOrLocationLinksResponse`,
`WorkspaceEdit`, `CallHierarchyItem`, `TypeHierarchyItem`) in a new
`LSP+CopiedFileMap.swift` in the SourceKitLSP module. The primitive
URI remapping is extracted into `CopiedFileMap.adjustedURI(for:)`
which remains in `BuildServerIntegration`.

`CallHierarchyItem.adjusted(for:)` also drops manual `LSPAny`
dictionary construction in favour of `HierarchyItemData`.
2026-05-07 16:10:02 -07:00
Rintaro Ishizaki 3d7ebf7f20 Factor out CopiedFileMap as a Sendable value type
Extract the copied-file adjustment logic from BuildServerManager into a
Sendable value type CopiedFileMap. Call sites snapshot cachedCopiedFileMap
once per request (hoisted before loops) instead of awaiting the actor on
every iteration.
2026-04-28 12:12:40 -07:00
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
Alex Hoppen 448164aae4 Require Swift 6.3
Swift 6.3 has been released and we no longer need to support building or testing SourceKit-LSP with Swift 6.2.
2026-04-03 08:14:13 +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