Commit Graph

92 Commits

Author SHA1 Message Date
Alex Hoppen
3e9c682cc9 Allow configuring of SourceKit-LSP’s options using .sourcekit-lsp configuration files
The idea here is to unify the different ways in which we can currently set options on SourceKit-LSP in a scalable way: Environment variables, command line arguments to `sourcekit-lsp` and initialization options.

The idea is that a user can define a `~/.sourcekit-lsp/.sourcekit-lsp` file (we store logs in `~/.sourcekit-lsp/logs` on non-Darwin platforms), which will be used as the default configuration for all SourceKit-LSP instances. They can also place a `.sourcekit-lsp` file in the root of a workspace to configure SourceKit-LSP for that project specifically, eg. setting arguments that need to be passed to `swift build` for that project and which thus also need to be set on SourceKit-LSP.

For compatibility reasons, I’m mapping the existing command line options into the new options structure for now. I hope to delete the command line arguments in the future and solely rely on `.sourcekit-lsp` configuration files.

Environment variable will be migrated to `.sourcekit-lsp` in a follow-up commit.

# Conflicts:
#	Sources/SourceKitLSP/SourceKitLSPServer+Options.swift
#	Sources/SourceKitLSP/Swift/SwiftLanguageService.swift
#	Sources/sourcekit-lsp/SourceKitLSP.swift
#	Tests/SourceKitLSPTests/BackgroundIndexingTests.swift
#	Tests/SourceKitLSPTests/ExecuteCommandTests.swift
2024-06-28 22:35:15 +02:00
Alex Hoppen
55f6dee5c8 Update links for repositories moved to the swiftlang org on GitHub 2024-06-25 06:57:00 -07:00
Alex Hoppen
7f90508e51 Add a document to describe which log level to use
Also change a few log levels and make all log messages consistently start with an uppercase letter.
2024-06-11 12:01:50 -07:00
Alex Hoppen
ce7f36e9ec Let the build system determine which toolchain to use for a document
This allows us to fix a toolchain when using a `SwiftPMBuildSystem`, which is critical to ensure that a target gets prepared using the same toolchain that is used to index it and that is used for sourcekitd.
2024-06-06 09:33:00 -07:00
Alex Hoppen
b479b2e874 Create a SwiftExtensions module
This allows us to share common Swift utility functions between SourceKit-LSP and LSPLogging.
2024-06-04 07:06:44 -07:00
Alex Hoppen
09ad77ba8d Instead of sending a message to the index log when an indexing task finishes, stream results as they come in
This also means that you can use the index log to view which tasks are currently being executed.

Since we only have a single log stream we can write to, I decided to prefix every line in the index log with two colored emojis that an easy visual association of every log line to the task that generated them.
2024-06-03 13:21:54 -07:00
Alex Hoppen
e87d9e8d5e Show message if background indexing is enabled but the workspace doesn’t support background indexing
If the user has enabled background indexing in sourcekit-lsp but opens a project that doesn’t support background indexing (compilation database, build server), we should show a message after opening the workspace, informing the user that background indexing is only supported in SwiftPM projects at the moment.

Fixes #1255
rdar://127474711
2024-05-28 14:12:19 -07:00
Alex Hoppen
f85d821839 Don’t cause any file system file effects when trying to find an implicit workspace for a file
When looking for a workspace that can handle a file, we were creating full-fledged workspaces along the way, which we would then discard if they couldn’t handle the file being opened. This had multiple problems:
1. When background indexing is enabled, it caused semantic indexing of the workspace, which wrote files to a `.index-build` directory and was a waste of work
2. When background indexing is enabled, it caused package resolution, which also created a `.index-build` folder to be created
3. It caused a syntactic test index of the workspace, which was a waste of work.

To fix this, do multiple things:
1. When creating a workspace, add a check right after build system creation. This allows us to early exit if the build system can’t handle the file and prevents us from generating the `Workspace`, fixing (1) and (3)
2. Don’t call `reloadPackage` when creating a `SwiftPMWorkspace`. Instead, explicitly call `generateBuildGraph` once we committed to creating the workspace.
2024-05-28 08:29:55 -07:00
Alex Hoppen
3e6319c3b9 Produce an index log for the client
This allows a user of SourceKit-LSP to inspect the result of background indexing. This allows a user of SourceKit-LSP to inspect the result of background indexing. I think this gives useful insights into what SourceKit-LSP is indexing and why/how it fails, if it fails, also for users of SourceKit-LSP.

rdar://127474136
Fixes #1265
2024-05-21 22:18:06 -07:00
Alex Hoppen
a850cb6849 When a file is changed, only mark targets that depend on it as out-of-date 2024-05-17 14:32:49 -07:00
Alex Hoppen
5e83d7d904 Support background preparation of targets 2024-05-10 11:58:04 -07:00
Alex Hoppen
d4dd57861c Introduce a notion of ConfiguredTargets into the build system
Instead of asking for build settings of a file, the build system manager asks for the targets of a file and then asks for the build settings of that file in a specific target. This has two advantages:
- We know about targets and can prepare the targets for background indexing
- Once we support build systems in which a single file can be part of multiple targets, we can have a centralized place that picks preferred targets for a file, eg. based on user configuration
2024-05-08 16:02:11 -07:00
Alex Hoppen
9ff1ff1430 Allow querying the build system for the language of a document
The build system has potentially  more information about a document's language than we do based on the file’s extension.
2024-05-03 14:48:15 -07:00
Alex Hoppen
5e4f1b03bf Generalize BuildSystem.testFiles to return all source files in a project 2024-05-03 14:48:15 -07:00
Alex Hoppen
7d49916faa Make BuildServerBuildSystem.buildSettings(for:language:) not throwing
No particular motivation for this change.
2024-05-03 14:48:15 -07:00
Alex Hoppen
a799da39aa Implement a syntactic workspace-wide test index
This workspace-wide syntactic test index is used for two purposes:
- It is used for XCTests instead of the semantic index for files that have on-disk or in-memory modifications to files
- It is uses for swift-testing tests, which are only discovered syntactically.

rdar://119191037
2024-04-23 09:25:31 -07:00
Alex Hoppen
7c46df3abe Remove clientID from request handling
The client ID was needed when a `MessageHandler` could handle messages from multiple connections. We don’t support this anymore (because it wasn’t needed) and so the client ID doesn’t need to get passed through as well.
2024-03-20 08:28:26 +01:00
Alex Hoppen
d76e9059bf Provide semantic functionality for packages that are subdirectories of a workspace folder
rdar://119740711
2024-02-28 09:20:30 -08:00
Alex Hoppen
757a029664 Log messages from the build server and clangd
Log messages sent to clangd and the build server in a similar way that we log requests to sourcekitd.

Fixes #886
rdar://116705677
2023-12-12 14:05:25 -08:00
Alex Hoppen
2a51479dea Remove language parameter from BuildSystem.registerForChangeNotifications
The language wasn’t used anywhere.
2023-10-30 13:57:11 -07:00
Alex Hoppen
3c83777dda Merge pull request #948 from ahoppen/ahoppen/cleanup
Two minor improvements
2023-10-30 13:54:43 -07:00
Alex Hoppen
cd57429a8b Reduce the scope of one task 2023-10-27 13:04:51 -07:00
Alex Hoppen
baa450a602 Remove Connection.sendSync
All callers should call the async version `Connection.send`.
2023-10-27 10:42:00 -07:00
Alex Hoppen
9abcd2a3a3 Remove the Notification type
`Notification` is just a wrapper around `NotificationType` and there’s no reason for it to exist anymore.

Resolves #880
rdar://116705670
2023-10-26 18:28:10 -07:00
Alex Hoppen
1458d06937 Add more fine grained dependency tracking to AsyncQueue
Instead of just having barriers and non-barriers, this allows `AsyncQueue` to track dependencies between tasks at a more fine-grained level.

For example, we can now specify that requests that affect one document only depend on edits to that same document and are not blocked by edits to any other document. As a consequence, a busy `sourcekitd` will not block requests from `clangd` to be executed and vice versa.

Resolves #875
rdar://116705652
2023-10-16 17:36:53 -07:00
Alex Hoppen
f960d7ed9b Change logging to use OSLog
OSLog is the suggesting logging solution on Apple platforms and we should be using it there, taking advantage of the different log levels and privacy masking.

Switch sourcekit-lsp to use OSLog on Apple platforms and implement a logger that is API-compatible with OSLog for all uses in sourcekit-lsp and which can be used on non-Darwin platforms.

The goal of this commit is to introduce the new logging API. There are still improvements about what we log and we can display more privacy-insensitive information after masking. Those changes will be in follow-up commits.
2023-10-13 13:46:32 -07: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
d9da113ca7 Remove BuildServerBuildSystem.requestQueue
The queue isn’t used anymore.
2023-10-06 18:07:20 -07:00
Alex Hoppen
4495256b35 Remove the queue parameter from Connection.send
We don’t actually care about the queue that we receive the reply on anymore since we migrated everything™ to actors/async/await.
2023-10-06 18:07:20 -07:00
Alex Hoppen
1f02b95e55 Shift responsibility for in-order message handling from Connection to SourceKitServer
This generally seems like the cleaner design because `SourceKitServer` is actually able to semantically inspect the message and decide whether it can be handled concurrently with other requests.
2023-10-03 07:56:49 -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
d7a454a45e Merge BuildServerBuildSystem and BuildServerHandler
They always existed in tandem and it makes migration to actors a lot easier if the handling of build server messages occurs within the same actor isolation domain as the build system iteself.
2023-09-25 16:37:03 -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
Alex Hoppen
026d3cb1d6 Remove LanguageServerEndpoint
Since we moved `BuilderServerHandler` and `ClangLanguageServerShim` to directly conform to `MessageHandler`, `SourceKitServer` was the only type inheriting from `LanguageServerEndpoint` and we can thus remove the type.
2023-09-19 17:32:54 -07:00
Alex Hoppen
ed1a9c1d85 Make BuilderServerHandler conform to MessageHandler directly 2023-09-19 17:32:54 -07:00
Max Desiatov
f5a30d9351 Fix uses of deprecated non-throwing AbsolutePath.init (#709)
These warnings appeared after an update to TSC deprecated this initializer.
2023-02-09 14:04:57 +00:00
Ruslan Latypov
c94c48415d fix scripts extension comparison to include dot 2022-10-24 14:41:58 +01:00
Ruslan Latypov
8ba893118c SKCore: allow non python build servers 2022-10-21 17:43:48 +01:00
Boris Buegling
43c072dc84 Adopt to path API changes
We are moving to a better model for TSC's path APIs in apple/swift-tools-support-core#353. The previous API is still available (but deprecated) as much as possible, but since SourceKit-LSP was using `resolveSymlinks` (which is now throwing) quite a bit, there are some changes necessary.
2022-10-18 15:28:54 -07: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
Saleem Abdulrasool
79105208d5 SKCore,SKTestSupport: adjust test server handling
The test system depended on the shebang to locate the python
interpreter.  However, this is not a portable system.  Instead, prefer
to explicitly search for the interpreter prior to the execution.  This
enables supporting execution of the script support on all platforms. A
secondary change of the printed string is required for Windows. Python
will replace `\n` with `\r\n` resulting in `\r\n` being emitted as
`\r\r\n` on Windows breaking the expectations on the receiver.  Adjust
this by explicitly writing out a binary string to the raw underlying
buffer to avoid the translation.
2022-09-06 09:19:37 -07:00