Commit Graph

141 Commits

Author SHA1 Message Date
Alex Hoppen
ca1da1af53 Re-generate sourcekitd UIDs
Also fix a bug that caused swift-format-ignore comments to get dropped when re-generating.
2026-01-12 14:36:32 +01:00
Divya Prakash
0ca0660d99 Refactor DocumentManager threading for Swift 6
Replaces DispatchQueue with ThreadSafeBox, relaxes T: Sendable constraints, and removes @unchecked Sendable from Document.
2025-12-21 19:26:02 +05:30
Anthony Latsis
d1b9c27b95 Merge pull request #2366 from AnthonyLatsis/jepa
Enable some Swift 7 mode features
2025-12-02 17:37:01 +00:00
Anthony Latsis
6b19657739 Enable ExistentialAny 2025-12-02 12:27:27 +00:00
Alex Hoppen
f9f13a4105 Don’t use Optional.map or Optional.flatMap
Replace usages of `Optional.map` and `Optional.flatMap` by if expressions or other expressions.

I personally find `Optional.map` to be hard to read because `map` implies mapping a collection to me. Usually the alternative constructs seem clearer to me.
2025-11-20 09:47:21 +01:00
Owen Voorhees
f04b971726 Adopt swift-tools-protocols 2025-10-31 14:11:11 -07:00
Ben Barham
add109d2d8 Avoid crashing when loading client plugins from the same path
When `DYLD_(FRAMEWORK|LIBRARY)_PATH` is set, `dlopen` will first check
if the basename of the provided path is within any of its search paths.
Thus it's possible that only a single library is loaded for each
toolchain, rather than a separate like we expect. The paths should be
equal in this case, since the client plugin is loaded based on the path
of `sourcekitd.framework` (and we should only have one for the same
reason). Allow this case and just avoid re-initializing.
2025-09-26 12:22:59 -07:00
Alex Hoppen
c7ca73aecb Drop support for building with Swift 6.1
Swift 6.2 has been released, so we no longer need to support building and testing SourceKit-LSP using Swift 6.1
2025-09-20 16:37:24 +02:00
Ahmed Elrefaey
a5854f4ecf Add signature help LSP request support (#2250)
Depends on https://github.com/swiftlang/swift/pull/83378

---

Adds support for the LSP signature help request.

> [!NOTE]
> As of https://github.com/swiftlang/swift/pull/83378, SourceKitD still
doesn't separate parameter documentation from the signature
documentation and thus parameters don't have their own separate
documentation. This should just work once SourceKitD implements this
functionality and we'll only need to modify the tests.
2025-09-05 14:52:56 +01:00
Ahmed Elrefaey
1982798b5d Fetch full documentation in code completion (#2207)
When resolving documentation for code completion items, we fetch full
documentation through the newly added
`swiftide_completion_item_get_doc_full_copy` SourceKitD function, if not
found we fallback to brief documentation as before using
`swiftide_completion_item_get_doc_brief`.

> [!NOTE]
> Unlike brief documentation, SourceKitD doesn't cache full
documentation for completion results to avoid bloating memory with a lot
of large strings.
>
> As of now, SourceKit-LSP doesn't cache completion item documentation
either, should we introduce a new full documentation cache (e.g. using
`LRUCache`)?
2025-09-04 19:42:37 +01:00
Alex Hoppen
6074529dac Manually fix swift-format lint rules
- I think there are valid calls with mixing inline and trailing closures (notably `Debouncer`), so I’m considering whether we should disable that rule.
- The `forEach` rule is a little annoying because we have `forEach` on `SKDResponseArray`. But it caught two cases of using `forEach` on arrays, so I think it’s worth keeping.
2025-08-11 09:31:09 +02:00
Alex Hoppen
98cd30bb1c Apply exhaustive swift-format configuration from swift-syntax
Apply the exhaustive swift-format configuration from https://github.com/swiftlang/swift-syntax/pull/3117 to sourcekit-lsp. Also apply all automatic formattings.
2025-08-11 09:23:39 +02:00
Anthony Latsis
7fb77b6b7a .swift-format: Enable NoVoidReturnOnFunctionSignature 2025-06-23 19:48:20 +01:00
Alex Hoppen
d63419de73 Address review comments 2025-05-12 15:48:45 +02:00
Alex Hoppen
69ab356b36 Log contextual requests that affect sourcekitd’s global state
This way we can log them when a sourcekitd request crashes and we can thus replay these contextual requests when diagnosing the crash.
2025-05-12 15:39:52 +02:00
Alex Hoppen
863c0e2cdf Merge pull request #2137 from ahoppen/terminate-unresponsive-clangd-sourcekitd
If sourcekitd or clangd don’t respond to a request for 5 minutes, terminate them and use crash recovery to restore behavior
2025-05-12 15:13:30 +02:00
Alex Hoppen
14cfd50582 If sourcekitd or clangd don’t respond to a request for 5 minutes, terminate them and use crash recovery to restore behavior
This should be a last stop-gap measure in case sourcekitd or clangd get stuck, don’t respond to any requests anymore and don’t honor cancellation either. In that case we can restore SourceKit-LSP behavior by killing them and using the crash recovery logic to restore functionality.

rdar://149492159
2025-05-07 13:43:28 +02:00
Alex Hoppen
17327e611c Ensure the DLHandle passed to SourceKitD.init(dlhandle:path:pluginPaths:initialize:) gets closed if the initializer fails
Just something I noticed while looking through code. I am not aware of any issues caused by this.

Also relax the `precondition` in `DLHandle.deinit` to a fault. If we do not close a `DLHandle`, that’s a bug but it’s not so bad that we should crash sourcekit-lsp for it.
2025-03-28 14:28:55 -07:00
Alex Hoppen
53407f59af Mark asynchronous blocks in Csourcekitd as Sendable
We don’t have any guarantees which thread these blocks will be called on by sourcekitd, so we shouldn’t make any assumptions about it in Swift. We should thus mark them as Sendable.
2025-03-27 11:06:49 -07:00
Alex Hoppen
5882eae734 Merge SourceKitD.swift and DynamicallyLoadedSourceKitD.swift
With the merge of `SourceKitD` and `DynamicallyLoadedSourceKitD`, there is no longer a need to have two files.
2025-03-27 11:06:48 -07:00
Alex Hoppen
92aa94fa43 Remove the split between SourceKitD and DynamicallyLoadedSourceKitD
There is only one real class that implements the `SourceKitD` protocol, so there really isn’t any need for the protocol + class split at all. Unify them to make code simpler to reason about.
2025-03-27 11:05:24 -07:00
Alex Hoppen
92f3c7740d Wait for request to be sent to sourcekitd before cancelling it in SwiftSourceKitPluginTests.testCancellation
Otherwise, the cancellation could get handled before the request actually gets sent to sourcekitd, which is not what we want to test here. There appears to be a second underlying issue that causes unexpected results when we cancel the fast completion request after sending the slow completion request. I’ll look at that in a follow-up PR.
2025-03-25 14:08:06 -07:00
Alex Hoppen
c68a9892fe Log sourcekitd requests inside withCancellableCheckedThrowingContinuation
Otherwise, we would log sending the sourcekitd request even if the task was already cancelled and we thus took an early exit in `withCancellableCheckedThrowingContinuation`.
2025-03-10 15:56:11 -07:00
Alex Hoppen
34f977219b Merge pull request #2041 from ahoppen/license-headers
Consistently add license headers to all files
2025-03-07 13:26:18 -08:00
Alex Hoppen
1cfa8db1d8 Require Swift 6 to build SourceKit-LSP
This significantly cleans up our `import` statements
2025-03-07 08:05:49 -08:00
Alex Hoppen
cf828a8135 Consistently add license headers to all files
To prepare for the GitHub Action license header check.
2025-03-06 22:01:00 -08:00
Alex Hoppen
b89a232457 Use realpath when setting SOURCEKIT_LSP_PLUGIN_SOURCEKITD_PATH_ environment variable
Otherwise we run into path mismatch issues when the test products are in a path that includes symlinks, such as `/tmp`.
2025-01-22 13:16:05 -08:00
Alex Hoppen
99019bbef2 Fix test failures when running SourceKit-LSP tests with an Xcode toolchain
We need to jump through a few extra hoops when the SourceKit plugin is located in SourceKit-LSP’s build folder and we are using `sourcekitd_plugin_initialize` instead of `sourcekitd_plugin_initialize_2`.
2025-01-16 12:44:22 -08:00
Alex Hoppen
16f897aefa Make the SourceKit plugins work on Windows 2025-01-11 06:57:03 +01:00
Alex Hoppen
1c02ed68b1 Only call sourcekitd_register_plugin_path if we have plugin paths 2025-01-09 14:09:02 +01:00
Alex Hoppen
2d3f933e63 Close DLHandle if initializing sourcekitd fails 2025-01-09 14:09:02 +01:00
Alex Hoppen
e5f1bbfc03 Set plugin paths in all tests
Otherwise, we were trying to load sourcekitd without the plugins for the normal SourceKIt-LSP tests and with the plugins for the plugin tests.
2025-01-09 14:09:01 +01:00
Alex Hoppen
1c3e5bb724 Communicate the path of sourcekitd that the plugin was loaded from to the plugin 2025-01-09 14:09:01 +01:00
Alex Hoppen
5709e1a864 Add a SourceKit plugin to handle code completion requests
This adds a sourcekitd plugin that drives the code completion requests. It also includes a `CompletionScoring` module that’s used to rank code completion results based on their contextual match, allowing us to show more relevant code completion results at the top.
2025-01-03 14:21:54 +01:00
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