dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.92k stars 4.02k forks source link

Simplifier.ReduceAsync method does not return, waits forever #69178

Open sapsari opened 1 year ago

sapsari commented 1 year ago

Trying to call Simplifier.ReduceAsync method inside CompletionProvider.GetChangeAsync method , in a Visual Studio extension. Simplifier.ReduceAsync hangs and does not respond.

Version Used: Roslyn binaries are version 4.3.1

Requirements: Visual Studio 2022 and Visual Studio extension development workload

Steps to Reproduce:

  1. Get repo https://github.com/sapsari/BugReportProjectForRoslynReduceAsync
  2. Reset Visual Studio experimental instance (C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2022\Microsoft Visual Studio SDK\Tools\Reset the Visual Studio 2022 Experimental Instance.lnk)
  3. Open solution, build project, run project.
  4. With VS_exp, open same solution. Then open file SampleCode.cs
  5. Type something inside body of method Test. Intellisense/CodeCompletion popup should appear with options "System.IO.Directory","System.IO.File" and "System.IO.Path". (If not, wait for a minute, extension should be loading in the background)
  6. Select one option and press Enter key.
  7. At this point Simplifier.ReduceAsync is being called, and causing Visual Studio to hang

Expected Behavior: Simplifier.ReduceAsync to return "File" (with param newText="System.IO.File")

Actual Behavior: Simpifier.ReduceAsync fails to return anything. But can be cancelled though.

https://github.com/dotnet/roslyn/assets/700243/559657f8-2a33-4ada-9060-67ad3727284a

sapsari commented 1 year ago

Also if you set TEST_REDUCE_ASYNC = false in the source code, meaning you don't call Simplifier.ReduceAsync anymore, and everything works fine.

And copy-pasted GetSimplifiedTypeNameAsync method from https://github.com/dotnet/roslyn/blob/2a594fa2157a734a988f7b5dbac99484781599bd/src/Features/Core/Portable/Snippets/SnippetFunctionService.cs#L38