Commit Graph

1890 Commits

Author SHA1 Message Date
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 f9cbba2c2c Migrate test-case atomic usages to ThreadSafeBox / Atomic
Migrate remaining AtomicBool / AtomicUInt32 usages in test cases to
ThreadSafeBox / Atomic.

- Closure-captured `AtomicBool` flags become `ThreadSafeBox<Bool>` for
  now. We will revisit this when eliminating ThreadSafeBox.
- One `AtomicUInt32` counter (SourceKitDRegistryTests.swift's
  `nextToken`) to `Atomic<UInt32>`.
2026-05-22 16:40:29 -07:00
Steffeeen a7f43dc54c Fix rename target selection for initializer calls
When rename is invoked on a type name in an initializer call, prefer
renaming the nominal type symbol instead of the constructor symbol.
2026-05-21 10:55:47 +02:00
Rintaro Ishizaki b7fc4b5f1b Merge pull request #2655 from femaref/feature/proper-end
provide proper start and end positions in the LSP protocol
2026-05-18 21:03:48 -07:00
femaref c4c552203a provide proper start and end positions in the LSP protocol
vscode provides an alternative action if the target of goto definition is in the same character range we requested.
this requires the start and end in the LSP response to be properly set, so vscode can see that the current character
is actually part of the request
2026-05-19 00:02:17 +02:00
Rintaro Ishizaki f2a121453d Scope language service instances per workspace
Previously, language services were held in a global registry on
SourceKitLSPServer and shared across workspaces, requiring complex
lifetime tracking (isImmortal, shutdownOrphanedLanguageServices) to
decide when to tear them down. In practice, every language service
already stored workspace-specific properties (buildServerManager,
semanticIndexManagerTask), so sharing them across workspaces was never
truly safe. Giving each Workspace its own service instances simplifies
lifetime management: services are created when needed and shut down
with their workspace.

Remove LanguageService.isImmortal, the workspace parameter from
canHandle(toolchain:), and the initialize/clientInitialized protocol
requirements.
2026-05-18 09:21:01 -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 7519e7755c Merge pull request #2656 from rintaro/fix-deployment-target-mismatch 2026-05-18 05:36:44 -07:00
Rintaro Ishizaki 829802891d [Test] Fix deployment target mismatch in SwiftPMBuildServerTests
testToolsets: sourcekit-lsp is built against a just-built SwiftPM,
which can use macOS 10.13 as the minimum for packages with no explicit
platforms requirement. The preparation step runs the toolchain's
'swift build', which can use a higher macOS minimum deployment target.
The resulting module embeds a higher deployment target, causing a
spurious mismatch diagnostic when the other target imports it.

testBasicSwiftArgs (swiftbuild variant): swift-build can clamp the
deployment target to the SDK's MinimumDeploymentTarget, which can be
above the 10.13 the BSP reports, so the expected triple no longer
matches.

Fix by explicitly setting the deployment target to 13.0 in both test
packages via 'platforms: [.macOS(.v13)]'.
2026-05-17 15:52:31 -07:00
Alex Hoppen c8fb7afb6d Merge pull request #2644 from YooGyeongMo/fix-references-includes-definition 2026-05-17 22:04:56 +02:00
Rintaro Ishizaki 5c820cf61f Fix testClosingGeneratedInterfacePreservesOriginatingLanguageService on CI
Use IndexedSingleSwiftFileTestProject with -ignore-module-source-info
to force the generated interface code path. Without this, CI toolchains
(built from source) resolve String to actual stdlib source files, causing
GetReferenceDocumentRequest to receive a file:// URI instead of
sourcekit-lsp://, resulting in an "Invalid Scheme" error.
2026-05-14 11:09:08 -07:00
Edward Lee ca91f5ff4f Preserve language service when closing generated interface documents
Closing a generated interface document (sourcekit-lsp:// URI) was
removing the language service for the originating source file because
both share the same buildSettingsFile key. Guard the removal so it
only happens when no other open document shares that key.

Relates to #2209
2026-05-13 15:56:27 -07:00
G.M_YOO a1fc1ed917 Remove testReferencesWithDeclaration covered by existing tests 2026-05-13 22:38:45 +09:00
25harsh 90ceac197d Use ExpressibleByLiteral conformances for LSPAny 2026-05-13 16:19:42 +05:30
Rintaro Ishizaki 223a88cb8c Add workspace/symbolNames and workspace/symbolInfo LSP extensions (#2619)
- **`sourcekit/workspace/symbolNames`** — returns a flat, deduplicated
list of every symbol name in the workspace index (source and indexed
system modules). Clients use this to drive their search UI locally.

- **`sourcekit/workspace/symbolInfo`** — given a list of exact symbol
names, returns `WorkspaceSymbolItem` for each occurrence across all
workspaces, for display in the search result list. Source-file symbols
get `SymbolInformation` with a `file://` location. SDK/stdlib symbols
get a `WorkspaceSymbol` with `location: .uri(…)` The client must call
`workspaceSymbol/resolve` after the user selects an SDK/stdlib symbol to
obtain the concrete interface location.

- **`workspaceSymbol/resolve`** — resolves the deferred
`WorkspaceSymbol` location from `sourcekit/workspace/symbolInfo`. Parses
the `?module=` value into `moduleName`/`groupName`, finds a real source
file via `mainFiles(containing:)`, calls `openGeneratedInterface`, and
returns the symbol with `location` replaced by a full
`sourcekit-lsp://generated-swift-interface/` URI + range (or a temp
`file://` path for clients without `workspace/getReferenceDocument`
support).
2026-05-12 22:21:17 -07:00
G.M_YOO a6a9c4412e Add test coverage for ReferencesContext.includeDeclaration
Revert the earlier behavior change and add regression test coverage for both modes of `includeDeclaration`. sourcekit-lsp already handles this per the LSP spec.

These tests pin the behavior so it cannot regress.

Related to #2638
2026-05-12 21:20:36 +09:00
G.M_YOO f874cc73d3 Exclude the symbol's own definition from the references response
References should return use sites, not the definition itself.
The textDocument/references request was including the symbol's own definition, adding noise when navigating from a definition.

This change removes .definition from the roles set when includeDeclaration is true. The existing testReferencesInMacro test was also updated to apply the same principle consistently across the macro case.

Fixes #2638
2026-05-12 20:08:03 +09:00
25harsh f185bc404f [SwiftSyntaxCodeActions] Moved syntactic code actions into a new module 2026-05-11 11:10:40 +05:30
Rintaro Ishizaki e638498119 Merge pull request #2580 from Steffeeen/local-sourcekit-build-docs
[ContributorDoc] Add detailed docs for using a local build of SourceKit
2026-05-10 17:59:30 -07:00
Steffeeen 7166514240 Add SOURCEKIT_LSP_RUN_SOURCEKITD_IN_PROCESS environment variable
This environment variable can be used to force SourceKit-LSP to run
SourceKitD in-process on macOS. This can be useful for debugging.
2026-05-10 16:40:40 +02:00
Rintaro Ishizaki 2773bcdfa2 Merge pull request #2633 from rintaro/sourcekitd-inject
Allow injection of a pre-initialized sourcekitd connection
2026-05-07 19:57:41 -07:00
Rintaro Ishizaki 4b2fa3193a Allow injection of a pre-initialized sourcekitd connection
Introduce `SourceKitDCore` as the protocol boundary between dylib
lifecycle management and the high-level `SourceKitD` API. Its single
lifecycle entry point, `initializeService(api:notificationCallback:)`,
receives the already-loaded `sourcekitd_api_functions_t` from
`SourceKitD.init(core:)`.

`SourceKitDCoreImpl` is the standard implementation: `init` opens the
dylib; `initializeService` registers any plugin paths, calls
`api.initialize()`, and wires the notification handler; `deinit` calls
`shutdown()` and closes the handle. Pre-initialized conformances
implement `initializeService` as a no-op.

Wire a `sourcekitdCoreInjector` hook through `Hooks` so an embedding
host can return a pre-initialized `SourceKitDCore` for a given toolchain
path, preventing `sourcekitd_initialize()` from being called a second
time.

Declare `SourceKitDCoreForPlugin` at its use sites so each call site
can express the exact deinit behavior it needs: `dlclose` for handles
acquired via `RTLD_NOLOAD`, and `leak` for externally-owned handles.
2026-05-07 09:58:47 -07:00
Alex Hoppen 234890c484 Merge pull request #2607 from DeeSee/fix-duplicate-rename-edits
Make RenameLocation unique
2026-05-04 19:23:37 +02:00
Bassam Khouri 1f7be4b2ef Tests: Update tests based
There was feedback in #2621 to update how the `.buildSystem_{config}`
file was be created.  While looking as this change, I converted one test
to a parameterized and also ensure the `.buildSystem_{config}` file is
created in the `createFiles()` call.

Relates to #2621
2026-04-30 10:50:21 -04:00
Alexander Skvortsov 0b1a2cb372 Make RenameLocation unique 2026-04-30 17:27:19 +03:00
Alex Hoppen caa4b97c57 Merge pull request #2597 from Steffeeen/inlay-hint-performance
Cache inlay hints to avoid flickering
2026-04-30 15:37:42 +02:00
Steffeeen c5593c09c6 Cache inlay hints to avoid flickering
Previously, we always recomputed the inlay hints by calling into
SourceKit. If the document that we compute inlay hints for has recently
changed, SourceKit may need a bit of time to recompute the semantic
analysis. The inlay hints may thus need roughly 200-700ms to be
computed. This causes flickering in VSCode as it removes the old inlay
hints immediately and only displays them again when SourceKit-LSP
returned them.

With this commit we cache the inlay hints and recompute them in the
background. After the recompute is finished we use
`workspace/inlayHint/refresh` request to tell the client to refresh its
inlay hints. On each textDocument/didChange request the cached inlay
hints are shifted according to the text edits to ensure their positions
are still correct. This avoids the flickering as we can always return
the cached inlay hints immediately. The returned hints may however
temporarily show outdated type information until the background
recompute is finished.
2026-04-29 20:45:23 +02: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 709ff92adc Merge pull request #2617 from rintaro/fix-rdar175272642
[Test] Fix testCompilerArgumentsForFileThatContainsPlusCharacterURLEcoded
2026-04-23 06:39:22 -07:00
Rintaro Ishizaki 9e6b71dc07 [Test] Fix testCompilerArgumentsForFileThatContainsPlusCharacterURLEncoded
The test was constructing the percent-encoded file URL from `filePath`,
which uses native OS path separators. On Windows this produced a
backslash-separated path inside a `file://` URL, making the URL
malformed. Fix by replacing `+` with `%2B` in `absoluteString` instead,
which is already a well-formed URL string with forward slashes on all
platforms.

rdar://175272642
2026-04-22 13:03:57 -07: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
Rintaro Ishizaki dfa7df3f6f [Test] Disable a test case while investigating
rdar://175272642
2026-04-21 15:47:27 -07:00
Alex Hoppen d3847f023e Merge pull request #2417 from ahoppen/no-implicit-cancellation
Don’t implicitly cancel requests when an edit is detected
2026-04-09 06:56:18 +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 facfb28d39 Don’t implicitly cancel requests when an edit is detected
Instead, use `staleRequestSupport.retryOnContentModified` as an indicator which requests should return a `ContentModified` error when the document is modified. This fixes https://github.com/swiftlang/sourcekit-lsp/issues/2136 by no longer implicitly cancelling inlayHints in Helix while still implicitly cancelling semantic tokens request, which was the motivation for https://github.com/swiftlang/sourcekit-lsp/pull/1629.

Fixes #2136
2026-04-03 13:38:40 +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
Rintaro Ishizaki 9f46380e08 Merge pull request #2587 from rintaro/test-compile-6.2
[Tests] Fix build failures when using 6.2 toolchains
2026-03-31 18:04:50 -07:00
Rintaro Ishizaki c0e890e689 [Tests] Fix build failures when using 6.2 toolchains 2026-03-31 13:01:24 -07:00
Rintaro Ishizaki 9af6d04520 [Test] Make testMakeCallIsNotCancelledBySubsequentScheduleCall robust
Without this change, the expectations could be fulfilled twice, which is
a API usage violation.
2026-03-31 10:15:27 -07:00
Rintaro Ishizaki df14928358 Merge pull request #2553 from Tabonx/convert-comment-to-doc-comment
Add ConvertCommentToDocComment refactoring action
2026-03-31 09:53:26 -07: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
Rintaro Ishizaki e21d2bd9ba Merge pull request #2489 from rintaro/test-discovery-refresh
[Test/PlaygroundsDiscovery] Add "/refresh" style entry point requests
2026-03-27 16:10:12 -07:00
Rintaro Ishizaki 64aa354caf [TestDiscovery] "/refresh" style tests/playgrounds requests
When the client opts in to `workspace/tests/refresh` or
`workspace/playgrounds/refresh` via experimental client capabilities,
SourceKit-LSP now maintains a proactive cache of the current test and
playground lists and sends the corresponding `workspace/.../refresh`
notification whenever the cache changes. `workspaceTests()` /
`workspacePlaygrounds()` then serve subsequent fetch requests directly
from the cache.

Add `EntryPointManager`: runs background scans, stores the results,
fires callbacks on changes:
 - Start scanning when build targets are updated including initial
   updates, any watched files are changed, and index is updated.
 - Send '/refresh' server initiated requests when the cache has changed.
 - Coalesces rapid invalidations by cancelling any in-flight refresh task.

Also:
- Simplify `SourceKitIndexDelegate` from an `actor` with `AtomicInt32`
  to a plain `class`, since it is only called from IndexStoreDB's
  internal serial dispatch queue.
2026-03-27 09:32:59 -07:00
Rintaro Ishizaki 10be054a63 [SKUtilities] Fix Debouncer deadline reset on subsequent scheduleCalls
`inProgressData` was always storing `ContinuousClock.now + debounceDuration`
instead of the computed `targetDate`, causing the debounce deadline to reset
on every call rather than being fixed at the time of the first `scheduleCall`.
2026-03-26 15:06:56 -07:00
Paul LeMarquand 9af9441d59 Merge pull request #2575 from plemarquand/dup-test-discovery-fix
When semantic test discovery encounters XCTest methods in an extension it adds the extension definition to the root items list for each child test method. With N test methods, the same extension root appears N times, each copy receiving all N children. After merging, this produces N*N test items instead of N.

The bug is normally masked by the syntactic index, which provides correct results that take priority via combineTests(). This bug was exposed while I was debugging why tests generated by build plugins would appear multiple times. Turns out because they don't exist on disk at the time of the syntatic scan only the semantic results are used, which surfaced the issue.

The fix is to track already-added extension USRs to ensure each extension added once as a root item.
2026-03-25 12:26:14 -04:00
Alex Hoppen 97ce44d98c Merge pull request #2412 from ahoppen/semantic-functionality-in-copies
Provide semantic functionality in copy destinations
2026-03-24 14:59:09 +01:00
Paul LeMarquand 74234e2f00 Cleanup test markers 2026-03-24 09:51:02 -04:00
Rintaro Ishizaki 83a9f88cd9 Merge pull request #2568 from rintaro/lspany-codable
[LSPAny] Replace manual LSPAnyCodable impl with Codable-backed default
2026-03-23 10:56:41 -07:00
Alex Hoppen 3f82222c05 Merge pull request #2565 from ahoppen/skip-swiftpm-bsp-server
Skip tests for the experimental SwiftPM build server if it is not installed in the user's toolchain
2026-03-23 17:30:07 +01:00