Skip to content

Conversation

dibarbet
Copy link
Member

@dibarbet dibarbet commented Jul 8, 2025

Resolves dotnet/vscode-csharp#8400

VSCode normalizes URIs and always uses the URI based on when the file was first opened (even if it is renamed to change casing). See microsoft/vscode-languageserver-node#1186. So VSCode sends the server a URI that may not match the casing of file on disk.

While we already ignore casing when looking up file paths in the workspace (and therefore find the correct document in the workspace for requests), we had an issue with diagnostics when checking if the file was open. We were comparing a URI created from the file with the URI VSCode sends us. With UNC URIs (windows file paths), case sensitivity is ignored when comparing paths, and so it doesn't matter. However with unix file paths, case sensitivity is not ignored and so the file path URI and VSCode open URI did not match.

The fix here is to instead use the request URI we were given to check if the document is open, instead of attempting to derive it from the file path.

@dibarbet dibarbet force-pushed the diagnostics_casing branch from c59fb07 to f6d4d97 Compare July 8, 2025 22:21
@dibarbet dibarbet changed the title Add test demonstrating issue Fix document diagnostics document open check Jul 8, 2025
@dibarbet dibarbet force-pushed the diagnostics_casing branch 2 times, most recently from b79547c to 5f1e719 Compare July 9, 2025 00:16
@dibarbet dibarbet force-pushed the diagnostics_casing branch from 5f1e719 to 805447c Compare July 9, 2025 00:20
{
context.TraceDebug("Ignoring diagnostics request because no text document was provided");
return new([]);
}

if (!context.IsTracking(textDocument.GetURI()))
Copy link
Member Author

@dibarbet dibarbet Jul 9, 2025

Choose a reason for hiding this comment

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

this was the issue - for non-unc paths it does a case sensitive comparison, so the URI created from the file path on disk did not match the opened URI (vscode normalizes it).

instead we use the request uri which per the LSP spec must be consistent with the open URI

}

return new([]);
return new([new DocumentDiagnosticSource(kind, context.GetRequiredDocument())]);
Copy link
Member Author

@dibarbet dibarbet Jul 9, 2025

Choose a reason for hiding this comment

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

the AbstractDocumentPullDiagnosticHandler.cs code above already verifies that the document is tracked. No need to do it again.

@dibarbet dibarbet marked this pull request as ready for review July 9, 2025 00:23
@dibarbet dibarbet requested a review from a team as a code owner July 9, 2025 00:23
var textDocument = context.TextDocument;
if (textDocument is null)
var identifier = GetTextDocumentIdentifier(diagnosticsParams);
if (identifier is null || context.Document is null)
{
context.TraceDebug("Ignoring diagnostics request because no text document was provided");
return new([]);
}
Copy link
Member

Choose a reason for hiding this comment

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

consider breaking this into two checks for better tra ing.

@dibarbet dibarbet merged commit 3635db8 into dotnet:main Jul 9, 2025
25 checks passed
@dibarbet dibarbet deleted the diagnostics_casing branch July 9, 2025 16:34
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Jul 9, 2025
@RikkiGibson RikkiGibson modified the milestones: Next, 18.0 P1 Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issue when file opened in workspace/folder (even when closed) is renamed to have different capitalisation
4 participants