Commit Graph

43 Commits

Author SHA1 Message Date
Alex Hoppen
2305dfab7a Don't escape slashes in various JSONEncoders
This makes the JSON easier to work with, especially for paths.
2025-03-03 07:55:09 -08:00
Matthew Bastien
d0a10dee87 clean up unnecessary commas 2025-01-17 15:40:43 -05:00
Matthew Bastien
bf8e86f752 add encoding and decoding tests 2025-01-17 11:11:55 -05:00
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
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
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
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
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
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
Owen Voorhees
77a81ad9c1 Expose diagnostic educational notes as diagnostic codes 2020-11-09 18:30:02 -08: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
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
Ben Langmuir
b3b9b243fb [test] Add test for DiagnosticCode serialization 2018-12-12 19:45:18 -08:00
Ben Langmuir
31ac957edc [test] Add tests for LSP Language properties and serialization 2018-12-12 19:45:18 -08:00
Abdullah Selek
e73dac558c Use Void over () on Tests files. 2018-12-08 18:32:44 +00:00
Ben Langmuir
740ccb9a1d [gardening] Remove unnecessary url: label from TextDocumentIdentifier 2018-12-07 17:30:04 -08:00
Ben Langmuir
13095fab99 [test] Remove defunct static var allTests everywhere
When we started managing the Linux test lists with the
`--generate-linuxmain` option to swiftpm, these all became dead code.
2018-12-06 09:58:35 -08:00
Ben Langmuir
048d72b163 Upgrade SwiftPM dependency to master branch
We are tied to using a SwiftPM that matches the toolchain, so upgrade
from 0.3.0 to .branch("master") and add a pins file to manage updating
that dependency.

This was driven by changes that broke loading packages being developed
with newer version of SwiftPM when using the 0.3.0 tag of libSwiftPM.
However, the changes seem to work when going in the other direction, so
using the newer libSwiftPM hasn't caused any known regressions for using
older toolchain versions (not guarantteed and not tested extensively
though).

This fixes using the latest (November 13) toolchain snapshot on macOS.
On Linux there are other issues not specific to LSP.
2018-11-16 15:11:38 -08:00
Ben Langmuir
aabf57a252 Import SourceKit-LSP sources 2018-11-13 15:50:48 -08:00