Commit Graph

47 Commits

Author SHA1 Message Date
Alex Hoppen
7e7df04b48 Make the SourceKitLSP module build in Swift 6 mode
Swift 6 mode didn’t find any notable data races. But it’s good to know Swift 6 will prevent future ones.
2024-05-13 21:28:42 -07:00
Alex Hoppen
70e373c1fa Make all non-test modules except for SourceKitLSP build in Swift 6 mode
This would have caught a race condition in background indexing that was caused by accessing `CheckedIndex` from multiple threads despite it not being thread-safe.
2024-05-13 10:05:25 -07:00
Alex Hoppen
42140c57b0 Make SKCore build with strict concurrency 2024-03-20 11:48:50 +01:00
joehsieh
98ba3ee7d8 Remove isFallback from func buildSettings for FallbackBuildSystem 2023-10-20 10:04:18 +09:00
Alex Hoppen
d0fc00ce98 Format using swift-format
Add `.swift-format` to the repo and format the repo with `swift-format`.

This commit does not add any automation to enforce formatting of sourcekit-lsp in CI. The goal of this commit is to get the majority of source changes out of the way so that the diff of actually enforcing formatting will have fewer changes or conflicts.
2023-10-10 13:44:47 -07:00
Alex Hoppen
453ebfb2b3 Make FallbackBuildSystem not conform to BuildSystem and remove no-op functions from it 2023-10-03 08:02:56 -07:00
Alex Hoppen
c642b37a96 Remove tracking of file build settings status in SourceKitServer and BuildSystemManager
The core idea here is that the toolchain language servers always call into `BuildSystemManager` and `BuildSystemManager` will always reply with build settings. If it hasn’t computed them yet, it will reply with fallback settings.

With that assumption, we can remove the `documentToPendingQueue` from `SourceKitServer` since there are no longer any documents that are pending – everything has a build settings immediately.

Similarly, `BuildSystemManager.mainFileStatuses` also isn’t needed anymore.

And lastly, since we know that `BuildSystemManager.buildSettings` will always return a value `registerForChangeNotifications` is changed not call `fileBuildSettingsChanged` immediately. Instead, it will only cause `fileBuildSettingsChanged` to be called when the file’s build settings change after the `registerForChangeNotifications` call.
2023-10-02 09:53:25 -07:00
Alex Hoppen
dffcc939f7 Change the build system to only notify delegate about changed files, not about new build settings
This defines away an entire class of data races if delegate callbacks are delivered out-of-order. If we aren’t providing the new build settings in the delegate callback, then it doesn’t matter if two `fileBuildSettingsChanged` calls change order since they don’t carry any state.
2023-10-02 09:53:25 -07:00
Alex Hoppen
5335acaae7 Migrate BuildServerBuildSystem to an actor and make methods in BuildSystemDelegate async
This concludes the migration of the build systems to async.
2023-10-02 09:47:33 -07:00
Alex Hoppen
54e6d958d6 Make all methods on BuildSystem async
This is the prerequisite for making the build systems actors.
2023-10-02 09:47:21 -07:00
Alex Hoppen
f1548bd757 Call into the BuildSystemManager from SwiftLanguageServer to get build settings
Instead of storing build settings inside the language servers based on update notifications from the build system, always call into the `BuildSystemManager` to get the build settings.

Overall, I think this is a much clearer separation of concerns and will allow us to remove `SourceKitServer.documentToPendingQueue` in a follow-up commit as `SwiftLanguageServer` can always directly call into `BuildSystemManager` to get build settings and we don’t need to wait for the initial notification to receive the first build settings.

This requies `BuildServerBuildSystem` to keep track of the build settings it has received from the BSP server.

`ClangLanguageServer` still caches build settings locally. `ClangLanguageServer` will change to the same pull-based model in a follow-up commit.
2023-10-02 09:44:01 -07:00
Alex Hoppen
b22af35eb1 Revert asyncificaiton changes
The asyncification changes caused some non-deterministic test failures. I believe that some of these are due to race conditions that are the result of the partial transition to actors.

Instead of merging the asyncification piece by piece, I will collect the changes asyncification changes in a branch and then qualify that branch througougly (running CI multiple times) before merging it into `main`.
2023-09-30 10:09:59 -07:00
Alex Hoppen
32af558a6e Migrate BuildServerBuildSystem to an actor and make methods in BuildSystemDelegate async
This concludes the migration of the build systems to async.
2023-09-29 16:56:00 -07:00
Alex Hoppen
e663bbcf8a Make all methods on BuildSystem async
This is the prerequisite for making the build systems actors.
2023-09-29 16:55:51 -07:00
Alex Hoppen
23b2db0588 Call into the BuildSystemManager from SwiftLanguageServer to get build settings
Instead of storing build settings inside the language servers based on update notifications from the build system, always call into the `BuildSystemManager` to get the build settings.

Overall, I think this is a much clearer separation of concerns and will allow us to remove `SourceKitServer.documentToPendingQueue` in a follow-up commit as `SwiftLanguageServer` can always directly call into `BuildSystemManager` to get build settings and we don’t need to wait for the initial notification to receive the first build settings.

This requies `BuildServerBuildSystem` to keep track of the build settings it has received from the BSP server.

`ClangLanguageServer` still caches build settings locally. `ClangLanguageServer` will change to the same pull-based model in a follow-up commit.
2023-09-28 22:37:57 -07:00
Ben Barham
15bdcc42e1 Revert "Call into the BuildSystemManager from SwiftLanguageServer to get build settings"
This reverts commit 9dd38798bb.
2023-09-28 15:51:07 -07:00
Alex Hoppen
9dd38798bb Call into the BuildSystemManager from SwiftLanguageServer to get build settings
Instead of storing build settings inside the language servers based on update notifications from the build system, always call into the `BuildSystemManager` to get the build settings.

Overall, I think this is a much clearer separation of concerns and will allow us to remove `SourceKitServer.documentToPendingQueue` in a follow-up commit as `SwiftLanguageServer` can always directly call into `BuildSystemManager` to get build settings and we don’t need to wait for the initial notification to receive the first build settings.

This requies `BuildServerBuildSystem` to keep track of the build settings it has received from the BSP server.

`ClangLanguageServer` still caches build settings locally. `ClangLanguageServer` will change to the same pull-based model in a follow-up commit.
2023-09-27 16:20:53 -07:00
Alex Hoppen
20e3fa368b Remove unused target-related functions in BuildSystem
None of these target-related functions was actually called or implemented properly in any build system.
2023-09-25 16:37:03 -07:00
Max Desiatov
effcb1c20a Move Platform to SwiftPM (#704) 2023-02-07 09:48:26 +00:00
Saleem Abdulrasool
4bbd74f105 SourceKit: sever dependency on TSCUtility
The dependency on `TSCUtility` was strictly for identifying the platform
of execution. This logic is relatively self-contained and effectively an
extension over an enumeration. Replicate this logic with updates for new
syntactic improvements. This allows us to partially reduce dependency on
swift-tools-support-core. The dependency on TSCBasic is more complicated
to remove due to the extensive use of `AbsolutePath`.

Co-authored-by: Alex Hoppen <alex@alexhoppen.de>
2023-01-02 12:30:28 -08:00
Saleem Abdulrasool
7d1bcee1b0 explicitly import TSCBasic types
Explicitly import interfaces from TSCBasic which now allows us to
identify all the swift-tools-support-core interfaces which are in
use in SourceKit-LSP.
2022-09-10 12:53:30 -07:00
Alex Hoppen
711c22544f Pass manual build arguments that specified using -Xswiftc when starting sourcekit-lsp, to the fallback build system
Previously, we weren’t respecting these arguments in the fallback build system.

rdar://97044457
2022-07-20 00:51:27 +02:00
David Goldman
472a06c88a Support index store path remappings (#562)
This allows sourcekit-lsp to make use of the path remappings recently added to
the index store and IndexStoreDB to remap remote paths into local paths
when loading index data locally.

These remappings can be provided via the `-index-prefix-map` command line flag to sourcekit-lsp or via the `BuildSystem` integration point.
2022-06-09 10:45:52 -04:00
Alex Hoppen
d02d3914c5 Query build system of workspaces to determine best workspace to open a file in
This sets the stage for multi-workspace support. Everything should be handled internally, we are just missing the API to actually open multiple workspaces at this point.
2022-05-04 14:48:31 +02:00
Ben Langmuir
3927e639be Revert "Support opening multiple workspaces in a single sourcekit-lsp instance" 2022-05-03 13:47:19 -07:00
Alex Hoppen
f91564a75f Query build system of workspaces to determine best workspace to open a file in
This sets the stage for multi-workspace support. Everything should be handled internally, we are just missing the API to actually open multiple workspaces at this point.
2022-05-02 09:31:07 +02:00
Alex Hoppen
9a5b1e81ef Reload Swift Package when new file creation is indicated by DidChangeWatchedFileNotification
Implement rudementary support for `DidChangeWatchedFileNotification` for SwiftPM projects: When a file is added, reload the Swift package to compute build settings for it.

This enables proper semantic functionality added to the project after the LSP server was started.

Resolves SR-15633
2022-01-19 11:20:10 +01:00
David Goldman
cf19900d84 Swap BuildSystem to remove build settings method (#183)
Remove `settings(for:)` from the BuildSystem API in favor of the change callback

- With the `settings(for:)` method removed, we instead block on a
  callback from the `BuildSystemManager` which itself handles
  the primary build system callback in conjunction with the fallback
  system

- We queue up notifications / requests that reference documents
  until we receive the callback.

- Remove language from FileBuildSettings as it is no longer needed,
  Swift-specific working dir fixes are now in SwiftCompileCommand

- registerForChangeNotifications should inform its delegate
  asynchronously instead of immediately
2020-06-01 13:20:15 -04:00
Ben Langmuir
a679d4553d [buildsystem] Standardize call between register and settings query NFC
In preparation for injecting doing more during registration, pass
through the same parameters (add language) so that we can call settings
as necessary.
2020-02-05 21:53:52 -08:00
Ben Langmuir
47d92d89f9 Remove unused toolchain lookup function NFC
We want to be able to lookup the toolchain by file eventually, but it's
currently dead code.
2020-02-05 21:53:52 -08:00
Ben Langmuir
cffced1844 Thread Language through FileBuildSettings NFC
Will make it easier to work with cached settings.
2020-02-05 21:53:52 -08:00
Alex Hoppen
aefa1688e4 Add support for semantic functionality for non-URL files in FallbackBuildSystem
In the fallback build system use the URIs pseudo path to construct
compiler arguments. For non-file URIs this means passing the raw URI as
the filename. We were already testing non-existing file-URLs like /a.txt
and arbitrary URIs seem to allow semantic functionality as well.
2019-11-20 09:41:48 -08:00
Alex Hoppen
5c839f8640 Add support for non-URL URIs
According to the LSP specification, arbitrary URIs can be used as
document identifiers. Instead of internally assuming that all URIs are
URLs, use a DocumentURI enum to represent URIs. These can either be file
URLs or other URIs whose value as treated as an opaque string.
2019-11-20 09:41:48 -08:00
Richard Howell
26d3fca5dd use LSPResult instead of optionals 2019-10-04 15:14:04 -07:00
Richard Howell
0f6f260701 add interface for fetching output paths 2019-10-04 14:51:26 -07:00
Richard Howell
315070d6f7 add inteface to fetch build target sources 2019-10-04 14:50:46 -07:00
Richard Howell
e3fce37388 use LSPResult instead of optional 2019-10-01 14:33:06 -07:00
Richard Howell
ab1ee4ea8c return empty reply instead of ignoring targets request 2019-09-25 14:27:44 -07:00
Richard Howell
81c50db7e1 add the workspace/buildTargets request 2019-09-25 14:16:30 -07:00
David Goldman
e5caf44fda Add a BuildSystemDelegate which supports notifications for build settings changes
Introduce a `BuildSystemDelegate` to handle notifications from the build system

* `SourceKitServer` is the main delegate to process these notifications
* Currently limited to changes in `FileBuildSettings`
* Delegate informs the `BuildSystem` of files to watch via `registerChangeWatching(for: URL)` and `unregisterChangeWatching(for: URL)`
* In the future we could have more integration for handling changes in dependencies

Handling changes in `FileBuildSettings`

* `SourceKitServer` sends notifications to the internal LSPs informing them of any opened documents that have changes in their compiler flags
    * For clangd, we send a notification to update the compilation database
    * For SourceKit/sourcekitd we must close and reopen the file to force a new AST with the new compiler flags
2019-09-06 17:44:36 -04:00
Ben Langmuir
e1fa70d086 Update SPM -> TSC module name prefixes 2019-09-03 08:29:19 -07:00
Richard Howell
1f57193cf4 add toolchain interface to BuildServer 2019-08-15 11:04:54 -07:00
Richard Howell
f6045fcfdc remove toolchain from FileBuildSettings 2019-08-15 10:53:14 -07:00
Ben Langmuir
b92abf4140 Remove testable imports of SKCore 2019-08-08 21:33:02 -07:00
Ben Langmuir
77351820ce Use AbsolutePath.pathString instead of description
Per review feedback; pathString is semantically the string we want,
while description is for creating a human-readable string.
2019-02-01 18:05:11 -08:00
Ben Langmuir
7f697fa14a [swiftpm] Update to latest master
* import Utility -> import SPMUtility
* AbsolutePath.asString -> path.description or "\(path)"
2019-02-01 16:47:04 -08:00
Ben Langmuir
802a416c17 [build-system] Rename FallbackBuildSettingsProvider -> FallbackBuildSystem 2018-12-03 23:02:20 -08:00