Commit Graph

778 Commits

Author SHA1 Message Date
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
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
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
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
Alex Hoppen
1286407762 Remove sourcekitd test hooks
Turns out that sourcekitd test hooks were a bad idea because of the following comment that I wrote:

```
`testHooks` are only considered when an instance is being created. If a sourcekitd instance at the given path already exists, its test hooks will be used.
```

During test execution in Xcode, we generate a bunch of `SourceKitServer` instances in the same process that all call `DynamicallyLoadedSourceKitD.getOrCreate`. Now, if `testDontReturnEmptyDiagnosticsIfDiagnosticRequestIsCancelled` is not the first test being executed in the process (which usually it is not), the test hooks in it won’t get used.

Switch back to using the preparation hooks, essentially reverting https://github.com/apple/sourcekit-lsp/pull/1412 and keeping the following snippet to fix the underlying issue

```swift
// Poll until the `CancelRequestNotification` has been propagated to the request handling.
for _ in 0..<Int(defaultTimeout * 100) {
  if Task.isCancelled {
    break
  }
  usleep(10_000)
}
```
2024-06-05 14:24:09 -07:00
Alex Hoppen
98eeea7039 Merge pull request #1211 from plemarquand/fix-backticks-in-test-ids
Filter backticks in TestItem IDs
2024-06-04 15:49:04 -07:00
Alex Hoppen
0f553067c4 Merge pull request #1421 from ahoppen/track-recently-finished-requests
Keep track of recently finished requests
2024-06-04 15:17:41 -07:00
Alex Hoppen
e73768b9b0 Merge pull request #1417 from ahoppen/one-with-lock
Unify `withLock` implementations
2024-06-04 15:17:33 -07:00
Alex Hoppen
5ac5b5685e Merge pull request #1412 from ahoppen/wait-for-prepration-to-propagate
Wait for cancellation to propagate in `testDontReturnEmptyDiagnosticsIfDiagnosticRequestIsCancelled`
2024-06-04 15:12:40 -07:00
Alex Hoppen
37e6a8a65a Wait for cancellation to propagate in testDontReturnEmptyDiagnosticsIfDiagnosticRequestIsCancelled
I saw a few non-deterministic test failures. I think the issue was that handling of the `CancelRequestNotification` is done asynchronously, which left a short window in which the sourcekitd diagnostics request could run and return results instead of being cancelled. Wait for the diagnostic request to actually be cancelled before running it for real.

While doing this, also introduce proper sourcekitd test hooks instead of relying on the preparation test hooks, which just got run as a side effect.
2024-06-04 11:34:11 -07:00
Alex Hoppen
3e11cd6bc8 Unify withLock implementations
Turns out that also most of the `withLock` definitions were never used.
2024-06-04 11:26:47 -07:00
Alex Hoppen
9c13dbbe24 Merge pull request #1420 from ahoppen/reduce-some-logging
Demote two log messages issued on the `error` level
2024-06-04 11:21:33 -07:00
Alex Hoppen
922d94b366 Merge pull request #1410 from ahoppen/swift-utilities
Create a `SwiftUtilities` module
2024-06-04 09:53:48 -07:00
Alex Hoppen
ece8634be5 Keep track of recently finished requests
This is only used so we don't log an error when receiving a `CancelRequestNotification` for a request that has just returned a response.
2024-06-04 07:58:16 -07:00
Alex Hoppen
560d3e9daa Merge pull request #1414 from ahoppen/no-cancel-if-removing-diag-from-cache
Don’t cancel in-progress diagnostic generation when calling `DiagnosticReportManager.removeItemsFromCache`
2024-06-04 07:24:16 -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
32852afd1f Demote two log messages issued on the error level
Just two cases where we were logging an error that wasn’t strictly necessary and was just spamming the log at the high log levels.
2024-06-03 23:15:38 -07:00
Alex Hoppen
e4d8331d15 Merge pull request #1404 from ahoppen/cpp-to-swift-rename-tests
Add tests to rename C++ symbols exposed to Swift
2024-06-03 21:20:10 -07:00
Alex Hoppen
fff9eb569e Merge pull request #1382 from ahoppen/stream-index-log
Instead of sending a message to the index log when an indexing task finishes, stream results as they come in
2024-06-03 19:33:29 -07:00
Alex Hoppen
5b119b705f Add tests to rename C++ symbols exposed to Swift
This exposes an issue where we wouldn’t rename a symbol on the clang side f a symbol was only defined in a header and not a C/C++/... file. In that case we failed to determine the language of the header file because there was no unit file that contained the header file. The cleaner solution here is to ask for the symbol provider of each occurrence directly.

rdar://127391127
2024-06-03 17:58:21 -07:00
Alex Hoppen
d04bf84893 Don’t cancel in-progress diagnostic generation when calling DiagnosticReportManager.removeItemsFromCache
This was causing a non-deterministic test failure: When target preparation finishes while a diagnostic request is in progress, it will re-open the document, which calls `DiagnosticReportManager.removeItemsFromCache` for that document’s URI. With the old implementation, we would thus cancel the diagnostics sourcekitd request and return a cancelled error to the diagnostics LSP request.

While doing this, I also realized that there was a race condition: Document re-opening would happen outside of the SourceKit-LSP message handling queue and could thus run concurrently to any other request. This means that a sourcekitd request could run after `reopenDocument` had closed the document but before it was opened again. Introduce an internal reopen request that can be handled on the main message handling queue and thus doesn’t have this problem
2024-06-03 17:51:23 -07:00
Alex Hoppen
f98da773a9 Make passing --experimental-prepare-for-indexing to swift build an experimental feature
I’d like to qualify `--experimental-prepare-for-indexing` independently of background indexing using `swift build`. Because of this, I think there is value in using SourceKit-LSP using background indexing but without `--experimental-prepare-for-indexing`. It could also be useful to determine if bugs we may find are due to `--experimental-prepare-for-indexing` or also occur when running plain `swift build` commands.
2024-06-03 15:22:00 -07:00
Alex Hoppen
f203b3a527 Merge pull request #1395 from ahoppen/uri-everywhere
Use `DocumentURI` instead of `URL` in more locations
2024-06-03 14:05:00 -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
Paul LeMarquand
c79f7dc9a7 Fix lint error 2024-06-03 15:35:45 -04:00
Alex Hoppen
1438c79c96 Merge pull request #1408 from ahoppen/deinit-symbol-kind
Classify deinitializers as constructors in document symbols
2024-06-03 12:06:14 -07:00
Alex Hoppen
1ce51ebdc1 A few miscellaneous changes 2024-06-03 11:26:20 -07:00
Alex Hoppen
c03d80d037 Migrate Rename.swift to use DocumentURI instead of URL 2024-06-03 11:26:20 -07:00
Alex Hoppen
3c5d8b9119 Change SwiftPMBuildSystem to use DocumentURI instead of URL 2024-06-03 11:26:19 -07:00
Alex Hoppen
b60acde260 Merge pull request #1406 from ahoppen/cancellation-logging-scope
Set the logging scope for notification handling one level higher so it’s also set for cancel notifications
2024-06-03 11:12:27 -07:00
Alex Hoppen
c639d2b25a Classify deinitializers as constructors in document symbols
LSP doesn't have a destructor kind. constructor is the closest match and also what clangd for destructors.
2024-06-03 09:18:04 -07:00
Paul LeMarquand
7734133cd1 Filter backticks in TestItem IDs
Backticks in TestItem IDs should be sanitized. Use the new
TokenSyntax.identifier when building up the TestItem IDs.
2024-06-03 11:40:42 -04:00