Skip to content
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

C# extension continuosly errors while viewing/scrolling a diff of two csharp files. #6256

Open
makzimus opened this issue Aug 30, 2023 · 12 comments

Comments

@makzimus
Copy link

makzimus commented Aug 30, 2023

Type: Bug

Issue Description

When diffing a csharp file the extension will continuously spam 2 errors while scrolling:

Request textDocument/inlayHint failed
Request textDocument/semanticTokens/range failed.

Steps to Reproduce

  • Diff 2 csharp files (I used the perforce SCM extension to show a diff in this case).
  • Scroll the diff.

Expected Behavior

No errors.

Actual Behavior

Errors appear.

Logs

C# log

[Error - 2:21:04 PM] Request textDocument/inlayHint failed. Message: Invalid URI: The hostname could not be parsed. Code: -32000 [object Object] [Error - 2:21:04 PM] Request textDocument/semanticTokens/range failed. Message: Invalid URI: The hostname could not be parsed. Code: -32000 [object Object] [Error - 2:21:04 PM] Request textDocument/inlayHint failed. Message: Invalid URI: The hostname could not be parsed. Code: -32000 [object Object] [Error - 2:21:04 PM] Request textDocument/semanticTokens/range failed. Message: Invalid URI: The hostname could not be parsed. Code: -32000 [object Object] Using dotnet configured on PATH

Environment information

VSCode version: 1.81.1
C# Extension: 2.0.416
Using OmniSharp: false

Visual Studio Code Extensions
Extension Author Version Folder Name
atlascode atlassian 3.0.5 atlassian.atlascode-3.0.5
cmake twxs 0.0.17 twxs.cmake-0.0.17
cmake-tools ms-vscode 1.15.31 ms-vscode.cmake-tools-1.15.31
comment-styler krembolabs 1.0.2 krembolabs.comment-styler-1.0.2
cpptools ms-vscode 1.17.5 ms-vscode.cpptools-1.17.5-win32-x64
csdevkit ms-dotnettools 0.3.21 ms-dotnettools.csdevkit-0.3.21-win32-x64
csharp ms-dotnettools 2.0.416 ms-dotnettools.csharp-2.0.416-win32-x64
githistory donjayamanne 0.6.20 donjayamanne.githistory-0.6.20
gitstash arturock 5.2.0 arturock.gitstash-5.2.0
godot-tools geequlim 1.3.1 geequlim.godot-tools-1.3.1
hexeditor ms-vscode 1.9.12 ms-vscode.hexeditor-1.9.12
isort ms-python 2023.10.1 ms-python.isort-2023.10.1
jgutility jg 1.0.0 jg.jgutility-1.0.0
json-escaper joshuapoehls 1.1.2 joshuapoehls.json-escaper-1.1.2
jsonpath-extract davidmarek 1.2.3 davidmarek.jsonpath-extract-1.2.3
jupyter-keymap ms-toolsai 1.1.2 ms-toolsai.jupyter-keymap-1.1.2
mono-debug ms-vscode 0.16.3 ms-vscode.mono-debug-0.16.3
partial-diff ryu1kn 1.4.3 ryu1kn.partial-diff-1.4.3
path-intellisense christian-kohler 2.8.4 christian-kohler.path-intellisense-2.8.4
perforce mjcrouch 4.15.7 mjcrouch.perforce-4.15.7
prettify-json mohsen1 0.0.3 mohsen1.prettify-json-0.0.3
project-manager alefragnani 12.7.0 alefragnani.project-manager-12.7.0
python ms-python 2023.4.0 ms-python.python-2023.4.0
remote-containers ms-vscode-remote 0.304.0 ms-vscode-remote.remote-containers-0.304.0
remote-explorer ms-vscode 0.4.1 ms-vscode.remote-explorer-0.4.1
remote-ssh ms-vscode-remote 0.102.0 ms-vscode-remote.remote-ssh-0.102.0
remote-ssh-edit ms-vscode-remote 0.86.0 ms-vscode-remote.remote-ssh-edit-0.86.0
remote-wsl ms-vscode-remote 0.81.0 ms-vscode-remote.remote-wsl-0.81.0
rest-client humao 0.25.1 humao.rest-client-0.25.1
todo-tree Gruntfuggly 0.0.226 gruntfuggly.todo-tree-0.0.226
vs-keybindings ms-vscode 0.2.1 ms-vscode.vs-keybindings-0.2.1
vscode-dotnet-runtime ms-dotnettools 1.7.1 ms-dotnettools.vscode-dotnet-runtime-1.7.1
vscode-gradle vscjava 3.12.7 vscjava.vscode-gradle-3.12.7
vscode-pylance ms-python 2023.8.40 ms-python.vscode-pylance-2023.8.40
vscode-yaml redhat 1.14.0 redhat.vscode-yaml-1.14.0
vscodeintellicode-csharp ms-dotnettools 0.1.26 ms-dotnettools.vscodeintellicode-csharp-0.1.26-win32-x64
vstuc visualstudiotoolsforunity 0.9.0 visualstudiotoolsforunity.vstuc-0.9.0
xml DotJoshJohnson 2.5.1 dotjoshjohnson.xml-2.5.1

Extension version: 2.0.416
VS Code version: Code 1.81.1 (6c3e3dba23e8fadc360aed75ce363ba185c49794, 2023-08-09T22:22:42.175Z)
OS version: Windows_NT x64 10.0.22621
Modes:

System Info
Item Value
CPUs 13th Gen Intel(R) Core(TM) i9-13900KS (32 x 3187)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) undefined
Memory (System) 31.77GB (4.27GB free)
Process Argv --crash-reporter-id 3813fa00-ad68-4b4c-be1e-46141697892d
Screen Reader no
VM 0%
A/B Experiments
vsliv368:30146709
vsreu685:30147344
python383cf:30185419
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263cf:30335440
vscorecescf:30445987
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593cf:30376535
pythonvs932:30410667
py29gd2263cf:30792227
vsclangdf:30486550
c4g48928:30535728
dsvsc012cf:30540253
pynewext54:30695312
azure-dev_surveyone:30548225
vscccc:30803845
2e4cg342:30602488
f6dab269:30613381
2i9eh265:30646982
showlangstatbar:30737416
0bi6i642:30823812
03d35959:30757346
57b77579:30736110
pythonfmttext:30731395
fixshowwlkth:30771522
showindicator:30805244
pythongtdpath:30769146
i26e3531:30792625
gsofa:30804715
pythonnosmt12:30797651
pythonidxpt:30805730
pythonnoceb:30805159
asynctok:30821568
dsvsc013:30795093
dsvsc014:30804076
diffeditorv2:30821572

@dibarbet
Copy link
Member

Looks like we're erroring creating URIs.

@makzimus could you set the 'dotnet.server.trace' setting to 'Trace' and attach the contents of the C# LSP trace logs? That should tell us what URI its throwing on.

Thanks!

@dibarbet dibarbet self-assigned this Aug 30, 2023
@dibarbet dibarbet added this to the September milestone Aug 30, 2023
@makzimus
Copy link
Author

Log file snippet:
csharp_lsp_trace.txt

@makzimus makzimus changed the title C# extension continously errors while viewing/scrolling a diff of two csharp files. C# extension continuosly errors while viewing/scrolling a diff of two csharp files. Aug 31, 2023
@dibarbet
Copy link
Member

dibarbet commented Sep 6, 2023

Thanks, I think the logs have enough info to fix. I'll take a look.

@dibarbet
Copy link
Member

dibarbet commented Sep 6, 2023

System.URI is throwing on these URIs as it tries to parse the URI Taking a look at the RFC spec (link), it looks like one of them should be valid, the other one is not

Taking a look at them one by one (minus the query parameters):
perforce://@=1454483/some/file/here/source.cs

Splitting it up into parts (using this ref) we have
perforce(scheme):(sep)//(begin hier-part)@=1454483(authority)/some/file/here/source.cs(path)

The authority is defined as [ userinfo "@" ] host [ ":" port ]. We have an empty userinfo followed by an @ followed by the host =1454483. Host is defined as IP-literal / IPv4address / reg-name. Our name is not an IP and fits neither an IP-Literal nor a IPv4address. The definition of reg-name is *( unreserved / pct-encoded / sub-delims ). = is a valid character in sub-delims and 1454483 are in unreserved so it appears this should be a valid URI. However, System.URI is throwing on this host name as it doesn't follow the URI RFC exactly. See dotnet/runtime#64707

Taking a look at perforce://%239/some/file/here/source.cs we can extract the host as before to be %239. This is pct-encoded (generally allowed in the host) followed by a 9. However I do not think this URI is valid as the spec states this:

URI producing applications must not use percent-encoding in host unless it is used to represent a UTF-8 character sequence.

Which '#' (what %23 represents) is not. Additionally, '#' is not part of 'sub-delims' and so wouldn't be valid to leave unencoded either.

@dibarbet
Copy link
Member

dibarbet commented Sep 6, 2023

Not sure there is much we can do here at the moment. For the first URI we need dotnet/runtime#64707, for the second I think you'd need to reach out to whichever extension is creating these URIs as I don't think it's valid.

@makzimus
Copy link
Author

A better behaviour might be to not use showErrorMessage for these types of errors, and instead just rely on logging. It is quite the experience having no way to mute the error notifications.

@garrettlondon1
Copy link

Trying to create DocumentContext for textDocument/semanticTokens/range for (no project context) for file:///c%3A/Components/Deal/Other/CreateDeal.razor
[Warn  - 7:23:06 PM] Could not create a document context for textDocument/semanticTokens/range for file:///c%3A/Components/Deal/Other/CreateDeal.razor. Endpoint may crash later if it calls GetRequiredDocumentContext.
[Error - 7:23:06 PM] System.ArgumentNullException: Value cannot be null. (Parameter 'DocumentContext')
   at Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts.RazorRequestContext.GetRequiredDocumentContext() in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/EndpointContracts/RazorRequestContext.cs:line 47
   at Microsoft.AspNetCore.Razor.LanguageServer.Semantic.SemanticTokensRangeEndpoint.HandleRequestAsync(SemanticTokensRangeParams request, RazorRequestContext requestContext, CancellationToken cancellationToken) in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Semantic/SemanticTokensRangeEndpoint.cs:line 71
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, CancellationToken cancellationToken)
[Error - 7:23:06 PM] Request textDocument/semanticTokens/range failed.
  Message: Value cannot be null. (Parameter 'DocumentContext')
  Code: -32000 
[object Object]

Getting the same, dozens of errors when scrolling a document

@dansoper
Copy link

I am experiencing this issue - using the GitLens extension - while scrolling in Diff view. I understand the comments above about the fix being required elsewhere, but please could you consider not alerting so many errors? It makes reviewing diffs very annoying!

Thanks.

@garrettlondon1
Copy link

At this point I don't care when the bugs get fixed I just want to be able to hide the error message from popping up.

@davidwengier any insight on this?

@davidwengier
Copy link
Contributor

This has nothing to do with me, but personally speaking I also think the toasts for every failed LSP request are annoying and wish they could be turned off or just didn't happen. I don't even know if that is possible though. I also agree with @dibarbet that if an extension is not sending valid URIs they should fix that. LSP is a pretty objectively URI based protocol.

@dibarbet
Copy link
Member

So two things -
@garrettlondon1 @davidwengier your issue is different from the one here - it looks like an error in the Razor language server not related to a URI parsing failure:

at Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts.RazorRequestContext.GetRequiredDocumentContext() in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/EndpointContracts/RazorRequestContext.cs:line 47

Could you file a separate issue on dotnet/razor?

Second thing is that for the original issue here, its actually not the extension that is creating the pop-up boxes. We error the request (because we don't know the URI), but then vscode's LSP client is the one actually creating the pop-up. I do not know of a way to prevent that, other than not erroring the request. But I'll leave this open so we can take a look.

@garrettlondon1
Copy link

Created an issue for the second point above here: #6977

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants