Commit Graph

1186 Commits

Author SHA1 Message Date
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
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 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
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
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 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 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
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 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 8804d2613c Move testJumpToCopiedHeader to CopyHeaderTests
Consolidate all test that test functionality for copy destinations. Also rename the test case because not only headers may be declared as copied using `copyDestinations`.
2026-03-23 17:23:05 +01:00
Paul LeMarquand 2814fa37ef Fix duplicate XCTest discovery for tests defined in extensions
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.

Related issue: https://github.com/swiftlang/vscode-swift/issues/2162
2026-03-23 11:39:55 -04: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 64a2e8bc4c Merge pull request #2573 from Bhushan-Aditya/fix-empty-actor-test
Fix testEmptyActor using class instead of actor declaration
2026-03-23 11:01:52 +01:00
Rintaro Ishizaki a9566ac183 [LSPAny] Replace manual LSPAnyCodable impl with Codable-backed default
Remove hand-written `init?(fromLSPDictionary:)` / `encodeToLSPAny()`
from LSPAnyCodable types, relying instead on the default implementations
backed by `LSPAnyEncoder`/`LSPAnyDecoder`
2026-03-22 08:01:17 -07:00
Rintaro Ishizaki 894496e9be Merge pull request #2549 from Tabonx/feature/codeAction-resolve-support 2026-03-22 06:11:21 -07:00
Bhushan-Aditya 81a54b4a81 Fix testEmptyActor using class instead of actor keyword
Made-with: Cursor
2026-03-22 12:29:46 +05:30
Pavel Kroupa 394bc3e19e Merge branch 'main' into convert-comment-to-doc-comment
# Conflicts:
#	Tests/SourceKitLSPTests/CodeActionTests.swift
2026-03-21 21:30:43 +01:00
Pavel Kroupa 8639c19347 Add codeAction/resolve support 2026-03-21 10:38:44 +01:00
Rintaro Ishizaki be2d554aa1 Merge pull request #2569 from ahoppen/wait-for-real-build-settings
Always wait for real build settings in `testExperimentalFeaturesPassedToSyntaxTreeManager`
2026-03-20 22:36:50 -07: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
Alex Hoppen e59d5e8bd3 Always wait for real build settings in testExperimentalFeaturesPassedToSyntaxTreeManager
If the SwiftPM build server is slow to respond, we may get document symbols based on a `SyntaxTreeManager` with fallback build settings, which would not contain the `_test_EverythingUnexpected` experimental feature and which would thus fail.

Similar issues existed in other tests as well.
2026-03-20 16:01:42 +01:00
Owen Voorhees 9b79fd7226 Improve failure message in potentially flaky test 2026-03-19 17:34:37 -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
Doug Gregor 795c5cc429 Set the -ignore-module-source-info flag in the right place for this test 2026-03-18 08:02:14 -07:00
Doug Gregor 336ea1bc2a [Test] Make sure to propagate extra compiler flags for single-file test projects 2026-03-17 14:49:00 -07:00