dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.85k stars 670 forks source link

"Request textDocument/onTypeFormatting failed" when editing Razor file #5569

Closed random-pixels closed 1 year ago

random-pixels commented 1 year ago

Issue Description

When editing a Razor document, get constant popups "Request textDocument/onTypeFormatting failed." When I click the "Go to output" button, I see the following errors logged:


Razor.VSCode version 7.0.0-preview.23067.5

Razor's trace level is currently set to 'Off'

  • To change Razor's trace level set 'razor.trace' to 'Off', 'Messages' or 'Verbose' and then restart VSCode.
  • To report issues invoke the 'Report a Razor issue' command via the command palette.

[Error - 11:02:58 a.m.] [null] [Error - 11:05:13 a.m.] [null] [Error - 11:05:13 a.m.] Request textDocument/onTypeFormatting failed. Message: Unhandled method textDocument/onTypeFormatting Code: -32000 [object Object] [Error - 11:05:16 a.m.] [null] [Error - 11:05:16 a.m.] Request textDocument/onTypeFormatting failed. Message: Unhandled method textDocument/onTypeFormatting Code: -32000 [object Object]

Steps to Reproduce

With Csharp extension 1.25.4 installed, create a new MVC Web Application. Then just edit the Index.cshtml file by typing or pasting some code in. Any keypress results in the popup.

Expected Behavior

No errors when typing

Actual Behavior

Error when typing

Logs

OmniSharp log

Starting OmniSharp server at 2023-02-02, 10:25:28 a.m. Target: /home/-/Programming/VSCode Projects/SignalR/SignalRSample OmniSharp server started with .NET 6.0.113 . Path: /home/-/.vscode/extensions/ms-dotnettools.csharp-1.25.4-linux-x64/.omnisharp/1.39.4-net6.0/OmniSharp.dll PID: 10113 [info]: OmniSharp.Stdio.Host Starting OmniSharp on Unknown 0.0 (Unknown) [info]: OmniSharp.Services.DotNetCliService Checking the 'DOTNET_ROOT' environment variable to find a .NET SDK [info]: OmniSharp.Services.DotNetCliService DotNetPath set to /usr/lib/dotnet/dotnet [info]: OmniSharp.MSBuild.Discovery.MSBuildLocator Located 1 MSBuild instance(s) 1: .NET Core SDK 6.0.113 17.0.1 - "/usr/lib/dotnet/sdk/6.0.113/" [info]: OmniSharp.MSBuild.Discovery.MSBuildLocator Registered MSBuild instance: .NET Core SDK 6.0.113 17.0.1 - "/usr/lib/dotnet/sdk/6.0.113/" [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0 [info]: OmniSharp.Cake.CakeProjectSystem Detecting Cake files in '/home/-/Programming/VSCode Projects/SignalR/SignalRSample'. [info]: OmniSharp.Cake.CakeProjectSystem Did not find any Cake files [info]: OmniSharp.MSBuild.ProjectSystem No solution files found in '/home/-/Programming/VSCode Projects/SignalR/SignalRSample' [info]: OmniSharp.MSBuild.ProjectManager Queue project update for '/home/-/Programming/VSCode Projects/SignalR/SignalRSample/SignalRSample.csproj' [info]: OmniSharp.Script.ScriptProjectSystem Detecting CSX files in '/home/-/Programming/VSCode Projects/SignalR/SignalRSample'. [info]: OmniSharp.Script.ScriptProjectSystem Did not find any CSX files [info]: OmniSharp.WorkspaceInitializer Configuration finished. [info]: OmniSharp.Stdio.Host Omnisharp server running using Stdio at location '/home/-/Programming/VSCode Projects/SignalR/SignalRSample' on host 9924. [info]: OmniSharp.MSBuild.ProjectManager Loading project: /home/-/Programming/VSCode Projects/SignalR/SignalRSample/SignalRSample.csproj [info]: OmniSharp.MSBuild.ProjectManager Successfully loaded project file '/home/-/Programming/VSCode Projects/SignalR/SignalRSample/SignalRSample.csproj'. [info]: OmniSharp.MSBuild.ProjectManager Adding project '/home/-/Programming/VSCode Projects/SignalR/SignalRSample/SignalRSample.csproj' [info]: OmniSharp.MSBuild.ProjectManager Update project: SignalRSample Received response for /v2/getcodeactions but could not find request. Received response for /completion/resolve but could not find request. [warn]: OmniSharp.Roslyn.CSharp.Services.Navigation.FindUsagesService No symbol found. File: /home/-/Programming/VSCode Projects/SignalR/SignalRSample/StaticDetails.cs, Line: 6, Column: 0. [warn]: OmniSharp.Roslyn.CSharp.Services.Navigation.FindUsagesService No symbol found. File: /home/-/Programming/VSCode Projects/SignalR/SignalRSample/StaticDetails.cs, Line: 6, Column: 0. [warn]: OmniSharp.Roslyn.CSharp.Services.Navigation.FindUsagesService No symbol found. File: /home/-/Programming/VSCode Projects/SignalR/SignalRSample/StaticDetails.cs, Line: 6, Column: 0. [warn]: OmniSharp.Roslyn.CSharp.Services.Navigation.FindUsagesService No symbol found. File: /home/-/Programming/VSCode Projects/SignalR/SignalRSample/StaticDetails.cs, Line: 6, Column: 0. [warn]: OmniSharp.Roslyn.CSharp.Services.Navigation.FindUsagesService No symbol found. File: /home/-/Programming/VSCode Projects/SignalR/SignalRSample/StaticDetails.cs, Line: 6, Column: 0. Received response for /v2/getcodeactions but could not find request. Received response for /completion/resolve but could not find request. Received response for /completion/resolve but could not find request. [warn]: OmniSharp.Roslyn.CSharp.Services.Navigation.FindUsagesService No symbol found. File: /home/-/Programming/VSCode Projects/SignalR/SignalRSample/StaticDetails.cs, Line: 7, Column: 0. [warn]: OmniSharp.Roslyn.CSharp.Services.Navigation.FindUsagesService No symbol found. File: /home/-/Programming/VSCode Projects/SignalR/SignalRSample/StaticDetails.cs, Line: 7, Column: 0. [warn]: OmniSharp.Roslyn.CSharp.Services.Navigation.FindUsagesService No symbol found. File: /home/-/Programming/VSCode Projects/SignalR/SignalRSample/StaticDetails.cs, Line: 8, Column: 0. Received response for /completion/resolve but could not find request. Received response for /v2/getcodeactions but could not find request. Received response for /v2/getcodeactions but could not find request. Received response for /v2/getcodeactions but could not find request. Received response for /completion/resolve but could not find request. [warn]: OmniSharp.Roslyn.CSharp.Services.Navigation.FindUsagesService No symbol found. File: /home/-/Programming/VSCode Projects/SignalR/SignalRSample/StaticDetails.cs, Line: 15, Column: 39. [warn]: OmniSharp.Stdio.Host ************ Request ************ { "Type": "request", "Seq": 1891, "Command": "/close", "Arguments": { "FileName": "/home/-/Programming/VSCode Projects/SignalR/SignalRSample/Views/Home/Index.cshtml__virtual.cs" } } [fail]: OmniSharp.Stdio.Host ************ Response (9.2403ms) ************ { "Request_seq": 1891, "Command": "/close", "Running": true, "Success": false, "Message": "\"System.ArgumentException: 'Index.cshtml__bg__virtual.cs' is not open.\\n at Microsoft.CodeAnalysis.Workspace.CheckDocumentIsOpen(DocumentId documentId)\\n at Microsoft.CodeAnalysis.Workspace.<>c.b__199_0(Solution oldSolution, ValueTuple`4 data)\\n at Microsoft.CodeAnalysis.Workspace.SetCurrentSolution[TData](Func`3 transformation, TData data, Action`3 onBeforeUpdate, Action`3 onAfterUpdate)\\n at Microsoft.CodeAnalysis.Workspace.OnDocumentClosed(DocumentId documentId, TextLoader reloader, Boolean updateActiveContext)\\n at OmniSharp.OmniSharpWorkspace.CloseDocument(DocumentId documentId) in /home/vsts/work/1/s/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs:line 106\\n at OmniSharp.Roslyn.CSharp.Services.Files.FileCloseService.Handle(FileCloseRequest request) in /home/vsts/work/1/s/src/OmniSharp.Roslyn.CSharp/Services/Files/FileCloseService.cs:line 25\\n at OmniSharp.Endpoint.EndpointHandler`2.AggregateResponsesFromLanguageHandlers(ExportHandler`2[] handlers, TRequest request) in /home/vsts/work/1/s/src/OmniSharp.Host/Endpoint/EndpointHandler.cs:line 190\\n at OmniSharp.Endpoint.EndpointHandler`2.HandleRequestForLanguage(String language, TRequest request, RequestPacket packet) in /home/vsts/work/1/s/src/OmniSharp.Host/Endpoint/EndpointHandler.cs:line 233\\n at OmniSharp.Endpoint.EndpointHandler`2.Process(RequestPacket packet, LanguageModel model, JToken requestObject) in /home/vsts/work/1/s/src/OmniSharp.Host/Endpoint/EndpointHandler.cs:line 142\\n at OmniSharp.Stdio.Host.HandleRequest(String json, ILogger logger) in /home/vsts/work/1/s/src/OmniSharp.Stdio/Host.cs:line 258\"", "Body": null, "Seq": 28491, "Type": "response" } [warn]: OmniSharp.Stdio.Host ************ Request ************ { "Type": "request", "Seq": 1905, "Command": "/close", "Arguments": { "FileName": "/home/-/Programming/VSCode Projects/SignalR/SignalRSample/Views/Home/Index.cshtml__virtual.cs" } } [fail]: OmniSharp.Stdio.Host ************ Response (0.8935ms) ************ { "Request_seq": 1905, "Command": "/close", "Running": true, "Success": false, "Message": "\"System.ArgumentException: 'Index.cshtml__virtual.cs' is not open.\\n at Microsoft.CodeAnalysis.Workspace.CheckDocumentIsOpen(DocumentId documentId)\\n at Microsoft.CodeAnalysis.Workspace.<>c.b__199_0(Solution oldSolution, ValueTuple`4 data)\\n at Microsoft.CodeAnalysis.Workspace.SetCurrentSolution[TData](Func`3 transformation, TData data, Action`3 onBeforeUpdate, Action`3 onAfterUpdate)\\n at Microsoft.CodeAnalysis.Workspace.OnDocumentClosed(DocumentId documentId, TextLoader reloader, Boolean updateActiveContext)\\n at OmniSharp.OmniSharpWorkspace.CloseDocument(DocumentId documentId) in /home/vsts/work/1/s/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs:line 106\\n at OmniSharp.Roslyn.CSharp.Services.Files.FileCloseService.Handle(FileCloseRequest request) in /home/vsts/work/1/s/src/OmniSharp.Roslyn.CSharp/Services/Files/FileCloseService.cs:line 25\\n at OmniSharp.Endpoint.EndpointHandler`2.AggregateResponsesFromLanguageHandlers(ExportHandler`2[] handlers, TRequest request) in /home/vsts/work/1/s/src/OmniSharp.Host/Endpoint/EndpointHandler.cs:line 190\\n at OmniSharp.Endpoint.EndpointHandler`2.HandleRequestForLanguage(String language, TRequest request, RequestPacket packet) in /home/vsts/work/1/s/src/OmniSharp.Host/Endpoint/EndpointHandler.cs:line 233\\n at OmniSharp.Endpoint.EndpointHandler`2.Process(RequestPacket packet, LanguageModel model, JToken requestObject) in /home/vsts/work/1/s/src/OmniSharp.Host/Endpoint/EndpointHandler.cs:line 142\\n at OmniSharp.Stdio.Host.HandleRequest(String json, ILogger logger) in /home/vsts/work/1/s/src/OmniSharp.Stdio/Host.cs:line 258\"", "Body": null, "Seq": 30696, "Type": "response" }

C# log

(empty)

Environment information

VSCode version: 1.74.3 C# Extension: 1.25.4

Mono Information There is a problem with running OmniSharp on mono: Error: Unable to find Mono. Ensure that Mono's '/bin' folder is added to your environment's PATH variable.
Dotnet Information .NET SDK (reflecting any global.json): Version: 6.0.113 Commit: 4a23b50f97 Runtime Environment: OS Name: linuxmint OS Version: 21.1 OS Platform: Linux RID: ubuntu.22.04-x64 Base Path: /usr/lib/dotnet/sdk/6.0.113/ global.json file: Not found Host: Version: 6.0.13 Architecture: x64 Commit: 1af80ba017 .NET SDKs installed: 6.0.113 [/usr/lib/dotnet/sdk] .NET runtimes installed: Microsoft.AspNetCore.App 6.0.13 [/usr/lib/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.13 [/usr/lib/dotnet/shared/Microsoft.NETCore.App] Download .NET: https://aka.ms/dotnet-download Learn about .NET Runtimes and SDKs: https://aka.ms/dotnet/runtimes-sdk-info
Visual Studio Code Extensions |Extension|Author|Version| |---|---|---| |brackets-light-pro|fehey|0.4.6| |cpptools-themes|ms-vscode|2.0.0| |csharp|ms-dotnettools|1.25.4| |dotnet-test-explorer|formulahendry|0.7.8| |github-plus-theme|thenikso|1.4.3| |gitlens|eamodio|13.2.0| |isort|ms-python|2022.8.0| |jupyter|ms-toolsai|2022.11.1003412109| |jupyter-keymap|ms-toolsai|1.0.0| |jupyter-renderers|ms-toolsai|1.0.14| |php-debug|xdebug|1.31.0| |python|ms-python|2022.20.2| |ruby|rebornix|0.28.1| |sqltools|mtxr|0.27.1| |sqltools-driver-mysql|mtxr|0.5.1| |vscode-icon-theme|jtlowe|1.6.6| |vscode-icons|vscode-icons-team|12.2.0| |vscode-intelephense-client|bmewburn|1.9.4| |vscode-jupyter-cell-tags|ms-toolsai|0.1.6| |vscode-jupyter-slideshow|ms-toolsai|0.1.5| |vscode-pull-request-github|GitHub|0.56.0| |vscode-pylance|ms-python|2023.2.10| |vscode-ruby|wingrunr21|0.28.0|;

Additional Information

May be related to https://github.com/OmniSharp/omnisharp-vscode/issues/5561

tkoenig89 commented 1 year ago

My colleagues and i are experiencing the same issue. We rolled back to version 1.25.2 of the extension which can format razor pages properly.

As the update to v1.25.4 came close to our migration to .Net 7 we are not sure what exactly caused the issue.

(probably a duplicate of #5561)

random-pixels commented 1 year ago

(probably a duplicate of #5561)

I mentioned in my original post that it could be related to #5561. Definitely not a duplicate, as steps to reproduce, symptoms, and actual error message are different.

elishnevsky commented 1 year ago

I confirm the presence of this bug. Had to roll back to v1.25.2.

dibarbet commented 1 year ago

Closing as dupe of https://github.com/OmniSharp/omnisharp-vscode/issues/5561