-
Notifications
You must be signed in to change notification settings - Fork 417
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1406 from savpek/feature/codeactions-with-options
Codeactions with options/ui.
- Loading branch information
Showing
12 changed files
with
461 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/OmniSharp.Roslyn/WorkspaceServices/ExtractInterfaceWorkspaceService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis; | ||
|
||
namespace OmniSharp | ||
{ | ||
public class ExtractInterfaceWorkspaceService : DispatchProxy | ||
{ | ||
protected override object Invoke(MethodInfo targetMethod, object[] args) | ||
{ | ||
// IExtractInterfaceOptionsService and extract interface results are internal types -> workaround with proxy. | ||
// This service simply passes all members through as selected and doesn't try show UI. | ||
// When roslyn exposes this interface and members -> remove this workaround. | ||
var resultTypeInternal = Assembly.Load("Microsoft.CodeAnalysis.Features").GetType("Microsoft.CodeAnalysis.ExtractInterface.ExtractInterfaceOptionsResult"); | ||
var enumType = resultTypeInternal.GetNestedTypes().Single(x => x.Name == "ExtractLocation"); | ||
|
||
var toSameFileEnumValue = Enum.Parse(enumType, "SameFile"); | ||
|
||
var interfaceName = args[3] ?? throw new InvalidOperationException($"{nameof(ExtractInterfaceWorkspaceService)} default interface name was null."); | ||
|
||
var resultObject = Activator.CreateInstance(resultTypeInternal, new object[] { | ||
false, // isCancelled | ||
((List<ISymbol>)args[2]).ToImmutableArray(), // InterfaceMembers selected -> select all. | ||
interfaceName, | ||
$"{interfaceName}.cs", | ||
toSameFileEnumValue | ||
}); | ||
|
||
return typeof(Task).GetMethod("FromResult").MakeGenericMethod(resultTypeInternal).Invoke(null, new[] { resultObject }); | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/OmniSharp.Roslyn/WorkspaceServices/ExtractInterfaceWorkspaceServiceFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.Composition; | ||
using System.Reflection; | ||
using Microsoft.CodeAnalysis.Host; | ||
using Microsoft.CodeAnalysis.Host.Mef; | ||
|
||
namespace OmniSharp | ||
{ | ||
[Shared] | ||
[ExportWorkspaceServiceFactoryWithAssemblyQualifiedName("Microsoft.CodeAnalysis.Features", "Microsoft.CodeAnalysis.ExtractInterface.IExtractInterfaceOptionsService")] | ||
public class ExtractInterfaceWorkspaceServiceFactory : IWorkspaceServiceFactory | ||
{ | ||
public IWorkspaceService CreateService(HostWorkspaceServices workspaceServices) | ||
{ | ||
// Generates proxy class to get around issue that IExtractInterfaceOptionsService is internal at this point. | ||
var internalType = Assembly.Load("Microsoft.CodeAnalysis.Features").GetType("Microsoft.CodeAnalysis.ExtractInterface.IExtractInterfaceOptionsService"); | ||
return (IWorkspaceService)typeof(DispatchProxy).GetMethod(nameof(DispatchProxy.Create)).MakeGenericMethod(internalType, typeof(ExtractInterfaceWorkspaceService)).Invoke(null, null); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/OmniSharp.Roslyn/WorkspaceServices/PickMemberWorkspaceService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Reflection; | ||
|
||
namespace OmniSharp | ||
{ | ||
public class PickMemberWorkspaceService : DispatchProxy | ||
{ | ||
protected override object Invoke(MethodInfo targetMethod, object[] args) | ||
{ | ||
// IPickMember and PickMemberResults are internal types -> workaround with proxy. | ||
// This service simply passes all members through as selected and doesn't try show UI. | ||
// When roslyn exposes this interface and members -> remove this workaround. | ||
var resultTypeInternal = Assembly.Load("Microsoft.CodeAnalysis.Features").GetType("Microsoft.CodeAnalysis.PickMembers.PickMembersResult"); | ||
return Activator.CreateInstance(resultTypeInternal, new object[] { args[1], args[2] }); | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/OmniSharp.Roslyn/WorkspaceServices/PickMemberWorkspaceServiceFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.Composition; | ||
using System.Reflection; | ||
using Microsoft.CodeAnalysis.Host; | ||
using Microsoft.CodeAnalysis.Host.Mef; | ||
|
||
namespace OmniSharp | ||
{ | ||
[Shared] | ||
[ExportWorkspaceServiceFactoryWithAssemblyQualifiedName("Microsoft.CodeAnalysis.Features", "Microsoft.CodeAnalysis.PickMembers.IPickMembersService")] | ||
public class PickMemberWorkspaceServiceFactory : IWorkspaceServiceFactory | ||
{ | ||
public IWorkspaceService CreateService(HostWorkspaceServices workspaceServices) | ||
{ | ||
// Generates proxy class to get around issue that IPickMembersService is internal at this point. | ||
var internalType = Assembly.Load("Microsoft.CodeAnalysis.Features").GetType("Microsoft.CodeAnalysis.PickMembers.IPickMembersService"); | ||
return (IWorkspaceService)typeof(DispatchProxy).GetMethod(nameof(DispatchProxy.Create)).MakeGenericMethod(internalType, typeof(PickMemberWorkspaceService)).Invoke(null, null); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.