Skip to content

Commit 8a2329d

Browse files
committed
Filter unsupported actions
1 parent 51bdfc9 commit 8a2329d

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/RoslynWorkspaceAccess/RoslynWorkspaceAccessors.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using Microsoft.CodeAnalysis.CodeActions;
33
using Microsoft.CodeAnalysis.CodeFixes;
44
using Microsoft.CodeAnalysis.Diagnostics;
5+
using Microsoft.CodeAnalysis.ExtractClass;
6+
using Microsoft.CodeAnalysis.ExtractInterface;
57
using Microsoft.CodeAnalysis.GenerateType;
68
using Microsoft.CodeAnalysis.Host;
79
using Microsoft.CodeAnalysis.Host.Mef;
@@ -23,7 +25,20 @@ public static async Task<IEnumerable<CodeAction>> GetCodeActionsAsync(this Docum
2325
var codeFixService = document.Project.Solution.Services.ExportProvider.GetExports<ICodeFixService>().Single().Value;
2426
var fixes = await codeFixService.GetFixesAsync(document, span, cancellationToken);
2527
return fixes.Where(static c => c.Fixes.Length != 0)
26-
.SelectMany(static c => c.Fixes.Select(static f => f.Action));
28+
.SelectMany(static c => c.Fixes.Select(static f => f.Action))
29+
.Where(isSupportedCodeAction);
30+
31+
// https://github.com/dotnet/roslyn/blob/8aa0e2e2ccb66c8b0fe0e002d80a92e870304665/src/LanguageServer/Protocol/Handler/CodeActions/CodeActionHelpers.cs#L96
32+
static bool isSupportedCodeAction(CodeAction codeAction)
33+
{
34+
if ((codeAction is CodeActionWithOptions and not ExtractInterfaceCodeAction and not ExtractClassWithDialogCodeAction) ||
35+
codeAction.Tags.Contains(CodeAction.RequiresNonDocumentChange))
36+
{
37+
return false;
38+
}
39+
40+
return true;
41+
}
2742
}
2843

2944
public static DocumentTextDifferencingService GetDocumentTextDifferencingService(this SolutionServices services)

0 commit comments

Comments
 (0)