Commit Graph

52 Commits

Author SHA1 Message Date
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
Adam Ward
158529270c Only scan tests if part of a test target 2025-12-08 15:16:36 -05:00
Adam Ward
308375a135 Move syntactic index back to Workspace 2025-12-08 15:16:36 -05:00
Adam Ward
9602433d2a Add new workspace/playgrounds request 2025-12-08 15:16:36 -05:00
Ben Barham
9c145fd9a2 Merge pull request #2375 from bnbarham/pass-toolset-through
Pass toolsets through to preparation for the SwiftPM build server
2025-12-04 07:46:36 +10:00
Ben Barham
8ac9cd640d Resolve /usr/bin/* shims on macOS
CMake was previously doing this itself before 4.0, but seems to be
inserting `/usr/bin/*` now. Resolve the `/usr/bin` trampoline ourselves
in a similar fashion to swiftly (but with xcrun).

Resolves rdar://163462990.
2025-12-03 12:37:07 +10:00
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
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
Alex Hoppen
99f2bb3915 Merge pull request #2364 from ahoppen/no-optional-map
Don’t use `Optional.map` or `Optional.flatMap`
2025-12-02 00:01:23 +01:00
Alex Hoppen
0e061c5c10 Merge pull request #2363 from ahoppen/preparation-status-trailing-slash
Fix issue that caused the target preparation status to not be cleared when workspace root did not have trailing slash
2025-11-21 06:08:01 +01: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
Alex Hoppen
05b290ea9d Fix issue that caused the target preparation status to not be cleared when workspace root did not have trailing slash
If a workspace was opened as `/path/to/workspace` instead of `/path/to/workspace/` (notice the trailing slash), the check for `url.deletingLastPathComponent() == self.projectRoot` failed because deleting the last path component always produces a URL with a trailing slash and URL considers two path different if they mismatch in their trailing slash usage.

Use `DocumentURI` for equality checking, which is a little more lenient with declaring equality, including with regard to trailing slashes, and whose equality definition aligns better with what we want in SourceKit-LSP.

I searched for other usages of `==` between URLs and there doesn’t seem to be any similar issues.
2025-11-20 09:21:47 +01:00
Ben Barham
b3cb43fb74 Ensure the string passed to PathIsRelativeW is null terminated
`CompilationDatabaseTests` have been flakey on Windows since
https://github.com/swiftlang/sourcekit-lsp/pull/2334. This didn't really
introduce the failure though - it just added tests that now catch it.

The underlying cause is that `filename.isAbsolutePath` sometimes returns
`true` for a relative path, which then causes the CWD to be prepended
instead of the given `compileCommandsDirectory`.

`PathIsRelativeW` requires a null terminated string, so presumably we
were hitting junk after the initial path that sometimes turned it into
an absolute path. From the Windows docs:
> A pointer to a null-terminated string of maximum length MAX_PATH that
contains the path to search.

Fixes #2360
Resolves rdar://165006835
2025-11-20 13:43:49 +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
76847dbf27 Do not try to infer build settings from a sibling file if determining the target timed out 2025-10-16 07:44:54 +02:00
Alex Hoppen
c360cfa8c1 Make buildSettings(for:in:langauge:fallbackAfterTimeout:) require a target
This simplifies the control flow to get build settings slightly.
2025-10-11 12:20:13 +02:00
Alex Hoppen
f7dba31ac9 Infer build settings from a sibling file if current file doesn’t have build settings 2025-10-11 12:20:12 +02:00
Alex Hoppen
331f15659c Merge pull request #2311 from ahoppen/long-build-server-init
Do not block SourceKit-LSP functionality when a build server takes long to initialize
2025-09-30 08:22:24 +01:00
Alex Hoppen
a6c291b84e Do not block SourceKit-LSP functionality when a build server takes long to initialize
We previously waited for the initialization response from the build server during the creation of a `Workspace` so that we could create a `SemanticIndexManager` with the index store path etc. that was returned by the `build/initialize` response. This caused all functionality (including syntactic) of SourceKit-LSP to be blocked until the build server was initialized.

Change the computation of the `SemanticIndexManager` and related types to happen in the background so that we can provide functionality that doesn’t rely on the build server immediately.

Fixes #2304
2025-09-29 13:02:08 +01:00
Ben Barham
8c4f1ad847 Log when absolute compilation DB search paths are skipped
Absolute search paths were being ignored without logging, which makes it
somewhat difficult to diagnose. Log when they're skipped.

Also remove a duplicate options merging block - both
`createWorkspaceWithInferredBuildServer` and `findImplicitWorkspace`
(the only callers of `createWorkspace`) already merge in the workspace
options.
2025-09-26 14:25:55 -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
32e919c0cd Merge pull request #2302 from ahoppen/multi-file-indexing-batch-size
Match the batch size for multi-file indexing to the driver's batch size
2025-09-23 16:53:57 +02:00
Alex Hoppen
aa7ff70042 Merge pull request #2300 from ahoppen/drop-6.1
Drop support for building with Swift 6.1
2025-09-22 14:16:39 +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
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
c7ca73aecb Drop support for building with Swift 6.1
Swift 6.2 has been released, so we no longer need to support building and testing SourceKit-LSP using Swift 6.1
2025-09-20 16:37:24 +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
fa67c22235 Merge pull request #2277 from ahoppen/bsp-timeouts
Add a timeout for `workspace/buildTargets` and `buildTarget/sources` requests
2025-09-20 13:13:40 +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
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
c142b601ff Add a timeout for workspace/buildTargets and buildTarget/sources requests
This allows us to provide functionality based on fallback settings for unresponsive BSP servers.

Fixes #2252
2025-09-01 16:12:41 +02:00
Alex Hoppen
b88543954c Merge pull request #2271 from ahoppen/copied-files
Add support for copied header files to SourceKit-LSP
2025-09-01 12:48:58 +02:00
Alex Hoppen
1aae2a4c32 Merge pull request #2266 from ahoppen/bsp-failed-to-initialize
If a BSP server fails to initialize, show the error message to the user
2025-08-31 08:22:56 +02:00
Alex Hoppen
882c990cae Add support for copied header files to SourceKit-LSP
If a build server copies files (eg. header) to the build directory during preparation and those copied files are referenced for semantic functionality, we would currently jump to the file in the build directory. Teach SourceKit-LSP about files that are copied during preparation and if we detect that we are jumping to such a file, jump to the original file instead.

So far only the definition request checks the copied file paths. Adding support for copied file paths in the other requests will be a follow-up change.
2025-08-30 23:35:14 +02:00
Alex Hoppen
d9046e4737 Fix issue that caused targets to be sorted top-down instead of bottom-up for background indexing
This sign flip slipped in with https://github.com/swiftlang/sourcekit-lsp/pull/1674.

There was also a non-determinism in the prepration schedule order.
2025-08-30 20:49:55 +02:00
Alex Hoppen
3f9dedd663 If a BSP server fails to initialize, show the error message to the user
When the BSP server fails to initialize, it can’t give us any compiler arguments and we won’t be able to provide semantic functionality. Show the message to the user so they can do something about fixing it instead having to dig into SourceKit-LSP logs.
2025-08-28 16:42:38 +02:00
Matthew Bastien
58096eb822 cache snapshots opened in sourcekitd by textDocument/doccDocumentation requests 2025-08-27 15:30:50 +02:00
Alex Hoppen
35556757e7 Merge pull request #2254 from ahoppen/remove-pound-if 2025-08-26 07:27:52 +02:00
Alex Hoppen
509ac6f9be Replace a couple of #if conditions by runtime checks
This ensures that we build all branches on all platforms, reducing the likelihood of build failures on other platforms.
2025-08-25 23:33:17 +02:00
Alex Hoppen
c31b62eeda Merge pull request #2259 from ahoppen/only-reload-current-package
Improve package reloading logic when manifest is changed
2025-08-25 23:26:25 +02:00
Alex Hoppen
ac0eb22226 Improve package reloading logic when manifest is changed
Two improvements to the logic that determines if we need to reload the package on a file change:
1. Only reload a package if the modified package manifest or Package.resolved is in the root of the package folder. This is relevant if we have a multi-root workspace, in which currently a single change to a package manifest or Package.resolved causes all packages to get reloaded.
2. While I was at it, I noticed that we didn’t properly handle version-specific package manifests. Also trigger a package reload if a version-specific package manifest is modified, created or deleted.
2025-08-25 09:23:08 +02:00
Alex Hoppen
13007e7493 Catch output-file-map.json write error thrown from TSC
We already had logic to retry loading a package manifest if writing the output-file-map failed. This only covered errors thrown from Foundation but I was seeing similar errors from TSC. Cover those as well.
2025-08-25 07:48:46 +02:00
Alex Hoppen
d811fcf855 Ensure that we end the Reloading package interval if a call in reloadPackageAssumingOnPackageLoadingQueue throws
If a call in `reloadPackageAssumingOnPackageLoadingQueue` throws, we weren’t getting to the end of it and would thus never end the signpost started within. Move the `endInterval` call up ensure it is always ended.

Found this while investigating https://ci-external.swift.org/job/swift-PR-windows/44247/console, which failed SourceKit-LSP testing because PackageA could not be loaded due to

```
Initial package loading: invalid access to C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\build\tmp\lsp-test\924F7085\PackageA\.build\index-build\x86_64-unknown-windows-msvc\debug\MyLibrary.build\output-file-map.json
```
2025-08-13 13:37:37 +02:00
Alex Hoppen
d887490990 Merge pull request #2231 from ahoppen/exhaustive-swift-format
Apply exhaustive swift-format configuration from swift-syntax
2025-08-11 21:02:32 +02:00
Alex Hoppen
6074529dac Manually fix swift-format lint rules
- I think there are valid calls with mixing inline and trailing closures (notably `Debouncer`), so I’m considering whether we should disable that rule.
- The `forEach` rule is a little annoying because we have `forEach` on `SKDResponseArray`. But it caught two cases of using `forEach` on arrays, so I think it’s worth keeping.
2025-08-11 09:31:09 +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