Commit Graph

1834 Commits

Author SHA1 Message Date
Alex Hoppen
44a095c8aa 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.

Fixes #1541
rdar://130844901
2024-10-08 17:35:13 -07:00
Alex Hoppen
75c70d9c5a Decode a few keys in SourceKitLSPOptions that we missed before
We forgot to decode the following keys in the custom decode function, which meant that you couldn’t set them using SourceKit-LSP’s `config.json` file.
- `backgroundPreparationMode`
- `sourcekitdRequestTimeout`

In particular this meant that you couldn’t enable the `--experimental-prepare-for-indexing` preparation mode.

Add the necessary decoding functions in `release/6.0` and eliminate the custom decode logic entirely in `main`.
2024-09-06 13:03:42 -07:00
Alex Hoppen
1780d06c45 Add option to allow SourceKit-LSP to prepare a target without lazy type checking
rdar://130333458
2024-07-25 17:16:21 -07:00
Pavel Yaskevich
8a6df8ac5e Remove availableLibraries argument from loadPackageGraph
Prebuilt/provided libraries feature is reverted by https://github.com/swiftlang/swift-package-manager/pull/7800
2024-07-19 16:09:55 -07:00
Alex Hoppen
7baf991603 Merge pull request #1578 from ahoppen/6.0/import-free
[6.0] Import `Darwin` in files that use `free`
2024-07-18 13:59:43 -07:00
Alex Hoppen
a044f680a3 Import Darwin in files that use free
rdar://131965190
2024-07-18 11:30:12 -07:00
Alex Hoppen
3f8d7feb3e Merge pull request #1564 from plemarquand/add-trigger-reindex-to-req-list-60
[6.0] Add TriggerReindexRequest to builtinRequests
2024-07-17 12:40:03 -07:00
Alex Hoppen
f487ebddb0 Merge pull request #1566 from plemarquand/multi-package-root-fix-60
[6.0] Fix incorrect ConfiguredTargets for Package.swift w/ multiple workspaces
2024-07-17 12:39:56 -07:00
Paul LeMarquand
f830432322 Fix incorrect ConfiguredTargets for Package.swift w/ multiple workspaces
In a project with multiple folders each containing a Package.swift, the
`bestWorkspace` found in `workspaceForDocument(uri:)` was always the
first one encountered.

`fileHandlingCapability(for:)` checks if there are configured targets
for the Package.swift and if there are, the workspace is chosen since
the Package.swift is determined to be part of the workspace. However the
check in `configuredTargets(for:)` always returned a target for any
`Package.swift`, even if that `Package.swift` was not part of the
workspace associated with the BuildSystem.

Ultimately this manifested as code completion not working in all but one
of the Package.swift files in a multi workspace project.

Some work was done in #1210 to address swiftlang/vscode-swift#768, which
is where this issue originated from. However while verifying
swiftlang/vscode-swift#768 I found that #1210 didn't fully address code
completion of `Package.swift` files in multi workspace projects.
2024-07-16 13:32:38 -04:00
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
aca98d39be Merge pull request #1554 from plemarquand/release/6.0
[6.0] Respect module name argument order precedence
2024-07-16 08:11:29 -07:00
Paul LeMarquand
17cb540b8c Add TriggerReindexRequest to buildinRequests
`TriggerReindexRequest` was missing from the list of builtinRequests,
which caused the LSP to respond with a methodNotFound error when it
recieved a `workspace/triggerReindex` request.
2024-07-15 08:50:01 -04:00
Finagolfin
3f00eba475 Import new Bionic module from Android overlay instead where possible 2024-07-10 20:42:04 +05:30
Finagolfin
9ca2942abd Import new Android overlay 2024-07-04 19:39:38 +05:30
Paul LeMarquand
8033e8437e Respect module name argument order precedence
When the same flag is specified multiple times the last one found is
used.
2024-07-04 09:09:32 -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
a84c253aa1 Skip testWasm if the host toolchain can’t build for WASM
This fixes a test failure when running tests using Xcode 15.4.
2024-06-29 07:05:35 +02:00
Alex Hoppen
d8651a3b73 Fix a compilation issue caused by #1533 and #1524 racing 2024-06-28 22:57:48 +02:00
Alex Hoppen
f761866d7d Look for SourceKit-LSP options in $XDG_CONFIG_HOME/sourcekit-lsp
The reverse-DNS notation is macOS style and doesn’t feel at home on Linux.
2024-06-28 22:56:02 +02: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
5440ba2d57 Support using SourceKit-LSP for projects that are cross-compiled
We previously always assumed that the project was being built for the host.

Fixes #786
Fixes #1475
rdar://129662080
rdar://113099964
2024-06-28 22:35:27 +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
b34ed66069 Merge pull request #1522 from ahoppen/6.0/log-toolchain-path
Log path of the toolchain used to opening a document
2024-06-26 22:24:50 +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
55f6dee5c8 Update links for repositories moved to the swiftlang org on GitHub 2024-06-25 06:57:00 -07: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
a111b4748b Merge pull request #1485 from ahoppen/working-directory-on-amazonlinux
When setting a working directory on process launch is not supported, set it using `sh`
2024-06-20 13:44:47 -07:00
Alex Hoppen
198854494a Merge pull request #1497 from apple/maxd/fix-command-name
Fix incorrect command name in `sourcekit-lsp --help` output
2024-06-20 09:06:48 -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
Max Desiatov
6cd6e73797 Fix incorrect command name in sourcekit-lsp --help output
Currently the name of the command is `source-kit-lsp` in `sourcekit-lsp --help` output:

```
❯ sourcekit-lsp --help
OVERVIEW: Language Server Protocol implementation for Swift and C-based languages

USAGE: source-kit-lsp <options> <subcommand>
```
2024-06-19 15:02:48 +01:00
Alex Hoppen
8642768902 Fix a few Swift concurrency warnings 2024-06-18 18:07:22 -07:00
Alex Hoppen
acabb1d406 Merge pull request #1490 from ahoppen/resolve-symlinks-toolchain-txt
Resolve symlinks in toolchain path when creating sourcekitd reproducer bundle
2024-06-18 15:22:13 -07:00
Alex Hoppen
df08551d7c When setting a working directory on process launch is not supported, set it using sh
In particular, this affects Amazon Linux 2, which has a glibc that doesn’t support `posix_spawn_file_actions_addchdir_np`.

rdar://128016626
2024-06-18 15:12:26 -07:00
Alex Hoppen
9f5c404b79 Merge pull request #1489 from ahoppen/no-notification-missing-compiler-args
Remove warning message about missing compiler arguments
2024-06-18 15:10:29 -07:00