Commit Graph

521 Commits

Author SHA1 Message Date
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 a39c92022f Add forOpenDocument label to language service lookup methods
Rename languageServices(for:), primaryLanguageService(for:), and their
internal counterparts to use the `forOpenDocument` label, so the
precondition that the document must already be open is visible at call
sites.

Also make primaryLanguageService(forOpenDocument:) throw instead of
returning an optional, and switch several resolve-style handlers from
the find-or-create primaryLanguageService(for:_:) to
primaryLanguageService(forOpenDocument:), since those call sites already
have an open document in hand.
2026-05-20 10:31:44 -07: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 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 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
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
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 7e853de0ce When background indexing is disabled, attempt to infer the SwiftPM build system 2026-03-18 18:19:25 -07:00
Doug Gregor 8252acf822 Merge pull request #2562 from DougGregor/avoid-module-source-info
Ignore module source info files in tests affected by them
2026-03-18 16:21:38 -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
Rintaro Ishizaki 99905fc533 [Tests] Report XCTFail for unfulfilled XCTestExpectations
Otherwise, the failures were often reported as confusing
`failed: caught error: "CancellationError()"`
2026-03-17 13:39:29 -07:00
Doug Gregor aa75264c8e Ignore module source info files in tests affected by them 2026-03-17 09:40:12 -07:00
Owen Voorhees 9bd1e9d766 Eliminate just-built SwiftSyntax dependency from macro tests 2026-03-16 16:51:37 -07:00
Owen Voorhees 796bd64b9b Use Bundle.module when looking up test resources 2026-03-15 16:49:17 -07:00
Alex Hoppen d13471cc74 Merge pull request #2485 from Steffeeen/semantic-tokens
Only create semantic tokens in cases where they are actually needed
2026-03-15 13:33:15 +01:00
Steffeeen dc2da5cc58 Add reportSyntacticHighlightInSemanticTokens config option
When this option is set to `true` the results for
`textDocument/semanticTokens` include semantic tokens for syntactic
highlighting obtained from swift-syntax. If this option is set to
`false` only the semantic tokens obtained from SourceKit are included.
This option defaults to `false`.
2026-03-13 17:02:47 +01:00
Rintaro Ishizaki 2d699a1b86 Merge pull request #2482 from rintaro/testsupport-no-gpg-sign
[TestSupport] Don't try to GPG-sign commits
2026-02-16 10:20:23 -08:00
Rintaro Ishizaki c802fa995b [TestSupport] Don't try to GPG-sign commits
When `commit.gpgsign = true` is enabled globally, signing fails because
the author 'Dummy <noreply@swift.org>' likey has a no configured GPG
key, causing test failures.
2026-02-14 07:10:13 -08:00
Hamish Knight b2f42a1c48 Test to make sure sourcekitd doesn't change working directory
Ensure that the working directory remains consistent across the
lifetime of `TestSourceKitLSPClient`.
2026-02-09 10:05:13 +00:00
Alex Hoppen 596a51619d Merge pull request #2419 from ahoppen/remove-test-connection
Remove `TestJSONRPCConnection`
2026-01-16 07:42:20 +01:00
Karan Lokchandani 473088afe6 Add position markers in the expected ranges (#2449)
this should make tests more readable, follow up to this pr
https://github.com/swiftlang/sourcekit-lsp/pull/2435
reference comment here
https://github.com/swiftlang/sourcekit-lsp/pull/2435#discussion_r2670161613

---------

Signed-off-by: Karan <karanlokchandani@protonmail.com>
2026-01-13 23:06:06 +01:00
Alex Hoppen 24941a4af7 Remove TestJSONRPCConnection
This isn’t used anywhere. Noticed this while trying to fix a build warning in the file.
2026-01-04 09:51:26 +01:00
Alex Hoppen 219428328c Address my own review comments
Apply the following changes:
- Check for the presence of `#Playgrounds` textually before getting the module name in `SwiftPlaygroundsScanner`. This is important because getting the module name requires us to get build settings for the file, which can be expensive. Do the cheaper check first
- Make `syntacticTests` and `syntacticPlaygrounds` closures capture the workspace instead of passing the workspace from the `SwiftSyntacticIndex` back out. I like this better because now we can’t accidentally pass the wrong workspace to a `SwiftSyntacticIndex`, eg. to `buildTargetsChanges`.
- Capture the initialize result in `TestSourceKitLSPClient` instead of using `postInitialization` to capture the result
- Minor cleanup of unnecessary abstractions, likely artifacts of earlier iterations
- Restructure tests so that every test has its own list of source files, allowing for easier local reasoning – turns out some of these tests didn’t even need to open a workspace, just to check the initialize response
2025-12-08 15:16:36 -05:00
Adam Ward 60289cdfd6 Add tests 2025-12-08 15:16:36 -05: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
Ben Barham 525af90c11 Revert "Temporarily skip macro tests on Amazon Linux" 2025-11-21 08:42:47 +10:00
Adam Ward ddcddded67 Support swift.play in textDocument/codelens request
- New `swift.play` CodeLens support that is an experimental feature while [swift play](https://github.com/apple/swift-play-experimental/) is still experimental
- Add #Playground macro visitor to parse the macro expansions
- File must `import Playgrounds` to record the macro expansion
- The `swift-play` binary must exist in the toolchain to
- TextDocumentPlayground will record the id and optionally label to match detail you get from
```
$ swift play --list
Building for debugging...
Found 1 Playground
* Fibonacci/Fibonacci.swift:23 "Fibonacci"
```
- Add LSP extension documentation for designing pending `workspace/playground` request
- Add new parsing test cases
- Update CMake files

Issue: #2339 #2343

Add column to unnamed label

Update Sources/SwiftLanguageService/SwiftCodeLensScanner.swift

Co-authored-by: Alex Hoppen <alex@alexhoppen.de>

Update Sources/SwiftLanguageService/SwiftPlaygroundsScanner.swift

Co-authored-by: Alex Hoppen <alex@alexhoppen.de>

Update Sources/SwiftLanguageService/SwiftPlaygroundsScanner.swift

Co-authored-by: Alex Hoppen <alex@alexhoppen.de>

Update Tests/SourceKitLSPTests/CodeLensTests.swift

Co-authored-by: Alex Hoppen <alex@alexhoppen.de>

Address review comments

Fix test failures

Fix more review comments

Update for swift-tools-core
2025-11-07 15:51:17 -05:00
Ben Barham d046c7be2d Temporarily skip macro tests on Amazon Linux
These are failing on the 2023 bootstrap job, skip for now to allow
getting a toolchain out.
2025-11-06 07:15:10 +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 abf98b9283 Merge pull request #2314 from ahoppen/new-upcoming-features
Enable `InferIsolatedConformances` and `NonisolatedNonsendingByDefault`
2025-10-09 20:46:03 +02:00
Alex Hoppen 9dff775010 Enable InferIsolatedConformances and NonisolatedNonsendingByDefault
This allows us to easily get rid of some `@_inheritActorContext`. The others seem to be a little more tricky and I haven’t spent too much time at trying to figure out how to remove the attribute from those.
2025-10-09 00:46:48 +02:00
Doug Gregor 555816c651 Merge pull request #2312 from DougGregor/swift-if-config-dependency
Add SwiftIfConfig as a dependency for macro testing
2025-09-30 18:08:20 -07:00
Doug Gregor 8f6da7c439 Add SwiftIfConfig as a dependency for macro testing 2025-09-30 09:20:29 -07:00
Alex Hoppen 6b494ddf95 Flush logs at the end of test execution
Otherwise it sometimes happens that shutdown and other messages are logged during the next test’s execution, which makes it harder to diagnose issues.
2025-09-29 13:51:09 +02:00
Alex Hoppen 95538e7de9 Migrate appendingPathComponent to appending(component:)
`appending(component:)` is the more modern API and can take multiple path components at the same time.
2025-09-23 16:57:56 +02:00
Alex Hoppen 078a996dac Merge pull request #2293 from ahoppen/multi-file-indexing
Support indexing of mulitple Swift files within the same compiler invocation
2025-09-22 09:02:03 +02:00
Alex Hoppen d1981debec Do not cancel update index store tasks in favor of a task with fewer files
We should not take the number of files in an `UpdateIndexStoreTaskDescription` as an indication on how important the task is. If we do need this functionality, eg. because we want to update the index of files with syntactic matches for a rename term, this should be communicated using a specific purpose similar to `TargetPreparationPurpose`. Since the only reason we update the index store for a file right now is background indexing, such a check is not needed.
2025-09-20 16:26:26 +02:00
Alex Hoppen a005021666 Support indexing of mulitple Swift files within the same compiler invocation
Fixes #1268
2025-09-20 16:26:26 +02:00
Hamish Knight 2aa09ae0a1 Fix sourcekitdSupportsFullDocumentationInCompletion to not rely on ideApi
`ideApi` is only available within the plugin itself, it's not available
to sourcekitd. Switch to sending a completion request and checking
that we get full documentation back.
2025-09-19 17:13:18 +01:00
Alex Hoppen 346c978576 Merge pull request #2290 from ahoppen/custom-build-server-test-project
Use `CustomBuildServerTestProject` in `BuildServerTests`
2025-09-13 11:55:47 +02:00
Alex Hoppen daf16c4909 Use CustomBuildServerTestProject in BuildServerTests
I suspect that we don’t wait for `TestSourceKitLSPClient` to finish deinitializing (and thus waiting for the shutdown response) when we destroy it in `tearDown` based on the logs in https://ci.swift.org/job/oss-swift-incremental-RA-macos-apple-silicon/9004 (rdar://160344405).

Since I generally dislike the `setUp` and `tearDown` methods and we have `CustomBuildServerTestProject` now to model a setup of a SourceKitLSP server with a custom build server, use that instead of manually hooking up the build server through a workspace.
2025-09-12 08:37:57 +02:00
Ahmed Mahmoud 8c1ea67fc0 Skip signature help tests if not supported in sourcekitd 2025-09-06 00:53:16 +03:00