Skip to content

Commit

Permalink
Merge pull request OmniSharp#293 from OmniSharp/plugins/mef
Browse files Browse the repository at this point in the history
Plugin system with MEF
  • Loading branch information
nosami committed Oct 21, 2015
2 parents a7025de + 4fefdf5 commit d3d8fa3
Show file tree
Hide file tree
Showing 476 changed files with 4,161 additions and 1,630 deletions.
2 changes: 1 addition & 1 deletion OmniSharp.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.22815.1
VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{2C348365-A9D8-459E-9276-56FC46AAEE31}"
EndProject
Expand Down
48 changes: 45 additions & 3 deletions build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,55 @@ set PATH=!USERPROFILE!\.dnx\runtimes\dnx-clr-win-x86.1.0.0-beta4\bin;!PATH!

call dnu restore
if %errorlevel% neq 0 exit /b %errorlevel%
cd tests\OmniSharp.Tests

pushd tests\OmniSharp.Dnx.Tests
call dnx . test
if %errorlevel% neq 0 exit /b %errorlevel%
popd

pushd tests\OmniSharp.MSBuild.Tests
call dnx . test
if %errorlevel% neq 0 exit /b %errorlevel%
cd ..\OmniSharp.Stdio.Tests
popd

pushd tests\OmniSharp.Plugins.Tests
call dnx . test
if %errorlevel% neq 0 exit /b %errorlevel%
popd

pushd tests\OmniSharp.Roslyn.CSharp.Tests
call dnx . test
if %errorlevel% neq 0 exit /b %errorlevel%
popd

pushd tests\OmniSharp.ScriptCs.Tests
call dnx . test
if %errorlevel% neq 0 exit /b %errorlevel%
cd ..\..
popd

pushd tests\OmniSharp.Stdio.Tests
call dnx . test
if %errorlevel% neq 0 exit /b %errorlevel%
popd

pushd tests\OmniSharp.Tests
call dnx . test
if %errorlevel% neq 0 exit /b %errorlevel%
popd

pushd tests\OmniSharp.Tests
call dnx . test
if %errorlevel% neq 0 exit /b %errorlevel%
popd

call dnu build src/OmniSharp.Abstractions --configuration Release --out artifacts
call dnu build src/OmniSharp.Dnx --configuration Release --out artifacts
call dnu build src/OmniSharp.MSBuild --configuration Release --out artifacts
call dnu build src/OmniSharp.Nuget --configuration Release --out artifacts
call dnu build src/OmniSharp.Roslyn --configuration Release --out artifacts
call dnu build src/OmniSharp.Roslyn.CSharp --configuration Release --out artifacts
call dnu build src/OmniSharp.ScriptCs --configuration Release --out artifacts
call dnu build src/OmniSharp.Stdio --configuration Release --out artifacts
call dnu publish src\OmniSharp --no-source --out artifacts\build\omnisharp --runtime dnx-clr-win-x86.1.0.0-beta4

popd
46 changes: 43 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ if ! type dnvm > /dev/null 2>&1; then
curl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | DNX_BRANCH=dev sh && source ~/.dnx/dnvm/dnvm.sh
fi

# work around restore timeouts on Mono
[ -z "$MONO_THREADS_PER_CPU" ] && export MONO_THREADS_PER_CPU=50

# HACK - dnu restore with beta4 fails most of the time
# due to timeouts or other failures.
# Fetch the latest dnu and use that instead
Expand All @@ -17,14 +20,51 @@ dnvm install 1.0.0-beta4
dnvm alias default 1.0.0-beta4
dnu restore
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
cd tests/OmniSharp.Tests

pushd tests/OmniSharp.Dnx.Tests
dnx . test -parallel none
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
popd

pushd tests/OmniSharp.MSBuild.Tests
dnx . test -parallel none
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
popd

pushd tests/OmniSharp.Plugins.Tests
dnx . test -parallel none
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
cd ../OmniSharp.Stdio.Tests
popd

pushd tests/OmniSharp.Roslyn.CSharp.Tests
dnx . test -parallel none
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
cd ../../
popd

pushd tests/OmniSharp.ScriptCs.Tests
dnx . test -parallel none
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
popd

pushd tests/OmniSharp.Stdio.Tests
dnx . test -parallel none
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
popd

pushd tests/OmniSharp.Tests
dnx . test -parallel none
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
popd

dnvm use 1.0.0-beta4
dnu build src/OmniSharp.Abstractions --configuration Release --out artifacts
dnu build src/OmniSharp.Dnx --configuration Release --out artifacts
dnu build src/OmniSharp.MSBuild --configuration Release --out artifacts
dnu build src/OmniSharp.Nuget --configuration Release --out artifacts
dnu build src/OmniSharp.Roslyn --configuration Release --out artifacts
dnu build src/OmniSharp.Roslyn.CSharp --configuration Release --out artifacts
dnu build src/OmniSharp.ScriptCs --configuration Release --out artifacts
dnu build src/OmniSharp.Stdio --configuration Release --out artifacts
dnu publish src/OmniSharp --configuration Release --no-source --out artifacts/build/omnisharp --runtime dnx-mono.1.0.0-beta4 2>&1 | tee buildlog
# work around for kpm bundle returning an exit code 0 on failure
grep "Build failed" buildlog
Expand Down
68 changes: 68 additions & 0 deletions src/OmniSharp.Abstractions/Endpoints.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using OmniSharp.Mef;
using OmniSharp.Models;
using OmniSharp.Models.v1;
using V2 = OmniSharp.Models.V2;

namespace OmniSharp
{
public interface RequestHandler<TRequest, TResponse> : IRequestHandler
{
Task<TResponse> Handle(TRequest request);
}

public interface IAggregateResponse
{
IAggregateResponse Merge(IAggregateResponse response);
}

public interface IRequest { }

public static class OmnisharpEndpoints
{
public const string GotoDefinition = "/gotodefinition";
public const string FindSymbols = "/findsymbols";
public const string UpdateBuffer = "/updatebuffer";
public const string ChangeBuffer = "/changebuffer";
public const string CodeCheck = "/codecheck";
public const string FilesChanged = "/filesChanged";
public const string FormatAfterKeystroke = "/formatAfterKeystroke";
public const string FormatRange = "/formatRange";
public const string CodeFormat = "/codeformat";
public const string Highlight = "/highlight";
public const string AutoComplete = "/autocomplete";
public const string FindImplementations = "/findimplementations";
public const string FindUsages = "/findusages";
public const string GotoFile = "/gotofile";
public const string GotoRegion = "/gotoregion";
public const string NavigateUp = "/navigateup";
public const string NavigateDown = "/navigatedown";
public const string TypeLookup = "/typelookup";
public const string GetCodeAction = "/getcodeactions";
public const string RunCodeAction = "/runcodeaction";
public const string Rename = "/rename";
public const string SignatureHelp = "/signatureHelp";
public const string MembersTree = "/currentfilemembersastree";
public const string MembersFlat = "/currentfilemembersasflat";
public const string TestCommand = "/gettestcontext";
public const string Metadata = "/metadata";
public const string PackageSource = "/packagesource";
public const string PackageSearch = "/packagesearch";
public const string PackageVersion = "/packageversion";
public const string WorkspaceInformation = "/projects";
public const string ProjectInformation = "/project";
public const string FixUsings = "/fixusings";

public const string CheckAliveStatus = "/checkalivestatus";
public const string CheckReadyStatus = "/checkreadystatus";
public const string StopServer = "/stopserver";

public static class V2
{
public const string GetCodeActions = "/v2/getcodeactions";
public const string RunCodeAction = "/v2/runcodeaction";
}
}
}
34 changes: 34 additions & 0 deletions src/OmniSharp.Abstractions/Mef/MefValueProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Collections.Generic;
using System.Composition.Hosting.Core;
using System.Linq;

namespace OmniSharp.Mef
{
public class MefValueProvider<T> : ExportDescriptorProvider
{
private readonly T _item;

public MefValueProvider(T item)
{
_item = item;
}

public override IEnumerable<ExportDescriptorPromise> GetExportDescriptors(CompositionContract contract, DependencyAccessor descriptorAccessor)
{
if (contract.ContractType == typeof(T))
{
yield return new ExportDescriptorPromise(contract, string.Empty, true,
() => Enumerable.Empty<CompositionDependency>(),
deps => ExportDescriptor.Create((context, operation) => _item, new Dictionary<string, object>()));
}
}
}

public static class MefValueProvider
{
public static MefValueProvider<T> From<T>(T value)
{
return new MefValueProvider<T>(value);
}
}
}
28 changes: 28 additions & 0 deletions src/OmniSharp.Abstractions/Mef/OmniSharpEndpoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Composition;
using System.Threading.Tasks;

namespace OmniSharp.Mef
{
public class EndpointDescriptor
{
public string EndpointName { get; set; }
public Type RequestType { get; set; }
public Type ResponseType { get; set; }
}

[MetadataAttribute]
public class OmniSharpEndpointAttribute : ExportAttribute
{
public string EndpointName { get; }
public Type RequestType { get; }
public Type ResponseType { get; }

public OmniSharpEndpointAttribute(string endpointName, Type requestType, Type responseType) : base(typeof(IRequest))
{
EndpointName = endpointName;
RequestType = requestType;
ResponseType = responseType;
}
}
}
27 changes: 27 additions & 0 deletions src/OmniSharp.Abstractions/Mef/OmniSharpHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Composition;
using System.Threading.Tasks;

namespace OmniSharp.Mef
{
public interface IRequestHandler { }

public class OmniSharpLanguage
{
public string EndpointName { get; set; }
public string Language { get; set; }
}

[MetadataAttribute]
public class OmniSharpHandlerAttribute : ExportAttribute
{
public string Language { get; }
public string EndpointName { get; }

public OmniSharpHandlerAttribute(string endpoint, string language) : base(typeof(IRequestHandler))
{
EndpointName = endpoint;
Language = language;
}
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using System.Collections.Generic;
using OmniSharp.Mef;

namespace OmniSharp.Models
{
[OmniSharpEndpoint(OmnisharpEndpoints.AutoComplete, typeof(AutoCompleteRequest), typeof(IEnumerable<AutoCompleteResponse>))]
public class AutoCompleteRequest : Request
{
private string _wordToComplete;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@

using OmniSharp.Mef;

namespace OmniSharp.Models
{
public class ChangeBufferRequest
[OmniSharpEndpoint(OmnisharpEndpoints.ChangeBuffer, typeof(ChangeBufferRequest), typeof(object))]
public class ChangeBufferRequest : IRequest
{
public string FileName { get; set; }
public int StartLine { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace OmniSharp.Models
namespace OmniSharp.Models
{
public class CodeActionRequest : Request
public abstract class CodeActionRequest : Request
{
public int CodeAction { get; set; }
public bool WantsTextChanges { get; set; }
Expand Down
9 changes: 9 additions & 0 deletions src/OmniSharp.Abstractions/Models/v1/CodeCheckRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using OmniSharp.Mef;

namespace OmniSharp.Models
{
[OmniSharpEndpoint(OmnisharpEndpoints.CodeCheck, typeof(CodeCheckRequest), typeof(QuickFixResponse))]
public class CodeCheckRequest : Request
{
}
}
9 changes: 9 additions & 0 deletions src/OmniSharp.Abstractions/Models/v1/CodeFormatRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using OmniSharp.Mef;

namespace OmniSharp.Models
{
[OmniSharpEndpoint(OmnisharpEndpoints.CodeFormat, typeof(CodeFormatRequest), typeof(CodeFormatResponse))]
public class CodeFormatRequest : Request
{
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions src/OmniSharp.Abstractions/Models/v1/FilesChangedRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System.Collections.Generic;
using OmniSharp.Mef;

namespace OmniSharp.Models
{
[OmniSharpEndpoint(OmnisharpEndpoints.FilesChanged, typeof(IEnumerable<Request>), typeof(FilesChangedResponse))]
public class FilesChangedRequest : IRequest { }
}
15 changes: 15 additions & 0 deletions src/OmniSharp.Abstractions/Models/v1/FilesChangedResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using OmniSharp.Mef;

namespace OmniSharp.Models
{
public class FilesChangedResponse : IAggregateResponse
{
public IAggregateResponse Merge(IAggregateResponse response)
{
// File Changes just need to inform plugins, editors are not expecting any kind of real response
return response ?? new FilesChangedResponse();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using OmniSharp.Mef;

namespace OmniSharp.Models
{
[OmniSharpEndpoint(OmnisharpEndpoints.FindImplementations, typeof(FindImplementationsRequest), typeof(QuickFixResponse))]
public class FindImplementationsRequest : Request
{
}
}
11 changes: 11 additions & 0 deletions src/OmniSharp.Abstractions/Models/v1/FindSymbolsRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using OmniSharp.Mef;

namespace OmniSharp.Models
{
[OmniSharpEndpoint(OmnisharpEndpoints.FindSymbols, typeof(FindSymbolsRequest), typeof(QuickFixResponse))]
public class FindSymbolsRequest : IRequest
{
public string Language { get; set; }
public string Filter { get; set; }
}
}
Loading

0 comments on commit d3d8fa3

Please sign in to comment.