Skip to content

Commit

Permalink
Merge pull request #1 from rchande/MEFfix
Browse files Browse the repository at this point in the history
Make MEF work
  • Loading branch information
akshita31 authored Jul 23, 2018
2 parents 7e6ba33 + eba6ae2 commit af435a6
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
15 changes: 12 additions & 3 deletions src/OmniSharp.Abstractions/Mef/ExportIProjectSystemAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
using OmniSharp.Services;
using System;
using System.ComponentModel.Composition;
using System.Composition;

namespace OmniSharp.Mef
{
[MetadataAttribute]
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public class ExportIProjectSystemAttribute: ExportAttribute
{
public string Name;
public string Name { get; }
public string Before { get; }
public string After { get; }

public ExportIProjectSystemAttribute(string name) : base(name, typeof(IProjectSystem))
public ExportIProjectSystemAttribute(string name, string before="", string after="") : base(typeof(IProjectSystem))
{
Name = name;
Before = before;
After = after;
}
}

public class ProjectSystemMetadata
{
string Name { get; set; }
}
}
26 changes: 26 additions & 0 deletions src/OmniSharp.Abstractions/Mef/IOrderableMetadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OmniSharp.Mef
{
internal interface IOrderableMetadata
{
[DefaultValue("")]
string After { get; }
[DefaultValue("")]
string Before { get; }
string Name { get; }
}

class OrderableMetadata
{
public string After { get; set; }

public string Before { get; set; }
public string Name { get; set; }
}
}
8 changes: 6 additions & 2 deletions src/OmniSharp.Host/WorkspaceInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
using System.ComponentModel;
using System.Composition;
using System.Composition.Hosting;
using System.Linq;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using OmniSharp.Mef;
using OmniSharp.Options;
using OmniSharp.Roslyn;
using OmniSharp.Roslyn.Options;
Expand All @@ -28,8 +30,10 @@ public static void Initialize(

var projectEventForwarder = compositionHost.GetExport<ProjectEventForwarder>();
projectEventForwarder.Initialize();
var projectSystems = compositionHost.GetExports<IProjectSystem>();
var orderedProjectSystems = ExtensionOrderer.GetOrderedOrUnorderedList<IProjectSystem, Attribute>(projectSystems, _=> null);
var projectSystems = compositionHost.GetExports<Lazy<IProjectSystem, OrderableMetadata>>();
var ps = projectSystems.Select(n => n.Value);
var qs = projectSystems.Select(n => n.Metadata);
var orderedProjectSystems = ExtensionOrderer.GetOrderedOrUnorderedList<IProjectSystem, ExportIProjectSystemAttribute>(ps, eps => eps.Name);

foreach (var projectSystem in orderedProjectSystems)
{
Expand Down
4 changes: 2 additions & 2 deletions src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

namespace OmniSharp.MiscellanousFiles
{
[ExtensionOrder(After = nameof(ProjectSystem))]
[ExportIProjectSystem(nameof(MiscellanousFiles)), Shared]
//[ExtensionOrder(After = nameof(ProjectSystem))]
[ExportIProjectSystem("Misc files", after: nameof(ProjectSystem)), Shared]
public class MiscellanousFiles : IProjectSystem
{
private readonly string miscFileExtension = ".cs";
Expand Down

0 comments on commit af435a6

Please sign in to comment.