Commit Graph

96 Commits

Author SHA1 Message Date
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
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
Owen Voorhees
f04b971726 Adopt swift-tools-protocols 2025-10-31 14:11:11 -07: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
05c04decf2 Match the batch size for multi-file indexing to the driver's batch size
Until we have better measurements that would motivate a different batching strategy, copying the driver’s batch size seems like the most reasonable thing to do.
2025-09-22 09:52:44 +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
Alex Hoppen
e60894c482 Pass multiple URIs to updateIndexStore(forSwiftFiles:) 2025-09-13 12:44:05 +02:00
Alex Hoppen
78608933ba Guarantee that all files in a UpdateIndexStoreTaskDescription have the same language
It doesn’t make sense to try and index files with different langauges in a single compiler invocation.
2025-09-03 17:51:18 +02:00
Alex Hoppen
5c4f1ca93c Make UpdateIndexStoreTaskDescription.updateIndexStore handle mulitple files
This pushes multi-file indexing one level closer to the actual compiler invocation.
2025-09-03 08:58:01 +02:00
Alex Hoppen
690fd9288f Extract target out of the FileIndexInfo used by UpdateIndexStoreTaskDescription
This way we can guarantee that all files passed to `UpdateIndexStoreTaskDescription` belong to the same target, which will simplify multi-file indexing.
2025-09-03 08:45:04 +02:00
Alex Hoppen
dddc983dd2 Make BuildServerManager.toolchain only take a target, no document
The document wasn’t used in here.
2025-09-03 08:39:59 +02:00
Alex Hoppen
d73433128d Make the build/logMessage conform to the BSP spec
When I added the log structure to `build/logMessage` in #2022 I must have assumed that the entire BSP notifciation was an extension defined by SourceKit-LSP and didn’t realized that this was actually a change that made the notification non-compliant with BSP. Change it up a little bit to make it compliant again.
2025-09-02 20:41:40 +02:00
Alex Hoppen
3762e7a2a4 Fix all warnings
Fixes all warnings when building on macOS and Linux using Swift 6.1, Swift 6.2 and SDKs from Xcode 16.2 and Xcode 16.3
2025-08-25 14:40:16 +02:00
Alex Hoppen
98cd30bb1c Apply exhaustive swift-format configuration from swift-syntax
Apply the exhaustive swift-format configuration from https://github.com/swiftlang/swift-syntax/pull/3117 to sourcekit-lsp. Also apply all automatic formattings.
2025-08-11 09:23:39 +02:00
Alex Hoppen
7f4f92e5bd Rename build system to build server in most cases
The term *build system* predated our wide-spread adoption of BSP for communicating between SourceKit-LSP to the build system and was never really the correct term anyway – ie. a `JSONCompilationDatabaseBuildSystem` never really sounded right. We now have a correct term for the communication layer between SourceKit-LSP: A build server. Rename most occurrences of *build system* to *build server* to reflect this. There are unfortunately a couple lingering instances of *build system* that we can’t change, most notably: `fallbackBuildSystem` in the config file, the `workspace/waitForBuildSystemUpdates` BSP extension request and the `synchronize-for-build-system-updates` experimental feature.
2025-08-02 08:45:01 +02:00
Ben Barham
d5926bf69f Run formatting after swift-format changes 2025-06-30 17:08:05 -07:00
Alex Hoppen
8b2727f9f9 Ensure that unit file generated by background indexing are immediately loaded into indextore-db
Otherwise, we can end up in a situation where we declare indexing as done but haven’t loaded the new units into indexstore-db yet.
2025-03-19 07:24:16 -07:00
Alex Hoppen
d10c868497 Support indexing a file in the context of multiple targets
If a source file is part of multiple targets, we should index it in the context of all of those targets because the different targets may produce different USRs since they might use different build settings to interpret the file.
2025-03-14 15:49:59 -07:00
Alex Hoppen
1cfa8db1d8 Require Swift 6 to build SourceKit-LSP
This significantly cleans up our `import` statements
2025-03-07 08:05:49 -08:00
Alex Hoppen
9f5f06bc57 Merge pull request #2032 from ahoppen/ahoppen/response-file-indexing
Use response files to index files if argument list exceeds maximum number of arguments
2025-03-05 23:50:33 -08:00
Alex Hoppen
5541060451 Use response files to index files if argument list exceeds maximum number of arguments 2025-03-05 13:33:40 -08:00
Alex Hoppen
c3ecb9adae Add BSP request to get the output file paths of a target 2025-03-05 09:58:34 -08:00
Alex Hoppen
655a93f05a Add structure to the index logs
When the client supports it, communicate the structure of tasks that were stared during background indexing or by the build server to the client. If there are multiple operations happening in parallel, this allows the client to display them in separate log tracks instead of interspersing them with the emoji prefixes like we do today.
2025-03-04 16:36:26 -08:00
Alex Hoppen
0cb7c82d03 Use FileToIndex as the key of inProgressIndexTasks
Indexing a header via a main file and indexing the main file itself are two different index tasks that update the `indexStoreUpToDateTracker` in different ways. We should thus consider them differently in `inProgressIndexTasks` as well.
2025-03-01 09:24:13 -08:00
Alex Hoppen
628ce3cc63 If a build server doesn’t specify -index-store-path in the SourceKit options, add it during background indexing 2025-02-25 22:46:32 -08:00
Ben Barham
ab12429651 Update the compiler arguments used for background AST builds
This fixes two issues:
1. The SwiftPM build system was setup without passing through whether it
   should prepare or not. This meant that we lost eg. the argument to
   allow compiler errors when building the AST (even though it was set
   when building the modules)
2. The compiler argument adjustment to remove harmful and unnecessary
   flags only applied to indexing arguments, not those passed to the AST
   builds

Resolves rdar://141508656.
2025-02-07 11:57:30 -08:00
Alex Hoppen
c67c06e7b1 Merge pull request #1950 from ahoppen/gardening
Gardening
2025-01-24 22:33:51 -08:00
Alex Hoppen
64f2aef446 Fix build warnings
Quite a few of these were reminders to clean things up once we no longer need to support testing using compilers and sourcekitd from older toolchains.
2025-01-23 21:11:08 -08:00
Alex Hoppen
8cfc4b67f4 Add a hook to inject an IndexStoreDB instance into SourceKitLSPServer
rdar://142907558
2025-01-16 16:34:47 -08:00
Alex Hoppen
7fffc04e50 Mark all closures in the .stream outputRedirection of TSC as @Sendable
The closures aren’t guaranteed to be called on the same thread as the process was launched, which can cause assertion failure by the concurrency runtime.

rdar://142813605
2025-01-15 08:25:25 -08:00
Alex Hoppen
be546308ca Use URL in many cases where we used AbsolutePath
We made quite a few fixes recently to make sure that path handling works correctly using `URL` on Windows. Use `URL` in most places to have a single type that represents file paths instead of sometimes using `AbsolutePath`.

While doing so, also remove usages of `TSCBasic.FileSystem` an `InMemoryFileSystem`. The pattern of using `InMemoryFileSystem` for tests was never consistently used and it was a little confusing that some types took a `FileSystem` parameter while other always assumed to work on the local file system.
2024-11-18 18:19:48 -08:00
Alex Hoppen
8c2def8ef9 Rename SKSupport to LanguageServerProtocolExtensions 2024-11-13 16:53:58 -08:00
Alex Hoppen
47f3cd506b Split TSCExtensions into a separate module 2024-11-13 13:58:36 -08:00
Alex Hoppen
5bae73fca8 Use fallback build settings if build system doesn’t provide build settings within a timeout
When we receive build settings after hitting the timeout, we call `fileBuildSettingsChanged` on the delegate, which should cause the document to get re-opened in sourcekitd and diagnostics to get refreshed.

rdar://136332685
Fixes #1693
2024-10-16 10:55:29 -07:00
Alex Hoppen
8cd831b55d Adopt InternalImportsByDefault 2024-09-27 09:17:13 -07:00
Alex Hoppen
2ec571b529 Revert "Require a Swift 6 compiler to build SourceKit-LSP"
This reverts commit 7ab7c01cdc.

# Conflicts:
#	Package.swift
2024-09-26 18:23:59 -07:00
Alex Hoppen
7ab7c01cdc Require a Swift 6 compiler to build SourceKit-LSP
Xcode 16 with Swift 6 has been released, we can drop support for building and testing SourceKit-LSP using a Swift 5.10 toolchain. This allows us to remove a number of workarounds.
2024-09-17 16:53:13 -07:00
Alex Hoppen
d00722e33f Use BSP to log messages from preparation in the build system 2024-09-16 10:06:35 -07:00
Alex Hoppen
12923b6d73 Implement toolchain(for:) using BSP 2024-09-13 11:12:40 -07:00
Alex Hoppen
9d94fe36a9 Migrate defaultLanguage(for:) to BSP 2024-09-12 07:34:12 -07:00
Alex Hoppen
63c5ca4a2c Use BuildTargetIdentifier from BSP instead of ConfiguredTarget 2024-09-09 16:31:00 -07:00
Alex Hoppen
50a28bb86a Change FIXME and TODO comments to always have an associated issue
Do one of the following for every `FIXME` or `TODO` comment
- Add an issue that tracks the task
- Remove the comment if we are not planning to address it
2024-08-07 10:00:04 -07:00
Alex Hoppen
66f2d86775 Rename SKCore to BuildSystemIntegration 2024-07-25 09:11:13 -07:00
Alex Hoppen
cfe18f1256 Split toolchain-related functionality out of SKCore 2024-07-25 09:11:13 -07:00
Alex Hoppen
8c34a76f59 Rename LSPLogging to SKLogging 2024-07-25 09:11:13 -07:00
Alex Hoppen
2877675bd5 Adopt package access level
Change a l public declarations to the `package` access level, accept for:
- The `LanguageServerProtocol` module
- The `BuildServerProtocol` module
- `InProcessClient.InProcessSourceKitLSPClient`
- `LanguageServerProtocolJSONRPC` (I would like to create a more ergonomic API for this like `InProcessSourceKitLSPClient` in the future, but for now, we’ll leave it public)

Unfortunately, our pattern of marking functions as `@_spi(Testing) public` no longer works with the `package` access level because declarations at the `package` access level cannot be marked as SPI. I have decided to just mark these functions as `package`. Alternatives would be:
- Add an underscore to these functions, like we did for functions exposed for testing before the introduction of `SPI`
- Use `@testable` import in the test targets and mark the methods as `internal`

Resolves #1315
rdar://128295618
2024-07-19 09:54:30 -07:00
Alex Hoppen
2ba180b192 Send SIGKILL to swift-frontend indexing processes
We were sending `SIGINT` to `swift-frontend` processes if they didn’t terminate after 2 minutes. However, `swift-frontend` doesn’t listen to `SIGINT`.

If a task running `waitUntilExitStoppingProcessOnTaskCancellation` is cancelled and the process doesn’t terminate on a `SIGINT` after 2 seconds, kill it.

rdar://130103147
2024-06-26 09:43:05 +02:00
Alex Hoppen
e23e300f7c Add a request to re-index all files in SourceKit-LSP
Users should not need to rely on this request. The index should always be updated automatically in the background. Having to invoke this request manes there is a bug in SourceKit-LSP's automatic re-indexing. It does, however, offer a workaround to re-index files when such a bug occurs where otherwise there would be no workaround.

rdar://127476221
Resolves #1263
2024-06-26 06:33:32 +02:00
Alex Hoppen
da1f6dae80 Update links for repositories moved to the swiftlang org on GitHub 2024-06-25 04:34:28 -07:00