Commit Graph

821 Commits

Author SHA1 Message Date
Paul LeMarquand
310891108b Report workspace/triggerReindex server capability
Report to clients that the server supports the
`workspace/triggerReindex` request. This lets clients expose this
functionality only if SourceKit-LSP is configured to support it.
2024-07-16 13:04:01 -04:00
Alex Hoppen
f31f7b6de9 Merge pull request #1546 from plemarquand/prefix-module-name-to-test-id
[6.0] Prefix module name to test
2024-07-04 01:46:39 +02:00
Alex Hoppen
4dba9c287b Add a maximum duration for sourcekitd requests
VS Code does not cancel semantic tokens requests. If a source file gets into a state where an AST build takes very long, this can cause us to wait for the semantic tokens from sourcekitd for a few minutes, effectively blocking all other semantic functionality in that file.

To circumvent this problem (or any other problem where an editor might not be cancelling requests they are no longer interested in) add a maximum request duration for SourceKitD requests, defaulting to 2 minutes.

rdar://130948453
2024-07-02 23:06:13 +02:00
Paul LeMarquand
1abfb65a51 Prepend module name to TestItem IDs
It is possible to have two identically named suites in two different
test targets. These were being erroniously rolled up in to the same
parent TestItem.

Disambiguate these TestItems by prepending the module name. This has the
added benefit of making the TestItem IDs a fully qualified name that can
be passed to `swift test`.

The module name is pulled from the compiler arguments for the target. If
no module name can be found we fall back to the `targetID` for the
`ConfiguredTarget`.
2024-07-02 14:19:57 -04:00
Alex Hoppen
0fa7ffcee3 Allow specification of SourceKitLSPOptions in the initialize request
This allows editors to provide UI elements to toggle SourceKit-LSP options.

# Conflicts:
#	Sources/SourceKitLSP/Swift/SwiftLanguageService.swift
2024-06-28 22:55:53 +02:00
Alex Hoppen
68bff7f216 Make background indexing a proper option in SourceKitLSPOptions
This allows us to flip the default in the future more easily. It also allows users to disable background indexing when it’s enabled by default.

rdar://130280855

# Conflicts:
#	Tests/SourceKitLSPTests/BackgroundIndexingTests.swift
2024-06-28 22:36:11 +02:00
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
1a2e004838 Remove configuration options from WorkspaceFolder
This extension was added for VS Code but never used. Let’s remove it in favor of workspace-specific configuration files.

# Conflicts:
#	Sources/SourceKitLSP/SourceKitLSPServer.swift
2024-06-28 22:20:41 +02:00
Alex Hoppen
c1850998ff Merge pull request #1531 from ahoppen/6.0/diagnostics-in-secondary-files
[6.0] Handle diagnostics in secondary files correctly
2024-06-28 22:14:33 +02:00
Alex Hoppen
40ebf7ff9c Handle diagnostics in secondary files correctly
rdar://130503535
2024-06-28 06:08:44 +02:00
Alex Hoppen
0f44f033e7 Merge pull request #1526 from ahoppen/6.0/re-index
[6.0] Add a request to re-index all files in SourceKit-LSP
2024-06-27 21:50:32 +02:00
Alex Hoppen
4de0ba54c5 Translate the semantic token legend used by clangd to the semantic token legend used by SourceKit-LSP
clangd uses a completely different semantic token legend than SourceKit-LSP (it doesn’t even adhere to the ordering of the pre-defined token types) but we were passing index offsets from clangd through assuming that clangd uses the same legend, which was incorrect.

When retrieving semantic tokens from clangd, translate the semantic tokens from clangd’s legend to SourceKit-LSP’s legend.

rdar://129895062
2024-06-27 05:31:05 +02:00
Alex Hoppen
0f8b6a5d2a 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-27 05:14:58 +02:00
Alex Hoppen
2bcd14581e 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 22:29:15 +02:00
Alex Hoppen
252d5be7e3 Merge pull request #1512 from ahoppen/6.0/dont-reload-on-random-file-add
[6.0] Add test case that we don't reload the package if a `.swift` file get added in a folder that doesn't affect compilation
2024-06-26 22:28:36 +02:00
Alex Hoppen
63b0107dc4 Log path of the toolchain used to opening a document
I don’t know why we logged the toolchain’s identifier twice. That didn’t make much sense.
2024-06-26 06:35:42 +02:00
Alex Hoppen
cad2964434 Add test case that we don't reload the package if a .swift file get added in a folder that doesn't affect compilation
rdar://128573306
2024-06-24 17:59:47 -07:00
Alex Hoppen
18d1944fab Merge pull request #1506 from ahoppen/6.0/watch-package-resolved 2024-06-24 17:06:04 -07:00
Alex Hoppen
02092ee50a Merge pull request #1505 from ahoppen/6.0/work-done-progress-token-prefix 2024-06-24 17:05:01 -07:00
Alex Hoppen
5929cf93af Watch for changes to Package.resolved
We need to watch for changes to `Package.resolved` so that we can update the dependency checkouts in `.index-build` when the user runs `swift package update`.

rdar://130103181
2024-06-22 07:01:41 -07:00
Alex Hoppen
228e5782d6 Allow prefixing of the token for a WorkDoneProgress with a custom string
This allows VS Code to detect when sourcekitd has crashed and prompt the user to gather a diagnostic report + file an issue about the crash.

rdar://129678779
Fixes #1476
2024-06-22 06:57:59 -07:00
Alex Hoppen
0ebe641f6e Merge commit 'a111b4748be9fbc893abb8a6c4871bb59dabbde0' into 6.0/merge-main-2024-06-22 2024-06-22 06:50:41 -07:00
Alex Hoppen
e62473b8d6 Merge pull request #1492 from ahoppen/fix-concurrency-warnings
Fix a few Swift concurrency warnings
2024-06-20 08:59:31 -07:00
Alex Hoppen
8642768902 Fix a few Swift concurrency warnings 2024-06-18 18:07:22 -07:00
Alex Hoppen
30f1fd1997 Remove warning message about missing compiler arguments
It turns out that this message was more noise than help. For example, it would often show up when adding a new file to a SwiftPM project: The file gets added before we reload the package and thus we don’t have build settings for the new file for a short while. Since we can’t dismiss the notification we sent to the client, the notification will stick around.

Let’s just remove the message.
2024-06-18 12:26:05 -07:00
Alex Hoppen
7ef4a2d98b Merge branch 'main' into 6.0/merge-main-2024-06-17 2024-06-18 08:24:03 -07:00
Alex Hoppen
bc6751eb36 Merge branch 'main' into 6.0/merge-main-2024-06-17 2024-06-17 17:20:44 -07:00
Alex Hoppen
60d2876fbc Add workaround for rdar://116221716 2024-06-14 17:43:59 -07:00
Alex Hoppen
55ef104079 Merge pull request #1464 from ahoppen/protocol-requirement-satisfied-in-extension
Show protocol requirements satisfied in extensions in jump-to-definition
2024-06-12 14:47:02 -07:00
Alex Hoppen
2d2bac88c9 Merge pull request #1471 from ahoppen/enum-case-rename
Adjust test cases for fixed enum case rename
2024-06-12 14:46:49 -07:00
Alex Hoppen
0c42c01d44 Show protocol requirements satisfied in extensions in jump-to-definition
The key issue here was that we were looking at the symbol occurrence that had the `overrideOf` role and were using this symbol occurrence to also check that it’s a child of one of the receiver types. But if the protocol requirement is satisfied in an extension, we have an implicit symbol occurrence at the location where the protocol requirement is stated but the real declaration’s occurrence is inside the extension. The fix here is to just extract the USR from the `overrideOf` relation and then do another index lookup to find the symbol’s definition.

rdar://129412428
2024-06-12 09:30:36 -07:00
Alex Hoppen
518aac47d5 Merge pull request #1459 from ahoppen/testable-methods
Change methods that were only public for testing purposes to be `@_spi(Testing)`
2024-06-12 09:26:45 -07:00
Alex Hoppen
d96f2fb2b7 Merge pull request #1467 from ahoppen/debounce-index-progress
Debounce the creation of work done progress for indexing and package reloading
2024-06-12 09:22:38 -07:00
Alex Hoppen
c9e6348302 Merge pull request #1447 from ahoppen/atomics-not-unsafe
Change all variables that are `Atomic*` types to not be `nonisolated(unsafe)`
2024-06-12 09:12:31 -07:00
Alex Hoppen
7a61ff9c4c Adjust test cases for fixed enum case rename
Enum case rename is fixed by changes in sourcekitd. We can remove our workaround for the issue and add test cases that test the rename behavior.

Fixes #1228
rdar://127646036
2024-06-11 19:21:48 -07:00
Alex Hoppen
97ef5f46d7 Merge pull request #1460 from ahoppen/generated-interface-improvements
A couple of improvements for generated interfaces
2024-06-11 19:06:22 -07:00
Alex Hoppen
33d803f1d1 Change methods that were only public for testing purposes to be @_spi(Testing)
Fixes #876
Fixes #877
rdar://116705648
rdar://116705669
2024-06-11 19:03:26 -07:00
Alex Hoppen
91a08160b5 Merge pull request #1474 from ahoppen/logging-doc
Add a document to describe which log level to use
2024-06-11 15:24:05 -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
3fc03e9f0d Debounced the Reloading Package work done progress 2024-06-08 14:36:20 -07:00
Alex Hoppen
5bf62339cd Debounce the creation of work done progress for indexing
This avoids us from showing a work done progress for short-lived index tasks that take less than a second.

Fixes #1298
rdar://128071328
2024-06-08 14:36:06 -07:00
Alex Hoppen
202d723c77 When performing jump-to-definition on a method implementing a protocol requirement, jump to the requirement
rdar://129412482
2024-06-08 10:29:18 -07:00
Alex Hoppen
2a0f8c79b9 A couple of improvements for generated interfaces
- Rename methods to highlight that we’re talking about generated interfaces here, not `.swiftinterface` files
- Don’t open the generated interface in `documentManager`. Opening documents in `documentManager` should only be done by the `textDocument/didOpen` notification from the LSP client. Otherwise we might indefinitely keep the document in the document manager
- After getting the generated interface from sourcekitd, close the document in sourcekitd again. We don’t provide semantic functionality in the generated interface yet, so we can’t interact with the generated interface path. Before, we left it open in sourcekitd indefinitely.
- A couple of code simplifications.

Fixes #878
rdar://116705653
2024-06-08 07:56:19 -07:00
Alex Hoppen
8c62fb5cd2 Return after handling a CancelRequestNotification
We were dispatching the notification to `messageHandlingQueue`, which then didn’t do anything with it. That’s not necessary.
2024-06-07 10:19:57 -07:00
Alex Hoppen
6966a6b9c0 Merge branch 'main' into 6.0/merge-main-2024-06-07
# Conflicts:
#	Sources/SKSwiftPMWorkspace/SwiftPMBuildSystem.swift
2024-06-07 09:28:36 -07:00
Alex Hoppen
c43cffd044 Change all variables that are Atomic* types to not be nonisolated(unsafe)
Since the `Atomic*` types can not be marked as `Sendable` (because they aren’t C structs), we can change the variables to constants and can remove `nonisolated(unsafe)`.
2024-06-07 08:49:10 -07:00
Alex Hoppen
e656954f1d Merge branch 'main' into 6.0/merge-main-2024-06-06 2024-06-06 09:55:35 -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
efd7f9940c Merge pull request #1429 from ahoppen/atomics_on_heap
Heap allocate our atomics
2024-06-06 06:37:27 -07:00
Alex Hoppen
556fd333b5 Heap allocate our atomics
We used C atomics but these were allocated as Swift variables. Even thought they were atomic, concurrent accesses to them could violate Swift’s exclusivity laws, raising thread sanitizer errors.

Allocate the C atomics using malloc to fix this problem.

rdar://129170128
2024-06-05 23:27:47 -07:00