Commit Graph

277 Commits

Author SHA1 Message Date
Alex Hoppen
35899ab348 Merge pull request #1658 from ahoppen/revert-uri-hack
Revert "Add an extra percent encoding layer when encoding DocumentURIs to LSP requests"
2024-09-11 14:38:16 -07:00
Alex Hoppen
5d1eb73a68 Revert "Add an extra percent encoding layer when encoding DocumentURIs to LSP requests"
This reverts commit b2c17c748d.

The workaround isn’t needed anymore because we have a proper fix in the VS Code extension: https://github.com/swiftlang/vscode-swift/pull/1026
2024-09-10 14:51:28 -07:00
Alex Hoppen
b9370cf276 Allow overriding the timeout duration for tests 2024-09-10 13:44:59 -07:00
Alex Hoppen
b4d04ce983 Introduce a BuiltInBuildSystemAdapter that can be used to transition BuildSystem to a type that implements BSP 2024-09-09 16:31:00 -07:00
Alex Hoppen
d86a32bc19 Remove custom decoding function from SourceKitLSPOptions
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`
- `cancelTextDocumentRequestsOnEditAndClose`

We had the custom decoder function so that the keys weren’t required in the JSON but we could access eg. `SwiftPMOptions` without needing to deal with optionals in the codebase.

Make the accesses to these nested options structs a little more verbose but eliminate the source of the above bug, which seems like a good tradeoff.
2024-09-06 13:45:24 -07:00
Alex Hoppen
b2c17c748d Add an extra percent encoding layer when encoding DocumentURIs to LSP requests
The URI standard RFC 3986 is ambiguous about whether percent encoding and their represented characters are considered equivalent. VS Code considers them equivalent and treats them the same:

```js
vscode.Uri.parse("x://a?b=xxxx%3Dyyyy").toString() -> 'x://a?b%3Dxxxx%3Dyyyy'
vscode.Uri.parse("x://a?b=xxxx%3Dyyyy").toString(/*skipEncoding=*/true) -> 'x://a?b=xxxx=yyyy'
```

This causes issues because SourceKit-LSP's macro expansion URLs encoded by URLComponents use `=` do denote the separation of a key and a value in the outer query. The value of the `parent` key may itself contain query items, which use the escaped form '%3D'. Simplified, such a URL may look like `scheme://host?parent=scheme://host?line%3D2`.

But after running this through VS Code's URI type `=` and `%3D` get canonicalized and are indistinguishable.

To avoid this ambiguity, always percent escape the characters we use to distinguish URL query parameters, producing the following URL: `scheme://host?parent%3Dscheme://host%3Fline%253D2`.
2024-08-19 21:41:50 -07:00
Alex Hoppen
d4ebf594f0 Add convenience accessor in tests to get a full diagnostic report
This simplifies tests a little bit
2024-08-15 16:31:07 -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
ae660e0e9f Explicitly qualify module name for extensions that add retroactive conformances 2024-07-31 17:25:20 -07:00
Alex Hoppen
6144b5f27a Throw error FileManager.default.createFile if returns false
Returning `false` indicates that file creation failed, which we should note instead of ignoring it.

This fixes a warning on Linux that the result of `createFile` was ignored.
2024-07-31 17:25:20 -07:00
Alex Hoppen
970b44d255 Remove a few @preconcurrency imports
rdar://132378792 is fixed
2024-07-31 17:25:20 -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
66f2d86775 Rename SKCore to BuildSystemIntegration 2024-07-25 09:11:13 -07:00
Alex Hoppen
6d34d70883 Split SourceKitLSPOptions out of SKCore
This only leaves build system functionality in SKCore, which allows us to rename SKCore.
2024-07-25 09:11:13 -07:00
Alex Hoppen
cfe18f1256 Split toolchain-related functionality out of SKCore 2024-07-25 09:11:13 -07:00
Alex Hoppen
1ef71cf663 Merge LSPTestSupport and SKTestSupport 2024-07-25 09:11:13 -07:00
Alex Hoppen
8c34a76f59 Rename LSPLogging to SKLogging 2024-07-25 09:11:13 -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
83cb1625f4 Merge pull request #1544 from ahoppen/function-output-together
Set `prioritizeKeepingFunctionOutputTogether` in `.swift-format`
2024-07-02 22:46:24 +02:00
Alex Hoppen
f4ea614be6 Set prioritizeKeepingFunctionOutputTogether in .swift-format 2024-07-02 11:06:35 +02:00
Alex Hoppen
5784bf87e5 Merge pull request #1538 from ahoppen/skip-wasm-test
Skip `testWasm` if the host toolchain can’t build for WASM
2024-07-02 06:57:43 +02:00
Alex Hoppen
ab67a7e8ca 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-28 23:25:41 +02:00
Alex Hoppen
c6b82a7556 Fix a compilation issue caused by #1533 and #1524 racing 2024-06-28 22:54:52 +02:00
Alex Hoppen
16e4f83ec3 Merge pull request #1534 from ahoppen/configuration-improvements
Allow specification of SourceKitLSPOptions in the initialize request and look for SourceKit-LSP options in `$XDG_CONFIG_HOME/sourcekit-lsp`
2024-06-28 22:18:45 +02:00
Alex Hoppen
ddbad85c28 Allow specification of SourceKitLSPOptions in the initialize request
This allows editors to provide UI elements to toggle SourceKit-LSP options.
2024-06-28 10:25:37 +02:00
Alex Hoppen
d8e0fff6da 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
2024-06-28 10:23:29 +02:00
Alex Hoppen
d1cddb8c41 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.
2024-06-27 17:36:16 +02:00
Alex Hoppen
96f6e69dd8 Merge pull request #1513 from ahoppen/swiftlang-migration
Update links for repositories moved to the swiftlang org on GitHub
2024-06-25 21:09:10 -07:00
Alex Hoppen
da1f6dae80 Update links for repositories moved to the swiftlang org on GitHub 2024-06-25 04:34:28 -07:00
Alex Hoppen
5d42fcde17 Add a variant of send to TestSourceKitLSPClient that allows implicit discarding of VoidResponse
Cleans up tests slightly.
2024-06-25 03:41:07 -07:00
Alex Hoppen
4d90f40f72 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`.
2024-06-21 07:19:57 -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
e62473b8d6 Merge pull request #1492 from ahoppen/fix-concurrency-warnings
Fix a few Swift concurrency warnings
2024-06-20 08:59:31 -07:00
Alex Hoppen
8642768902 Fix a few Swift concurrency warnings 2024-06-18 18:07:22 -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
3952f68f81 Try linking again SwiftSyntax in SkipUnless.canBuildMacroUsingSwiftSyntaxFromSourceKitLSPBuild
I don’t remember the exact failure scenario but there were issues where the modules could be found but linking against the swift-syntax libraries from the sourcekit-lsp build failed. If this happens, skip any macro tests.
2024-06-18 08:35:40 -07:00
Alex Hoppen
e1d8de11b4 Skip testJumpToSatisfiedProtocolRequirementInExtension if the toolchain does not mark overridable function declarations as dynamic
This test requires https://github.com/apple/swift/pull/74080 and should be skipped if the host toolchain does not have that change.
2024-06-17 09:34:27 -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
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
fe90bef856 Skip testLibraryUsedByExecutableTargetAndPackagePlugin if SwiftPM can’t handle modules for the target and host properly
This fixes a test failure in Xcode 15.4.
2024-06-07 16:38:46 -07:00
Alex Hoppen
dfb7b46350 Add test to check that we get semantic functionality even if a dependency module fails to prepare
rdar://128683404
2024-06-07 11:26:07 -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
efabae8808 Take run destinations into account for SwiftPM build targets
We can have two targets with the same name in a SwiftPM workspace, one for a build target and one for the destination. We need to be able to tell them apart based on the run destination.
2024-06-06 09:33:00 -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
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
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