-
Notifications
You must be signed in to change notification settings - Fork 419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added an option to configure a code actions folder #848
Changes from 8 commits
ecbd327
71342f1
1c7ec8c
f51ad56
0df59c0
da1bdb6
7148e38
9ff5c31
5d9b63a
44dbde1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace OmniSharp.Options | ||
{ | ||
public class RoslynExtensionsOptions | ||
{ | ||
public string[] LocationPaths { get; set; } | ||
|
||
public IEnumerable<string> GetNormalizedLocationPaths(IOmniSharpEnvironment env) | ||
{ | ||
if (LocationPaths == null || LocationPaths.Length == 0) return Enumerable.Empty<string>(); | ||
|
||
var normalizePaths = new HashSet<string>(StringComparer.OrdinalIgnoreCase); | ||
foreach (var locationPath in LocationPaths) | ||
{ | ||
if (Path.IsPathRooted(locationPath)) | ||
{ | ||
normalizePaths.Add(locationPath); | ||
} | ||
else | ||
{ | ||
normalizePaths.Add(Path.Combine(env.TargetDirectory, locationPath)); | ||
} | ||
} | ||
|
||
return normalizePaths; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Composition; | ||
using OmniSharp.Services; | ||
|
||
namespace OmniSharp.Roslyn.CSharp.Services.CodeActions | ||
{ | ||
[Export(typeof(ICodeActionProvider))] | ||
public class ExternalCodeActionProvider : AbstractCodeActionProvider | ||
{ | ||
[ImportingConstructor] | ||
public ExternalCodeActionProvider(ExternalFeaturesHostServicesProvider featuresHostServicesProvider) | ||
: base("ExternalCodeActions", featuresHostServicesProvider.Assemblies) | ||
{ | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.Collections.Immutable; | ||
using System.Composition; | ||
using System.Reflection; | ||
using OmniSharp.Options; | ||
using OmniSharp.Services; | ||
using System.Linq; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sort usings? It looks like |
||
|
||
namespace OmniSharp.Roslyn.CSharp.Services | ||
{ | ||
[Export(typeof(IHostServicesProvider))] | ||
[Export(typeof(ExternalFeaturesHostServicesProvider))] | ||
[Shared] | ||
public class ExternalFeaturesHostServicesProvider : IHostServicesProvider | ||
{ | ||
public ImmutableArray<Assembly> Assemblies { get; } | ||
|
||
[ImportingConstructor] | ||
public ExternalFeaturesHostServicesProvider(IAssemblyLoader loader, OmniSharpOptions options, IOmniSharpEnvironment env) | ||
{ | ||
var builder = ImmutableArray.CreateBuilder<Assembly>(); | ||
|
||
var roslynExtensionsLocations = options.RoslynExtensionsOptions.GetNormalizedLocationPaths(env); | ||
if (roslynExtensionsLocations?.Any() == true) | ||
{ | ||
foreach (var roslynExtensionsLocation in roslynExtensionsLocations) | ||
{ | ||
builder.AddRange(loader.LoadAllFrom(roslynExtensionsLocation)); | ||
} | ||
} | ||
|
||
Assemblies = builder.ToImmutable(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
using System.Collections.Immutable; | ||
using System.Composition; | ||
using System.Reflection; | ||
using OmniSharp.Options; | ||
using OmniSharp.Services; | ||
using System.Linq; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sort usings? It looks like |
||
|
||
namespace OmniSharp.Roslyn.CSharp.Services | ||
{ | ||
[Export(typeof(IHostServicesProvider))] | ||
[Export(typeof(RoslynFeaturesHostServicesProvider))] | ||
[Shared] | ||
public class RoslynFeaturesHostServicesProvider : IHostServicesProvider | ||
{ | ||
public ImmutableArray<Assembly> Assemblies { get; } | ||
|
@@ -21,7 +24,8 @@ public RoslynFeaturesHostServicesProvider(IAssemblyLoader loader) | |
|
||
builder.AddRange(loader.Load(Features, CSharpFeatures)); | ||
|
||
this.Assemblies = builder.ToImmutable(); | ||
|
||
Assemblies = builder.ToImmutable(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,20 @@ | |
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" /> | ||
</startup> | ||
<runtime> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was added so that a refactoring written against Roslyn 1.0.0 (which is often the case) can load too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will need to be updated everytime we update Roslyn to a new version (or, at least, everytime the assembly version changes). Correct? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the current format, yes, correct. While this is technically not necessary, most of the code actions out there (i.e. packaged as VSIX-es) reference Roslyn assemblies from the host (VS). So it has to be low version if you want to avoid having a dependency on something like let's say Update 3 of Visual Studio to be installed by the user. Otherwise, we'd only be able to load into the current process code actions built specifically against the version of Roslyn OmniSharp is built against. I only added the three most common ones, maybe there are other DLLs that would be worthy of redirecting? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are others that will come up eventually, but this is good for now. |
||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> | ||
<dependentAssembly> | ||
<assemblyIdentity name="Microsoft.CodeAnalysis" publicKeyToken="31bf3856ad364e35" culture="neutral"/> | ||
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0"/> | ||
</dependentAssembly> | ||
<dependentAssembly> | ||
<assemblyIdentity name="Microsoft.CodeAnalysis.CSharp" publicKeyToken="31bf3856ad364e35" culture="neutral"/> | ||
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0"/> | ||
</dependentAssembly> | ||
<dependentAssembly> | ||
<assemblyIdentity name="Microsoft.CodeAnalysis.Workspaces" publicKeyToken="31bf3856ad364e35" culture="neutral"/> | ||
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0"/> | ||
</dependentAssembly> | ||
</assemblyBinding> | ||
</runtime> | ||
</configuration> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use
Array.Empty<Assembly>()
and avoid allocating here if you like.