Skip to content

Update request and notification definitions to LSP 3.17 #669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 4, 2022

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Nov 24, 2022

This updates the definitions of the requests and notifications to match version 3.17 of the LSP spec

rdar://83833293

@ahoppen ahoppen requested a review from benlangmuir as a code owner November 24, 2022 05:58
@ahoppen
Copy link
Member Author

ahoppen commented Nov 24, 2022

@swift-ci Please test

@@ -431,7 +431,7 @@ extension ClangLanguageServerShim {
// with `forceRebuild` set in case any missing header files have been added.
// This works well for us as the moment since clangd ignores the document version.
let note = DidChangeTextDocumentNotification(
textDocument: VersionedTextDocumentIdentifier(uri, version: nil),
textDocument: VersionedTextDocumentIdentifier(uri, version: 0),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version number is supposed to always increment, so reseting to 0 seems odd. Should we use OptionalVersioned... instead and keep nil?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering about this one as well. DidChangeTextDocumentNotification is supposed to take VersionedTextDocumentIdentifier and not OptionalVersionedTextDocumentIdentifier but apparently clangd has been handling this just fine so far… So maybe you’re right that the cleanest solution is if we just relax our LSP definition here… I still don’t like it though…

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well that's fun. In theory this means the 3.16+ spec is not backwards compatible with 3.15 and earlier for DidChangeTextDocument. But the documentation for null version is a bit vague in earlier specs and the authors say the intent is that in client to server communication it is never null (ie only allowed null for a server to client message), so what we were doing before is a bug I guess since we're the client in this scenario. I'm okay with using 0 since clangd handles it 🤷

Copy link
Member Author

@ahoppen ahoppen Dec 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up adding a test case: fa9b5f9. It appears to work fine.

/// The server cancelled the request. This error code should
/// only be used for requests that explicitly support being
/// server cancellable.
public static let ServerCancelled = ErrorCode(rawValue: -32802)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We return cancelled in places that are not client-canceled, so we should probably update those. Doesn't have to be for this PR though.

@benlangmuir
Copy link
Contributor

All the new request/notification types need to be added to the builtin message lists in Messages.swift or they won't decode correctly.

@ahoppen ahoppen force-pushed the ahopppen/update-lsp branch from e6293e2 to 7a723d0 Compare November 29, 2022 11:13
@ahoppen
Copy link
Member Author

ahoppen commented Nov 29, 2022

@swift-ci Please test

case end(WorkDoneProgressEnd)
}

public var state: State
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious: could WorkDoneProgress itself be the enum, or does that not work? I'm fine with it either way.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, good idea. I didn’t think of that.

@ahoppen ahoppen force-pushed the ahopppen/update-lsp branch from 7a723d0 to 93a8f91 Compare December 1, 2022 09:44
@ahoppen
Copy link
Member Author

ahoppen commented Dec 1, 2022

@swift-ci Please test

1 similar comment
@ahoppen
Copy link
Member Author

ahoppen commented Dec 2, 2022

@swift-ci Please test

@ahoppen ahoppen force-pushed the ahopppen/update-lsp branch from 2fe1928 to cf65abd Compare December 2, 2022 08:51
…lang

We weren’t sure if it works because it always sends 0 as the document’s version number, but everythig appears to be fine.
@ahoppen
Copy link
Member Author

ahoppen commented Dec 3, 2022

@swift-ci Please test

@ahoppen ahoppen merged commit 595acfa into swiftlang:main Dec 4, 2022
@ahoppen ahoppen deleted the ahopppen/update-lsp branch December 4, 2022 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants