Commit Graph

54 Commits

Author SHA1 Message Date
Alex Hoppen
aa0aa927ca Stop using TSCBasic.resolveSymlinks and URL.resolvingSymlinksInPath 2024-10-09 13:16:57 -07:00
Alex Hoppen
36478d87ed Allow build systems to specify the files to watch for changes
rdar://136014553
Resolves #1671
2024-09-30 10:33:32 -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
d8b41d4eff Merge pull request #1685 from ahoppen/only-scan-test-targets
Only scan test targets for tests
2024-09-19 20:41:40 -07:00
Alex Hoppen
120bd8688b Only scan test targets for tests
Don’t run the syntactic test scanner on files that we know are only part of non-test targets.

rdar://126493903
2024-09-19 13:42:40 -07:00
Alex Hoppen
40cc4c60c6 Adjustments because traverseModules no longer returns depth
We no longer need `depth`. Adopt a faster version of `traverseModules` that doesn’t return the depth.

rdar://136107035
2024-09-19 13:40:45 -07:00
Alex Hoppen
14765bbca8 Fix an issue that caused us to not get compiler arguments when opening a SwiftPM package at a symlink
When you had a package at `/pkg_real` and a symlink `/pkg` pointing to `/pkg_real`, then opened a workspace at `/pkg`, we wouldn’t get any build settings for any of the files. This was masked in tests because they still called `SwiftPMBuildSystem.targets(for:)`, which handled symlink resolution but wasn’t called in production.

Handle symlink resolution `BuildSystemManager`, remove `SwiftPMBuildSystem.targets(for:)` and its related members/methods, and migrate the tests to go through `BuildSystemManager`, which is what production code does. A nice side effect of this is that the tests will log the requests sent to the build system.
2024-09-18 17:41:36 -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
e15bdd7e90 Review SwiftPMBuildSystem.swift 2024-09-16 10:13:20 -07:00
Alex Hoppen
0bdbb507c9 Review CompilationDatabaseBuildSystem 2024-09-16 10:12:58 -07:00
Alex Hoppen
3a78b650c1 Share logic to infer language from file extension between BuildSystemManager and FileBuildSettings.patching 2024-09-16 10:10:26 -07:00
Alex Hoppen
85b2f1fd30 Review BuildServerProtocol module for consistency 2024-09-16 10:10:26 -07:00
Alex Hoppen
5870ad9eb4 Implement InverseSourcesRequest in BuildSystemManager
`buildTarget/inverseSources` is not required to be implemented by BSP servers and we have almost all information needed for it in `BuildSystemManager`.

This also makes sure that `buildTarget/sources` and `buildTarget/inverseSources` actually match each other. Before this change, we had source files like `Package.swift` for which we returned a target from `buildTarget/inverseSources` but that weren’t part of that target’s sources retrieved using `buildTarget/sources`.
2024-09-16 10:08:14 -07:00
Alex Hoppen
70288465dc Log target name instead of the target's URI 2024-09-16 10:07:31 -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
6cc2cc4e95 Implement reloadPackageStatusCallback using BSP messages 2024-09-15 16:28:12 -07:00
Alex Hoppen
66f24e3554 Introduce buildSystemTestHooks 2024-09-15 16:28:12 -07:00
Alex Hoppen
a96c0913ad Implement addSourceFilesDidChangeCallback in BuildSystemManager 2024-09-13 11:12:40 -07:00
Alex Hoppen
fac21f5976 Implement waitForUpToDateBuildGraph using BSP 2024-09-13 11:12:40 -07:00
Alex Hoppen
12923b6d73 Implement toolchain(for:) using BSP 2024-09-13 11:12:40 -07:00
Alex Hoppen
cc11fe1b02 Implement topologicalSort inside BuildSystemManager using dependency information 2024-09-12 17:26:41 -07:00
Alex Hoppen
bb96ff4c68 Migrate targets(dependingOn:) to BSP 2024-09-12 16:59:03 -07:00
Alex Hoppen
897cd5e775 Implicitly trigger build graph generation when creating a SwiftPMBuildSystem 2024-09-12 16:24:48 -07:00
Alex Hoppen
022a6de6c3 Handle filesDependenciesUpdated in BuildSystemManager instead of the build system
The implementation of which file’s dependencies have been updated is common across all build systems and thus build systems shouldn’t need to implement this logic. This also allows us to remove `BuildSystemDelegate`.
2024-09-12 07:34:12 -07:00
Alex Hoppen
9d94fe36a9 Migrate defaultLanguage(for:) to BSP 2024-09-12 07:34:12 -07:00
Alex Hoppen
c5ba9671f0 Migrate getting the list of all source files to BSP 2024-09-11 13:42:01 -07:00
Alex Hoppen
3a118980b4 Migrate BuildSystem.prepare to a BSP request 2024-09-11 09:48:50 -07:00
Alex Hoppen
7e3f453a7c Remove registerForChangeNotifications
This was only really used for the legacy BSP integration, which we are phasing out in favor of the new `SourceKitOptions` request.
2024-09-11 08:40:12 -07:00
Alex Hoppen
236f566977 Instead of having FileHandlingCapability for a source file, check if it belongs to any targets 2024-09-11 08:27:12 -07:00
Alex Hoppen
f9e468ffba Use BSP requests to get build settings of a source file 2024-09-10 09:30:36 -07:00
Alex Hoppen
ea21175dd7 Create BuildSystem in BuiltInBuildSystemAdapter
This finalizes the move of `BuiltInBuildSystem` creation into `BuiltInBuildSystemAdapter` and means that we can set the message handler of the `BuiltInBuildSystem` during initialization instead of using a setter method.
2024-09-09 18:00:05 -07:00
Alex Hoppen
6a9dcd2349 Split determining which build system to use for a workspace and the workspace creation
This allows us to create the build system from a `BuiltInBuildSystemAdapter` when it receives an `InitializeRequest`, which will be done in a follow-up commit.
2024-09-09 17:42:15 -07:00
Alex Hoppen
b490a6fef1 Use buildTarget/inverseSources from BSP to get targets of a source file 2024-09-09 16:31:30 -07:00
Alex Hoppen
63c5ca4a2c Use BuildTargetIdentifier from BSP instead of ConfiguredTarget 2024-09-09 16:31:00 -07:00
Alex Hoppen
e38d37e01c Use workspace/didChangeWatchedFiles from BSP to communicate file changes to the build system 2024-09-09 16:31:00 -07:00
Alex Hoppen
b4d04ce983 Introduce a BuiltInBuildSystemAdapter that can be used to transition BuildSystem to a type that implements BSP 2024-09-09 16:31:00 -07:00
Alex Hoppen
fd0573e4b8 Rename BuildSystem to BuiltInBuildSystem 2024-09-09 16:30:13 -07:00
Alex Hoppen
4d1fa7a7ee Fix a race condition that could cause the build graph to not be generated when doing initial background indexing
We were making the initial `generateBuildGraph` call in `SourceKitLSPServer` from a `Task`. This means that `generateBuildGraph` could be executed after `waitForUpToDateBuildGraph` was called by `SemanticIndexManager`. Thus `waitForUpToDateBuildGraph` returned immediately and no files were background indexed.

Make `generateBuildGraph` immediately schedule a package reload for SwiftPM build systems instead of doing the hop through a `Task`, fixing the race condition.

rdar://135551812
2024-09-09 11:50:18 -07:00
Alex Hoppen
33e955ab6c Merge pull request #1632 from ahoppen/lazy-workspace-loading
Don’t block the generation of a build system by build graph generation
2024-09-07 02:27:19 -07:00
Alex Hoppen
6e0281f79a Don’t block the generation of a build system by build graph generation
We currently load the entire package before generating a `SwiftPMBuildSystem`. That means that the initialize request to SourceKit-LSP is blocked until the package has been loaded, preventing us from offering any sort of functionality, including syntactic functionality like formatting.

Decouple build system creation and build graph generation (aka. package loading for SwiftPM). We can operate with fallback build settings until the build graph has been loaded and reopen the document once the proper build settings are available.

rdar://126644596
2024-09-06 22:51:53 -07:00
Alex Hoppen
d86a32bc19 Remove custom decoding function from SourceKitLSPOptions
We forgot to decode the following keys in the custom decode function, which meant that you couldn’t set them using SourceKit-LSP’s `config.json` file.
- `backgroundPreparationMode`
- `sourcekitdRequestTimeout`
- `cancelTextDocumentRequestsOnEditAndClose`

We had the custom decoder function so that the keys weren’t required in the JSON but we could access eg. `SwiftPMOptions` without needing to deal with optionals in the codebase.

Make the accesses to these nested options structs a little more verbose but eliminate the source of the above bug, which seems like a good tradeoff.
2024-09-06 13:45:24 -07:00
Kabir Oberai
821663c6fd Use SwiftPM's SDK computation logic (#1643)
Using `SwiftSDK.deriveTargetSwiftSDK`, which is the same method that SwiftPM's own CLI tools use to determine the SDK from passed-in info (target `--triple`, `--swift-sdk`, and host sdk). This allows us to better uphold the contract in the [Configuration File](d11c101ce2/Documentation/Configuration%20File.md (structure)) docs, namely that the `swiftSDK` param is "Equivalent to SwiftPM's `--swift-sdk` option" and similarly for `triple`.

As concrete examples of where (AFAICT) the current implementation diverges:
- Passing a `--triple` of `wasm32-unknown-wasi` to `swift-build` will use the toolchain-integrated Wasm SDK if one exists. Passing the same value to sourcekit-lsp does not do this.
- Perhaps more relevant: after landing https://github.com/swiftlang/swift-package-manager/pull/6828, this change will make it so that building for iOS is as simple as setting `"triple": "arm64-apple-ios"` in the config! Currently, it's necessary to set C/Swift flags and hardcode the sysroot. Should close https://github.com/swiftlang/sourcekit-lsp/issues/1587.

This PR depends on:

- https://github.com/swiftlang/swift-package-manager/pull/7925
2024-08-29 09:15:26 -07:00
Alex Hoppen
189f32ae04 Remove workarounds that are no longer needed 2024-08-17 07:52:55 -07:00
Pavel Yaskevich
2bb86c55c5 [SwiftPM] Switch from BuildTriple to BuildDestination
`BuildTriple` is going away to it's as good time as any to introduce a new type to be used by SourceKit-LSP.

Paired with https://github.com/swiftlang/swift-package-manager/pull/7884
2024-08-15 13:47:07 -07:00
Alex Hoppen
430fdef818 Use BuildDescription.traverseModules to get the target targets of a SwiftPM package 2024-08-08 16:55:02 -07:00
Alex Hoppen
e43740a5d0 Re-arrange members in SwiftPMBuildSystem by groups 2024-08-08 12:52:20 -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
Alexis Laferrière
ae152de1bc Merge pull request #1609 from AndrewHoos/asyncGraphLoading
Adopt new async (but not yet swift 6) methods from SwiftPM
2024-08-05 17:05:20 -07:00
Alex Hoppen
c31122b255 Merge pull request #1570 from ahoppen/remove-indexpathmappings
Remove `indexPrefixMappings` from `BuildSystem`
2024-08-05 10:41:05 -07:00