Commit Graph

56 Commits

Author SHA1 Message Date
Alex Hoppen
e073a01bbc Reply with null to shutdown request
The LSP spec says the result of `shutdown` is `null`, not an empty object.

Fixes #1733
rdar://137886488
2024-11-22 15:52:27 +01: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
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
1ef71cf663 Merge LSPTestSupport and SKTestSupport 2024-07-25 09:11:13 -07:00
Lokesh.T.R
087ea64ed3 Rename note to notification throughout the codebase wherever necessary 2024-05-29 17:58:04 +00:00
Alex Hoppen
b442195e61 Make ConnectionTests build in Swift 6 mode 2024-05-14 15:00:43 -07:00
Doug Gregor
f6d286ef0f Fixup for coding change to OptionalVersionedTextDocumentIdentifier 2024-04-24 21:25:55 -07:00
Alex Hoppen
8e9c19ac61 Don’t fatalError when constructing DocumentURI from an invalid URL 2024-04-04 11:05:49 -07:00
Alex Hoppen
bd1ff8a30b Rename ws in tests to project
Now that all the types that model test projects are suffixed `Project` instead of `Workspace`, the `ws` abbreviation doesn‘t make sense. It also never really fit with the new style of avoiding abbreviations. Rename all occurrences to `project`.

rdar://124727401
2024-03-20 23:05:54 +01:00
Alex Hoppen
abd534b584 Fix a race condition in TestMessageHandler
Not entirely sure what introduced the race condition. Found by thread sanitizer. Probably wouldn’t have been an issue if we had migrated this code to strict concurrency checking.
2024-03-05 13:23:25 -08:00
JCWasmx86
6e632129aa Validate ClangWorkspaceSettings before preferring it over unknown WorkspaceSettingsChanges
Basically everything will be decoded as ClangWorkspaceSettings, even if it has nothing to
do wit hit, yielding for example:
```
clangd(LanguageServerProtocol.ClangWorkspaceSettings(compilationDatabasePath: nil, compilationDatabaseChanges: nil))
```
This breaks at least my case of using WorkspaceSettingsChange. This patch adds a - maybe bandaid - fix for that.

Furthermore I removed one Test, as it - AFAIU - broke the invariant that none of the attributes
of ClangWorkspaceSettings may be nil.
2023-10-31 07:34:02 +01:00
Alex Hoppen
9abcd2a3a3 Remove the Notification type
`Notification` is just a wrapper around `NotificationType` and there’s no reason for it to exist anymore.

Resolves #880
rdar://116705670
2023-10-26 18:28:10 -07:00
Alex Hoppen
0e85e544a2 Remove unused functions from TestClient 2023-10-12 08:28:06 -07:00
Alex Hoppen
d0fc00ce98 Format using swift-format
Add `.swift-format` to the repo and format the repo with `swift-format`.

This commit does not add any automation to enforce formatting of sourcekit-lsp in CI. The goal of this commit is to get the majority of source changes out of the way so that the diff of actually enforcing formatting will have fewer changes or conflicts.
2023-10-10 13:44:47 -07:00
Alex Hoppen
bdda582714 Reduce usgaes of try! in tests
The usage of `try!` was still a relict of when `XCTest` didn’t allow throwing test method.
2023-09-18 19:16:49 -07:00
JCWasmx86
f10e5c5d8d Send token with WorkDoneProgress 2023-04-20 05:21:12 +02:00
Alex Hoppen
93a8f91436 Update request and notification definitions to LSP 3.17 2022-12-01 10:44:40 +01:00
Alex Hoppen
df594e332c Set a default timeout duration
Instead of having ad-hoc timeout durations in all the test cases, specify a default timeout duration that can be used by tests.

This allows us increase the timeout duration for all tests if we discover that e.g. sourcekitd is slower in CI setups.

rdar://91615376
2022-06-14 17:26:06 +02:00
Alex Hoppen
c445225721 Delete LinuxMain and XCTestManifests and automatically discover test on Linux
Automatic test discovery is enabled by default since Swift 5.4. I think we can start relying on it.
2022-01-18 12:52:36 +01:00
Snowy
56dafdeade Add RenameRequest and PrepareRenameRequest 2021-10-02 15:07:36 +02:00
David Goldman
9fbaebb40f Fix document symbols regression
This appears to have been accidentally removed in
17f656865d, the `children` field is
optional in the LSP spec.

Change-Id: I1055658c8f09873279d676fee0daff02fa59e3f8
2021-09-20 12:24:58 -04:00
Fredrik Wieczerkowski
f83f7f287e Fix LanguageServerProtocolTests
The coding of document symbols now correctly expects an empty children
array.
2021-08-27 05:18:20 +02:00
David Goldman
01f4b0ff00 Add LSP types and server stubs for call hierarchy support (#377)
* Add LSP types and server stubs for call hierarchy support

* Update CMakeLists.txt for new LSP types

* Call hierarchy misc fixes

* Minor PositionRangeArray fixes to simplify codable conformance

* Add CodingTests for PositionRangeArray and CallHierarchy encoding
2021-03-22 17:35:37 -04:00
David Goldman
e6b0796cff Additions to the LSP module for workspace/didChangeWatchedFiles (#376)
* Additions to the LSP module for `workspace/didChangeWatchedFiles`

We can then use this functionality to allow a `BuildSystem` to watch
files (e.g. via the client or even in-process file watching),
which would allow us to do things like detect new files and provide
accurate build settings for them.

* Improve #file and #line for LSP test errors

Also regenerate Linux main

* Add `LSPAnyCodable` protocol requirement to RegistrationOptions

* Don't encode an optional documentSelector to null

* Skip running `testSourcekitdCrashRecovery` when not on macOS
2021-03-17 15:11:26 -04:00
Owen Voorhees
77a81ad9c1 Expose diagnostic educational notes as diagnostic codes 2020-11-09 18:30:02 -08:00
David Goldman
5977d611aa Withhold diagnostics when fallback arguments are being used (#281)
While fallback arguments are being used (either from the fallback build system or fallback settings from the primary build system), withhold semantic diagnostics from sourcekitd and all diagnostics from clangd. This helps prevent user confusion from spurious errors.

- Also remove the DocumentURI standardization in favor of proper equality + hash checks to work around the %40 --> @ encoding issue seen on CI.
2020-06-11 11:38:50 -04:00
Ben Langmuir
a912fc0025 Regenerate linuxmain
Was missed after a recent test addition.
2020-04-01 10:41:50 -07:00
David Goldman
81e2688c5d Support for clangd's go-to-definition for #include/#import (#247)
* Support for clangd's go-to-definition for header files

- By forwarding the request to clangd when it fails to give
  symbol information, we are able to use its built in
  go-to-definition support for headers (jump to header file)

* Add static tibs test for clangd go-to-#include

* Move #include test to SourceKitTests and regenerate linux main

* Fix improper escaping of %40 in file URLs

* Add URL escaping test

* Another attempt to fix broken BuildServerBuildSystemTests test on Linux

- URL's `standardizedFileURL` removes trailing slashes from file URLs,
  but only on Linux
2020-03-13 19:20:25 -04:00
Alex Hoppen
bfdcccd9a3 In HoverResponse Decode single MarkedString as [MarkedString] with one element 2019-12-12 17:17:35 -08:00
Alex Hoppen
2b0f71a945 Update WorkspaceEdit to match version 3.14 of the LSP spec 2019-12-12 17:17:35 -08:00
Alex Hoppen
c3e70b5933 Update ServerCapabilities to match version 3.14 of the LSP spec 2019-12-12 17:17:35 -08:00
Alex Hoppen
7ebf103645 Update ImplementationRequest to match version 3.14 of the LSP spec 2019-12-06 08:31:44 -08:00
Alex Hoppen
bcadf01539 Update DocumentSymbolRequest to match version 3.14 of the LSP spec 2019-12-06 08:31:19 -08:00
Alex Hoppen
711d7827dd Update DefinitionRequest to match version 3.14 of the spec 2019-12-06 08:31:19 -08:00
Alex Hoppen
fa012d7386 Update CompletionItem to match version 3.14 of the spec 2019-12-06 08:31:19 -08:00
Alex Hoppen
a75a288a45 Update Completion to match version 3.14 of the spec 2019-12-06 08:31:19 -08:00
Ben Langmuir
d2cfe7e847 Upgrade CustomCodable to handle optional values using encodeIfPresent
The LSP spec requires us to omit keys for nil values rather than using
the JSON `null` constant in most places. This change to CustomCodable
allows us to do it automatically using CustomCodable, removing one of
the limitations of the property wrapper.

The idea for the adding overloads of `encode` and `decode` came from
https://forums.swift.org/t/pre-pitch-codable-customization-using-propertywrappers/30244/
2019-12-04 08:49:19 -08:00
Alex Hoppen
03dde148a9 Support MarkedStrings in Hover responses 2019-12-03 15:07:17 -08:00
Alex Hoppen
558d7fc664 Change backing storage of DocumentURI to URL
URL can in fact store URIs, it just doesn't have a very nice API to
interact with them. As long as we only operate on absoluteString, we
should be fine though. So instead of implementing the logic for
detecting file URLs ourselves, we can just use a URL as storage for
DocumentURI.
2019-11-20 09:41:48 -08:00
Alex Hoppen
5c839f8640 Add support for non-URL URIs
According to the LSP specification, arbitrary URIs can be used as
document identifiers. Instead of internally assuming that all URIs are
URLs, use a DocumentURI enum to represent URIs. These can either be file
URLs or other URIs whose value as treated as an opaque string.
2019-11-20 09:41:48 -08:00
Alex Hoppen
05ecd26d08 Reorganize the repository into a set of bare LSP modules and SourceKit modules
We will be able to split the LSP modules off later. These LSP modules
will provide the ability to write custom LSP servers and clients in
Swift. The sourcekit-lsp repository will build on top of this new
package to provide an LSP implementation that creates a language server
for Swift and C-based-languages.
2019-11-14 10:35:06 -08:00
Bruno Rocha
9eb2fe4453 Clean implementation 2019-10-04 12:34:09 -03:00
Ben Langmuir
2c460cb2d5 Move custom PositionRange encoding into a property wrapper
This lets us use the `Range<Position>` without manually converting back
and forth in the majority of cases. See the note on HoverResponse for
the behaviour with Optional that makes us have to provide a custom
Codable implementation in two places that used to be synthesized.
2019-10-02 14:38:40 -07:00
Ben Langmuir
81e46c7c46 [test] Flip the default value of allowUnexpectedNotification
This is/was mostly useful for testing specific notification
interactions. Most new tests shouldn't need it, so remove the
boilerplate.
2019-10-01 22:30:58 -07:00
Ben Langmuir
b3a89f9491 Remove testable imports of LanguageServerProtocol 2019-08-08 22:00:38 -07:00
Marcin Krzyzanowski
ea6d01d95f Remove unused Language.unknown from tests 2019-07-16 18:52:52 +02:00
Marcin Krzyzanowski
4376582b0f Remove language decoding check - no longer relevant 2019-07-16 13:35:58 +02:00
Marcin Krzyzanowski
fb2d4d14b8 Embrace Swift.Result in place SwiftPM.Basic.Result 2019-06-10 11:24:53 +02:00
Ben Langmuir
af05e94bb0 [test] Update generated files with new toolchain 2019-01-23 11:17:16 -08:00
Ben Langmuir
b3b9b243fb [test] Add test for DiagnosticCode serialization 2018-12-12 19:45:18 -08:00