Skip to content

Commit

Permalink
Merge pull request #969 from OmniSharp/lsp
Browse files Browse the repository at this point in the history
[Beta] Language Server Protocol
  • Loading branch information
david-driscoll authored Jan 9, 2018
2 parents 108dd1a + 803dab7 commit f0a3ac1
Show file tree
Hide file tree
Showing 32 changed files with 1,618 additions and 66 deletions.
31 changes: 17 additions & 14 deletions OmniSharp.sln
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2000
VisualStudioVersion = 15.0.27004.2005
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{2C348365-A9D8-459E-9276-56FC46AAEE31}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{07464F68-2D8E-45E5-B30A-768FCF4CC903}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
tests\app.config = tests\app.config
build.cake = build.cake
build.cmd = build.cmd
build.json = build.json
build.sh = build.sh
global.json = global.json
NuGet.Config = NuGet.Config
tools\packages.config = tools\packages.config
build\Packages.props = build\Packages.props
EndProjectSection
ProjectSection(FolderGlobals) = preProject
global_1json__JSONSchema = http://json.schemastore.org/global
global_1json__JSONSchema = http://json.schemastore.org/global
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{35E025BF-BBB2-4FAC-9F4B-37CBA083EE47}"
Expand Down Expand Up @@ -63,6 +51,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OmniSharp.Http", "src\OmniS
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OmniSharp.Http.Tests", "tests\OmniSharp.Http.Tests\OmniSharp.Http.Tests.csproj", "{1217C534-E8EB-454D-B6E1-12BD30E72F8E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OmniSharp.LanguageServerProtocol", "src\OmniSharp.LanguageServerProtocol\OmniSharp.LanguageServerProtocol.csproj", "{D182B870-72E7-4072-A439-45F4FC148A34}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OmniSharp.DotNet.ProjectModel", "src\OmniSharp.DotNet.ProjectModel\OmniSharp.DotNet.ProjectModel.csproj", "{31580626-6D87-491D-A65E-F6B881164398}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OmniSharp.Cake", "src\OmniSharp.Cake\OmniSharp.Cake.csproj", "{BA0713A6-EF63-419D-B60D-7A84B134531F}"
Expand Down Expand Up @@ -319,6 +309,18 @@ Global
{1217C534-E8EB-454D-B6E1-12BD30E72F8E}.Release|x64.Build.0 = Release|Any CPU
{1217C534-E8EB-454D-B6E1-12BD30E72F8E}.Release|x86.ActiveCfg = Release|Any CPU
{1217C534-E8EB-454D-B6E1-12BD30E72F8E}.Release|x86.Build.0 = Release|Any CPU
{D182B870-72E7-4072-A439-45F4FC148A34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D182B870-72E7-4072-A439-45F4FC148A34}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D182B870-72E7-4072-A439-45F4FC148A34}.Debug|x64.ActiveCfg = Debug|Any CPU
{D182B870-72E7-4072-A439-45F4FC148A34}.Debug|x64.Build.0 = Debug|Any CPU
{D182B870-72E7-4072-A439-45F4FC148A34}.Debug|x86.ActiveCfg = Debug|Any CPU
{D182B870-72E7-4072-A439-45F4FC148A34}.Debug|x86.Build.0 = Debug|Any CPU
{D182B870-72E7-4072-A439-45F4FC148A34}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D182B870-72E7-4072-A439-45F4FC148A34}.Release|Any CPU.Build.0 = Release|Any CPU
{D182B870-72E7-4072-A439-45F4FC148A34}.Release|x64.ActiveCfg = Release|Any CPU
{D182B870-72E7-4072-A439-45F4FC148A34}.Release|x64.Build.0 = Release|Any CPU
{D182B870-72E7-4072-A439-45F4FC148A34}.Release|x86.ActiveCfg = Release|Any CPU
{D182B870-72E7-4072-A439-45F4FC148A34}.Release|x86.Build.0 = Release|Any CPU
{31580626-6D87-491D-A65E-F6B881164398}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{31580626-6D87-491D-A65E-F6B881164398}.Debug|Any CPU.Build.0 = Debug|Any CPU
{31580626-6D87-491D-A65E-F6B881164398}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -380,6 +382,7 @@ Global
{A645D475-3448-4473-88CA-E3C3B31E33CA} = {35E025BF-BBB2-4FAC-9F4B-37CBA083EE47}
{0A9BF1CC-2F0D-431C-BAFD-403658E233F1} = {2C348365-A9D8-459E-9276-56FC46AAEE31}
{1217C534-E8EB-454D-B6E1-12BD30E72F8E} = {35E025BF-BBB2-4FAC-9F4B-37CBA083EE47}
{D182B870-72E7-4072-A439-45F4FC148A34} = {2C348365-A9D8-459E-9276-56FC46AAEE31}
{31580626-6D87-491D-A65E-F6B881164398} = {2C348365-A9D8-459E-9276-56FC46AAEE31}
{BA0713A6-EF63-419D-B60D-7A84B134531F} = {2C348365-A9D8-459E-9276-56FC46AAEE31}
{17DAECA3-AE28-4B40-AA52-1EF618346A85} = {35E025BF-BBB2-4FAC-9F4B-37CBA083EE47}
Expand Down
18 changes: 9 additions & 9 deletions src/OmniSharp.Abstractions/Models/Events/EventTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ namespace OmniSharp.Models.Events
{
public static class EventTypes
{
public static readonly string ProjectAdded = nameof(ProjectAdded);
public static readonly string ProjectChanged = nameof(ProjectChanged);
public static readonly string ProjectRemoved = nameof(ProjectRemoved);
public static readonly string Error = nameof(Error);
public static readonly string Diagnostic = nameof(Diagnostic);
public static readonly string PackageRestoreStarted = nameof(PackageRestoreStarted);
public static readonly string PackageRestoreFinished = nameof(PackageRestoreFinished);
public static readonly string UnresolvedDependencies = nameof(UnresolvedDependencies);
public const string ProjectAdded = nameof(ProjectAdded);
public const string ProjectChanged = nameof(ProjectChanged);
public const string ProjectRemoved = nameof(ProjectRemoved);
public const string Error = nameof(Error);
public const string Diagnostic = nameof(Diagnostic);
public const string PackageRestoreStarted = nameof(PackageRestoreStarted);
public const string PackageRestoreFinished = nameof(PackageRestoreFinished);
public const string UnresolvedDependencies = nameof(UnresolvedDependencies);
}
}
}
23 changes: 23 additions & 0 deletions src/OmniSharp.Abstractions/Services/IAssemblyLoader.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;

namespace OmniSharp.Services
Expand Down Expand Up @@ -38,5 +39,27 @@ public static IEnumerable<Assembly> Load(this IAssemblyLoader loader, params str
yield return Load(loader, name);
}
}

public static Assembly LoadByAssemblyNameOrPath(
this IAssemblyLoader loader,
string assemblyName)
{
if (File.Exists(assemblyName))
{
return loader.LoadFrom(assemblyName);
}
else
{
return loader.Load(assemblyName);
}
}

public static IEnumerable<Assembly> LoadByAssemblyNameOrPath(this IAssemblyLoader loader, IEnumerable<string> assemblyNames)
{
foreach (var assemblyName in assemblyNames)
{
yield return loader.LoadByAssemblyNameOrPath(assemblyName);
}
}
}
}
16 changes: 10 additions & 6 deletions src/OmniSharp.Host/CompositionHostBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,17 @@ public class CompositionHostBuilder
{
private readonly IServiceProvider _serviceProvider;
private readonly IOmniSharpEnvironment _environment;
private readonly ISharedTextWriter _writer;
private readonly IEventEmitter _eventEmitter;
private readonly IEnumerable<Assembly> _assemblies;

public CompositionHostBuilder(
IServiceProvider serviceProvider,
IOmniSharpEnvironment environment,
ISharedTextWriter writer,
IEventEmitter eventEmitter,
IEnumerable<Assembly> assemblies = null)
{
_serviceProvider = serviceProvider;
_environment = environment;
_writer = writer;
_eventEmitter = eventEmitter;
_assemblies = assemblies ?? Array.Empty<Assembly>();
}
Expand Down Expand Up @@ -68,7 +65,6 @@ public CompositionHost Build()
.WithProvider(MefValueProvider.From(memoryCache))
.WithProvider(MefValueProvider.From(loggerFactory))
.WithProvider(MefValueProvider.From(_environment))
.WithProvider(MefValueProvider.From(_writer))
.WithProvider(MefValueProvider.From(options.CurrentValue))
.WithProvider(MefValueProvider.From(options.CurrentValue.FormattingOptions))
.WithProvider(MefValueProvider.From(assemblyLoader))
Expand Down Expand Up @@ -163,13 +159,21 @@ public CompositionHostBuilder WithOmniSharpAssemblies()
var assemblies = DiscoverOmniSharpAssemblies();

return new CompositionHostBuilder(
_serviceProvider, _environment, _writer, _eventEmitter, assemblies);
_serviceProvider,
_environment,
_eventEmitter,
_assemblies.Concat(assemblies).Distinct()
);
}

public CompositionHostBuilder WithAssemblies(params Assembly[] assemblies)
{
return new CompositionHostBuilder(
_serviceProvider, _environment, _writer, _eventEmitter, assemblies);
_serviceProvider,
_environment,
_eventEmitter,
_assemblies.Concat(assemblies).Distinct()
);
}

private List<Assembly> DiscoverOmniSharpAssemblies()
Expand Down
6 changes: 6 additions & 0 deletions src/OmniSharp.Host/Internal/CommandOptionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.ComponentModel;
using Microsoft.Extensions.CommandLineUtils;

Expand All @@ -14,5 +15,10 @@ public static T GetValueOrDefault<T>(this CommandOption opt, T defaultValue)

return defaultValue;
}

public static bool GetValueOrDefault(this CommandOption opt, bool defaultValue)
{
return opt.Value()?.Equals("on", StringComparison.OrdinalIgnoreCase) == true || defaultValue;
}
}
}
4 changes: 1 addition & 3 deletions src/OmniSharp.Http/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,20 @@ class Startup
{
private readonly IOmniSharpEnvironment _environment;
private readonly IEventEmitter _eventEmitter;
private readonly ISharedTextWriter _writer;
private readonly IConfigurationRoot _configuration;
private CompositionHost _compositionHost;

public Startup(IOmniSharpEnvironment environment, IEventEmitter eventEmitter, ISharedTextWriter writer)
{
_environment = environment;
_eventEmitter = eventEmitter;
_writer = writer;
_configuration = new ConfigurationBuilder(environment).Build();
}

public IServiceProvider ConfigureServices(IServiceCollection services)
{
var serviceProvider = CompositionHostBuilder.CreateDefaultServiceProvider(_configuration, services);
_compositionHost = new CompositionHostBuilder(serviceProvider, _environment, _writer, _eventEmitter)
_compositionHost = new CompositionHostBuilder(serviceProvider, _environment, _eventEmitter)
.WithOmniSharpAssemblies()
.Build();

Expand Down
6 changes: 6 additions & 0 deletions src/OmniSharp.LanguageServerProtocol/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("TestUtility")]
[assembly: InternalsVisibleTo("OmniSharp")]
[assembly: InternalsVisibleTo("OmniSharp.Stdio.Tests")]
[assembly: InternalsVisibleTo("OmniSharp.LanguageServer.Tests")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using System.Linq;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using OmniSharp.Eventing;
using OmniSharp.Extensions.LanguageServer;
using OmniSharp.Extensions.LanguageServer.Models;
using OmniSharp.Extensions.LanguageServer.Protocol;
using OmniSharp.Models.Diagnostics;
using OmniSharp.Models.Events;
using OmniSharp.Stdio.Protocol;
using OmniSharp.Stdio.Services;

namespace OmniSharp.LanguageServerProtocol.Eventing
{
public class LanguageServerEventEmitter : IEventEmitter
{
private readonly LanguageServer _server;

public LanguageServerEventEmitter(LanguageServer server)
{
_server = server;
}

public void Emit(string kind, object args)
{
switch (kind)
{
case EventTypes.Diagnostic:
if (args is DiagnosticMessage message)
{
var groups = message.Results
.GroupBy(z => Helpers.ToUri(z.FileName), z => z.QuickFixes);

foreach (var group in groups)
{
_server.PublishDiagnostics(new PublishDiagnosticsParams()
{
Uri = group.Key,
Diagnostics = group
.SelectMany(z => z.Select(v => v.ToDiagnostic()))
.ToArray()
});
}
}
break;
case EventTypes.ProjectAdded:
case EventTypes.ProjectChanged:
case EventTypes.ProjectRemoved:
case EventTypes.Error:
case EventTypes.PackageRestoreStarted:
case EventTypes.PackageRestoreFinished:
case EventTypes.UnresolvedDependencies:
// TODO: As custom notifications
break;
}
}
}
}
Loading

0 comments on commit f0a3ac1

Please sign in to comment.