Fix URI handling when comparing encoded and unencoded URIs #74544
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves dotnet/vscode-csharp#5843
This is a 'fun' one.
Essentially the issue happened when the original didOpen for a document was received with an unencoded URI, but a followup request (for a xxx/resolve) passed in the encoded URI.
Unencoded URI:
Encoded URI:
Generally, clients are expected to be consistent when passing URIs to the server (always give the same encoded or unencoded version), see https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#uri
This is still true.
However, the issue came when roundtripping URIs sent by the server. Consider the following scenario
textDocument/didOpen
with unencoded URItextDocument/codelens
for the unencoded URISystem.Uri.AbsoluteUri
.The AbsoluteUri is always the encoded URI, so the codelens data contains the encoded URI.
roslyn/src/LanguageServer/Protocol/Protocol/Converters/DocumentUriConverter.cs
Line 20 in 9177306
codelens/resolve
request without touching the data (expected, its opaque to the client).codelens/resolve
request - butSystem.Uri.Equals
does not consider the encoded and unencoded URIs to be equal. This fails the request because we can't find the information from the priortextDocument/didOpen
associated with it.To fix this issue where the server cannot match the request for the encoded Uri to the unencoded version I considered a couple of paths
OriginalString
property instead of theAbsoluteUri
propertyIn this PR I chose 1. I don't believe 2 is the correct solution - the
OriginalString
is not always a valid URI depending on how the URI is created. For the generic LSP library converter, it cannot assume that theUri
object has a valid uri-formatted value inOriginalString
(note that this change was attempted before back when we used the VS LSP libraries, and had to be reverted).