Commit Graph

107 Commits

Author SHA1 Message Date
Alex Hoppen
bfaee492ba Minor improvements to DLHandle.Handle 2024-11-20 12:49:32 -08:00
Alex Hoppen
be546308ca Use URL in many cases where we used AbsolutePath
We made quite a few fixes recently to make sure that path handling works correctly using `URL` on Windows. Use `URL` in most places to have a single type that represents file paths instead of sometimes using `AbsolutePath`.

While doing so, also remove usages of `TSCBasic.FileSystem` an `InMemoryFileSystem`. The pattern of using `InMemoryFileSystem` for tests was never consistently used and it was a little confusing that some types took a `FileSystem` parameter while other always assumed to work on the local file system.
2024-11-18 18:19:48 -08:00
Alex Hoppen
947e5269c4 Reduce the number of public imports 2024-09-30 07:50:12 -07:00
Alex Hoppen
8cd831b55d Adopt InternalImportsByDefault 2024-09-27 09:17:13 -07:00
Alex Hoppen
57e933da97 Move Atomics from SKSupport to SwiftExtensions 2024-09-15 16:28:09 -07:00
Alex Hoppen
0bb605d641 Remove a few workarounds that should no longer be needed 2024-08-07 10:00:04 -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
Alex Hoppen
ea9bf37634 Make SourceKit-LSP build without warnings
Fixes all build warnings in SourceKit-LSP so that it builds without any issues using recent Swift development snapshots (`swift-DEVELOPMENT-SNAPSHOT-2024-07-22-a` and `swift-6.0-DEVELOPMENT-SNAPSHOT-2024-07-24-a`)
2024-07-25 15:45:22 -07:00
Alex Hoppen
8c34a76f59 Rename LSPLogging to SKLogging 2024-07-25 09:11:13 -07:00
Alex Hoppen
87f8b94c26 Build SourceKit-LSP in the Swift 6 language mode
rdar://126553799
2024-07-24 06:12:56 -07:00
Alex Hoppen
8e3bb6bd2f Merge pull request #1573 from ahoppen/package-access-level 2024-07-20 21:55:38 -07:00
Alex Hoppen
2877675bd5 Adopt package access level
Change a l public declarations to the `package` access level, accept for:
- The `LanguageServerProtocol` module
- The `BuildServerProtocol` module
- `InProcessClient.InProcessSourceKitLSPClient`
- `LanguageServerProtocolJSONRPC` (I would like to create a more ergonomic API for this like `InProcessSourceKitLSPClient` in the future, but for now, we’ll leave it public)

Unfortunately, our pattern of marking functions as `@_spi(Testing) public` no longer works with the `package` access level because declarations at the `package` access level cannot be marked as SPI. I have decided to just mark these functions as `package`. Alternatives would be:
- Add an underscore to these functions, like we did for functions exposed for testing before the introduction of `SPI`
- Use `@testable` import in the test targets and mark the methods as `internal`

Resolves #1315
rdar://128295618
2024-07-19 09:54:30 -07:00
Alex Hoppen
edf19dbbd8 Import Darwin in files that use free
rdar://131965190
2024-07-18 11:30:23 -07:00
Finagolfin
1cf6c76897 Import new Bionic module from Android overlay instead where possible 2024-07-08 19:08:07 +05:30
Finagolfin
7c20015331 Import new Android overlay 2024-07-04 02:20:23 +05:30
Alex Hoppen
191d366a2c 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 22:47:27 +02:00
Alex Hoppen
9618df80a0 Add documentation about each module's purpose and move some files between modules
The purpose of the different modules wasn’t clearly defined, which lead to inconsistent responsibilities between the different modules. Define each module’s purpose and move a few files between modules to satisfy these definitions.

There are a few more larger changes that will need to be made for a fully consistent module structure. These are FIXMEs in the new Modules.md document and I’ll address them in follow-up PRs.
2024-06-25 07:47:45 -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
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
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
3b68f15bc4 Merge pull request #1394 from ahoppen/thread-safe-box-sendable
Require `ThreadSafeBox.T` to be Sendable
2024-06-03 13:13:57 -07:00
Alex Hoppen
c7bf59e2ee Require ThreadSafeBox.T to be Sendable
Otherwise, I think `ThreadSafeBox` might still have data races. This also requires us to make `TestSourceKitLSPClient.RequestHandler` sendable.

rdar://128572489
2024-06-03 10:23:13 -07:00
Alex Hoppen
59672e942e Log when a sourcekitd request gets cancelled
I saw a failure in CI where a sourcekitd diagnostic request got cancelled without an LSP cancellation request. I am suspecting that there is some implicit cancellation going on in sourcekitd despite `key.cancel_builds: 0`, which doesn’t make sense to me. Adding some explicit logging to sourcekit-lsp to check if we cancel the request for some reason.
2024-06-03 08:19:58 -07:00
Alex Hoppen
76da45444f Re-generate sourcekitd UIDs 2024-05-23 13:41:40 -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
611f9b5db1 Don’t use @retroactive when building with a Swift 5.10 compiler
This fixes a building using a Swift 5.10 compiler.
2024-03-22 07:43:32 +01:00
Alex Hoppen
f1b34b1c9b Make SKD{Request,Response}{Dictionary,Array} Sendable 2024-03-20 11:48:50 +01:00
Alex Hoppen
e8d0a0d431 Make SourceKitD build with strict concurrency enabled 2024-03-12 14:46:34 -07:00
Alex Hoppen
bad10cd761 Make SourceKitDRegistry an actor 2024-03-12 14:38:00 -07:00
Alex Hoppen
331f16dca7 Merge pull request #1091 from ahoppen/ahoppen/markdown-documentation
Emit raw documentation comments instead of parsing XML
2024-03-01 14:05:12 -08:00
Alex Hoppen
d12b258d99 Rename SourceKitDImpl to DynamicallyLoadedSourceKitD
This makes it clearer how exactly `SourceKitDImpl` interacts with sourcekitd.
2024-02-28 09:28:59 -08:00
Alex Hoppen
a6b8cbecad Emit raw documentation comments instead of parsing XML
Fixes #1014
rdar://120685874
2024-02-26 19:55:23 -08:00
Alex Hoppen
5f69147bf9 Remove logging dependency from SourceKitD
Make logging protocol requirements on `SourceKitD` so that implementers of the protocol can decide how to log requests. This allows us to add different kinds of sourcekitd connections that behave differently in the future, for example one that dynamically links against sourcekitd instead of loading it it using `dlopen`.
2024-02-24 09:27:02 -08:00
Alex Hoppen
f5fb23ad4c Rename sourcekitd_ to sourcekitd_api_ and add nullability annotations to sourcekit_functions.h
Naming types in sourcekitd_functions.h `sourcekit_api_` instead of `sourcekitd_` indicates that these are types to be used with dynamically loaded sourcekitd libraries. It avoids confusion if sourcekitd is also linked, which adds the `sourcekitd_` symbols.

Adding nullability annotations to it is also just nice.

And some improved formatting never hurts.
2024-02-23 09:13:42 -08:00
Alex Hoppen
6f98029ff7 Rename SKDValue to SKDRequestValue
`SKDValue` is only used for requests and the name should reflect that.
2024-02-15 21:30:29 -08:00
Alex Hoppen
b5fd79fbb9 Generate sourcekitd UIDs instead of manually maintaining the list
rdar://121953119
2024-02-14 16:33:34 -08:00
Alex Hoppen
d73f44c447 Support cross-language rename between Swift and clang languages
This adds support for name translation between Swift anc clang languages to allow renaming across those language boundaries.

Rename is always initiated at the symbol’s definition, so when renaming an Objective-C symbol from Swift, the user is prompeted to enter the new Objective-C method name.

rdar://118996461
2024-01-31 10:51:03 -08:00
Alex Hoppen
f2e1707010 Make forEach and map on SKDResponseArray rethrowing 2024-01-25 18:44:43 -08:00
Alex Hoppen
1e72500f1a Merge pull request #1017 from ahoppen/ahoppen/secondary-cursor-info-results
Report secondary cursor info results
2024-01-11 09:30:10 -08:00
Alex Hoppen
7572fb96ee Report secondary cursor info results
rdar://119163908
2024-01-10 21:05:31 -08:00
Alex Hoppen
3991fae867 Define methods on SourceKitD to create arrays and dictionaries instead of using skd postfix syntax 2024-01-08 18:06:31 -08:00
Alex Hoppen
f901cc9250 Support creation of SKDRequest(Dictionary|Array) from literals
IMO this makes it a lot clearer which keys are present in the request dictionaries because we are no longer mutating them on the fly.
2023-12-22 22:29:11 -08:00
Alex Hoppen
34a36b44e6 Refactor rename to support index-based discovery of rename locations 2023-12-12 17:34:34 -08:00
Alex Hoppen
777f1dc463 Add support for rename within the current file
rdar://117822427
2023-12-09 08:35:13 -08:00
Alex Hoppen
8857a08940 Parse information from related identiers that is needed to perform local rename 2023-12-09 08:34:41 -08:00
Alex Hoppen
84fdea9e05 Filter overrides in DefinitionRequest by receiver types 2023-11-29 09:03:36 -08:00
Alex Hoppen
4052465905 Show overriden functions when performing jump-to-definition on a dynamic call
Fixes #809
rdar://114864256
2023-11-29 09:02:02 -08:00