Commit Graph

2084 Commits

Author SHA1 Message Date
Alex Hoppen
ec235dfd28 Merge pull request #1755 from ahoppen/shorter-diags-debounce-duration
Reduce the debounce duration to publish diagnostics to 1s
2024-10-14 13:26:35 -07:00
Alex Hoppen
38ac399b58 Reduce the debounce duration to publish diagnostics to 1s
We received two feedbacks that the 2s timeout is too long. 2s was a somewhat arbitrary choice, let’s reduce it to 1s.

Fixes #1753
2024-10-14 09:51:43 -07:00
Alex Hoppen
17b13a935a Merge pull request #1751 from ahoppen/windows-fixes 2024-10-11 11:31:44 -07:00
Rintaro Ishizaki
5802aadf57 Merge pull request #1746 from rintaro/raw-editor-placeholder
Update for EditorPlaceholder SPI changes in swift-syntax
2024-10-10 20:18:17 -07:00
Rintaro Ishizaki
7add264c3e Update for EditorPlaceholder SPI changes in swift-syntax 2024-10-10 11:44:07 -07:00
Alex Hoppen
c16e33d281 Miscellaneous adjustments to make tests pass on Windows
This is mostly test infrastructure that needed adjusting.
2024-10-10 09:28:26 -07:00
Alex Hoppen
2623b4949d Use the test’s default timeout duration for sourcekitd timeouts
Otherwise, we are stuck with the timeout default of 120s and the test runner can’t increase it.
2024-10-09 13:55:18 -07:00
Alex Hoppen
aa0aa927ca Stop using TSCBasic.resolveSymlinks and URL.resolvingSymlinksInPath 2024-10-09 13:16:57 -07:00
Alex Hoppen
3bf05ad51f Merge pull request #1743 from ahoppen/withtimeout-issue 2024-10-08 21:58:11 -07:00
Alex Hoppen
77f02fc706 Yield TimeoutError before cancelling body task in withTimeout
Otherwise, the body task might finish before we yield the `TimeoutError` and thus `withTimeout` would not actually throw a `TimeoutError`.

rdar://137171114
2024-10-08 15:26:02 -07:00
Paul LeMarquand
d8b0577465 Fix inadvertent shadowing of ClientCapabilities subtypes
When removing the LanguageServerProtocol namespace from types in
ClientCapabilities (#1734), some types inadvertently started shadowing
themselves. This lead to client initialization errors when the
initialization request couldn't be decoded:

```
type mismatch at params.capabilities.textDocument.completion.completionItemKind.valueSet.Index 0 : Expected to decode Dictionary<String, Any> but found number instead.
```

Disambiguating these inner types in ClientCapabilities fixes decoding.
2024-10-08 12:24:24 -04:00
Alex Hoppen
dd95a3d7fe Merge pull request #1738 from ahoppen/pop-outstanding-request-on-crash
Remove elements from `outstandingRequests` on crash
2024-10-07 16:06:52 -07:00
Alex Hoppen
e50b4d78e5 Remove elements from outstandingRequests on crash
Otherwise, we can have a retain cycle where the `OutstandingRequest` keeps the `JSONRPCConnection` alive.

Also move the code that handled `outstandingRequests` out of the `Task` because `outstandingRequests` should only be accessed from `queue`.
2024-10-04 17:22:26 -07:00
Alex Hoppen
aa7389c60f Merge pull request #1735 from ahoppen/frozen-messagekind
Mark `MessageDecodingError.MessageKind` as `@frozen`
2024-10-04 15:55:51 -07:00
Alex Hoppen
87db1bf614 Merge pull request #1736 from ahoppen/weak-back-ref
Make `BuildSystemManager` only keep a weak reference to `SourceKitLSPServer`
2024-10-04 15:54:24 -07:00
Alex Hoppen
dff72f1807 In withTaskPriorityChangedHandler execute the task that watches for priority changes with high priority
I saw a nondeterministic test failure of `AsyncUtilsTests.testWithTimeoutEscalatesPriority` and I believe this was the cause.

Also refactor a few test helper functions on the way.
2024-10-04 09:57:52 -07:00
Alex Hoppen
52599974a8 Make BuildSystemManager only keep a weak reference to SourceKitLSPServer
This allows us to free `SourceKitLSPServer` in tests even if there are outstanding messages from the build server to be handled.
2024-10-03 17:41:54 -07:00
Alex Hoppen
62271b47b7 Merge pull request #1734 from ahoppen/lsp-module-references
Remove references to the `LanguageServerProtocol` modules in that module itself
2024-10-03 14:31:55 -07:00
Alex Hoppen
06f6f8f17b Remove references to the LanguageServerProtocol modules in that module itself 2024-10-02 14:16:33 -07:00
Alex Hoppen
01640ee68f Merge pull request #1731 from ahoppen/bsp-implementation-documentation
Add a document that describes the basic steps needed to implement a BSP server
2024-10-02 10:27:30 -07:00
Alex Hoppen
ee29e31fb4 Merge pull request #1719 from ahoppen/explicit-bsp-shutdown
Explicitly shut down the build server when SourceKit-LSP is shut down
2024-10-02 10:27:15 -07:00
Alex Hoppen
2e61d33645 Mark MessageDecodingError.MessageKind as @frozen 2024-10-02 09:34:49 -07:00
Alex Hoppen
9a3a0df7a7 Merge pull request #1730 from ahoppen/finish-immediately-timeout
When `withTimeout` hits a timeout, don’t wait for cooperative cancellation before returning
2024-10-01 09:53:20 -07:00
Alex Hoppen
86653b3c45 When withTimeout hits a timeout, don’t wait for cooperative cancellation before returning
Previously, when we hit the timeout in `withTimeout`, we just cancelled `body` but relied on cooperative cancellation before the caller could continue. Since the caller is obviously no longer interested in the operation, we can return with `CancellationError` immediately.

Fixes #883
rdar://116705684
2024-09-30 15:55:09 -07:00
Alex Hoppen
f6eac86f3d Merge pull request #1724 from ahoppen/tracing-file
Add subcommand to visualize the requests running concurrently using a trace file
2024-09-30 15:50:22 -07:00
Alex Hoppen
3c7aa6f438 Merge pull request #1715 from ahoppen/bsp-cancellation
Share implementation of message handling on an `AsyncQueue` between `BuildSystemIntegration` and `SourceKitLSPServer`
2024-09-30 15:31:54 -07:00
Alex Hoppen
84878fe3a9 Merge pull request #1705 from ahoppen/watch-files-by-build-system
Allow build systems to specify the files to watch for changes
2024-09-30 15:31:41 -07:00
Alex Hoppen
c2d1c15310 Add a document that describes the basic steps needed to implement a BSP server 2024-09-30 14:51:07 -07:00
Alex Hoppen
dd19baa302 Add subcommand to visualize the requests running concurrently using a trace file
Showing the list of active requests didn’t turn out to be very useful for debugging. What is more useful, however, is to visualize the requests as the get enqueued and handled in a trace chart. This gives a very intuitive view of which request is blocking another request from getting executed.
2024-09-30 12:04:11 -07:00
Alex Hoppen
d25b65c307 Explicitly shut down the build server when SourceKit-LSP is shut down
The build server is automatically shut down using a background task when `BuildSystemManager` is deallocated.

This, however, leads to possible race conditions where the shutdown task might not finish before the test is done, which could result in the connection being reported as a leak. To avoid this problem, we want to explicitly shut, down the build server when the `SourceKitLSPServer` gets shut down.
2024-09-30 11:57:39 -07:00
Alex Hoppen
4e53c01944 Merge pull request #1729 from ahoppen/reduce-public-imports
Reduce the number of public imports
2024-09-30 11:43:44 -07:00
Alex Hoppen
7befd0c648 Share implementation of message handling on an AsyncQueue between BuildSystemIntegration and SourceKitLSPServer
This gives us cancellation support for `BuiltInBuildSystemAdapter`.
2024-09-30 10:42:46 -07:00
Alex Hoppen
36478d87ed Allow build systems to specify the files to watch for changes
rdar://136014553
Resolves #1671
2024-09-30 10:33:32 -07:00
Alex Hoppen
8861f3a88d Merge pull request #1721 from ahoppen/improve-bsp-crash-recovery-test
Improve `BuildServerBuildSystemTests.testCrashRecovery`
2024-09-30 10:23:34 -07:00
Alex Hoppen
d842579402 Merge pull request #1712 from ahoppen/build-system-logging-improvements
Improve logging surrounding build systems
2024-09-30 08:11:40 -07:00
Alex Hoppen
947e5269c4 Reduce the number of public imports 2024-09-30 07:50:12 -07:00
Alex Hoppen
431a1c7e4f Merge pull request #1710 from ahoppen/internal-imports
Adopt `InternalImportsByDefault`
2024-09-30 02:43:14 -07:00
Alex Hoppen
794d4936fe Revert "Use fallback build settings if build system doesn’t provide build settings within a timeout"
This reverts commit 78217ec6a6.
2024-09-27 12:32:47 -07:00
Alex Hoppen
bd422cf5d7 Improve logging surrounding build systems 2024-09-27 11:07:39 -07:00
Alex Hoppen
f09f7e8714 Improve BuildServerBuildSystemTests.testCrashRecovery
The original idea behind this test was that only opening `Crash.swift` would retrieve build settings for `Crash.swift`. But that wasn’t actually true: Scanning for tests also retrieved build settings (to get the test’s module name). This caused test failures if we set `SOURCEKIT_LSP_TEST_TIMEOUT: 10`, like we do in `settings.json`.

Improve the test to actually check that the BSP server has crashed and increase timeout to be bigger than the 10s restart delay.
2024-09-27 10:58:50 -07:00
Alex Hoppen
9b4a9b04bc Merge pull request #1720 from ahoppen/atomic-instead-of-queue
Use an `AtomicInt32` to count `pendingUnitCount` instead of using `AsyncQueue`
2024-09-27 10:30:43 -07:00
Alex Hoppen
b91f72f1d4 Merge pull request #1700 from ahoppen/build-settings-timeout
Use fallback build settings if build system doesn’t provide build settings within a timeout
2024-09-27 10:28:50 -07:00
Alex Hoppen
8cd831b55d Adopt InternalImportsByDefault 2024-09-27 09:17:13 -07:00
Alex Hoppen
2c9436b08c Use an AtomicInt32 to count pendingUnitCount instead of using AsyncQueue
Adding an item to `AsyncQueue<Serial>` is linear in the number of pending queue items, thus adding n items to an `AsyncQueue` before any can execute is in O(n^2). This decision was made intentionally because the primary use case for `AsyncQueue` was to track pending LSP requests, of which we don’t expect to have too many pending requests at any given time.

`SourceKitIndexDelegate` was also using `AsyncQueue` to track the number of pending units to be processed and eg. after indexing SourceKit-LSP, I have seen this grow up to ~20,000. With the quadratic behavior, this explodes time-wise.

Turns out that we don’t actually need to use a queue here at all, an atomic is sufficient and much faster.

Independently, we should consider mitigating the quadratic behavior of `AsyncQueue<Serial>` or `AsyncQueue` in general.
2024-09-26 21:51:28 -07:00
Alex Hoppen
fb5ee8e9c7 Miscellaneous adjustments to allow SourceKit-LSP to build using Swift 5.10 2024-09-26 18:23:59 -07:00
Alex Hoppen
2ec571b529 Revert "Require a Swift 6 compiler to build SourceKit-LSP"
This reverts commit 7ab7c01cdc.

# Conflicts:
#	Package.swift
2024-09-26 18:23:59 -07:00
Alex Hoppen
78217ec6a6 Use fallback build settings if build system doesn’t provide build settings within a timeout
When we receive build settings after hitting the timeout, we call `fileBuildSettingsChanged` on the delegate, which should cause the document to get re-opened in sourcekitd and diagnostics to get refreshed.

rdar://136332685
2024-09-26 17:50:58 -07:00
Alex Hoppen
c96fff1c7b Merge pull request #1716 from ahoppen/explicit-self
Specify explicit `self` in `ExternalBuildSystemAdapter`
2024-09-26 17:45:28 -07:00
Alex Hoppen
b9aa4ddda0 Merge pull request #1702 from ahoppen/environment-variable-prefix
Consistently use `SOURCEKITLSP_` as prefix of environment variables instead of `SOURCEKIT_LSP`
2024-09-26 14:44:10 -07:00
Alex Hoppen
bdf9615324 Specify explicit self in ExternalBuildSystemAdapter
I’m not entirely sure why but the file fails to compile with multiple arches without the `self`.
2024-09-26 13:29:59 -07:00