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.91k stars 4.01k forks source link

Unable to extract method that includes a "return" #47135

Open davkean opened 4 years ago

davkean commented 4 years ago

Version Used:

Version 16.8.0 Preview 3.0 [30425.163.main]

Steps to Reproduce:

Highlight between the $$$ and CTRL+.

The exact code is here: https://github.com/dotnet/project-system/blob/b450eb548e2ff1f7e94e9b5f392590ad15886957/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Rename/RenamerProjectTreeActionHandler.cs#L112-L123.

public void Method()
{                
$$$
               // TODO - implement PublishAsync() to sync with LanguageService
                // https://github.com/dotnet/project-system/issues/3425)
                // await _languageService.PublishAsync(treeVersion);
                IVsOperationProgressStageStatus stageStatus = (await _operationProgressService.GetValueAsync()).GetStageStatus(CommonOperationProgressStageIds.Intellisense);
                await stageStatus.WaitForCompletionAsync();

                // Apply actions and notify other VS features
                CodeAnalysis.Solution? currentSolution = GetCurrentProject()?.Solution;
                if (currentSolution == null)
                {
                    return;
                }
$$$
}

Expected Behavior: To be offerred to Extract Method/Extract Local Function

Actual Behavior: No refactorings, if I remove the bottom if from the selection then I'm offered the fix.

davkean commented 4 years ago

I would prefer to be left with invalid code than not to be offered this refactoring.

CyrusNajmabadi commented 4 years ago

I'd definitely like this. Perhaps allow EM, but with a warning that we went be able to preserve semantics.

This has been a long-standing request/deficiency here.

jinujoseph commented 4 years ago

cc @ryzngard