зеркало из https://github.com/dotnet/razor.git
Cleanup
This commit is contained in:
Родитель
2007ade8b8
Коммит
f3de1fbe4c
|
@ -76,7 +76,7 @@
|
|||
<Tooling_MicrosoftCodeAnalysisTestingVersion>1.1.2-beta1.22109.1</Tooling_MicrosoftCodeAnalysisTestingVersion>
|
||||
<MicrosoftVisualStudioShellPackagesVersion>17.2.32330.158</MicrosoftVisualStudioShellPackagesVersion>
|
||||
<MicrosoftVisualStudioPackagesVersion>17.3.133-preview</MicrosoftVisualStudioPackagesVersion>
|
||||
<RoslynPackageVersion>4.4.0-dev</RoslynPackageVersion>
|
||||
<RoslynPackageVersion>4.4.0-2.22424.2</RoslynPackageVersion>
|
||||
<VisualStudioLanguageServerProtocolVersion>17.4.1004-preview</VisualStudioLanguageServerProtocolVersion>
|
||||
<MicrosoftNetCompilersToolsetVersion>4.4.0-1.final</MicrosoftNetCompilersToolsetVersion>
|
||||
</PropertyGroup>
|
||||
|
|
|
@ -2,43 +2,45 @@
|
|||
// Licensed under the MIT license. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Microsoft.CommonLanguageServerProtocol.Framework;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts
|
||||
namespace Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts;
|
||||
|
||||
internal readonly struct RazorRequestContext
|
||||
{
|
||||
internal readonly struct RazorRequestContext
|
||||
private readonly DocumentContext? _documentContext;
|
||||
|
||||
public readonly ILspLogger LspLogger;
|
||||
|
||||
public readonly ILogger Logger;
|
||||
|
||||
public readonly ILspServices LspServices;
|
||||
|
||||
public RazorRequestContext(
|
||||
DocumentContext? documentContext,
|
||||
ILspLogger lspLoger,
|
||||
ILogger logger,
|
||||
ILspServices lspServices)
|
||||
{
|
||||
public readonly DocumentContext? DocumentContext;
|
||||
public readonly ILspLogger LspLogger;
|
||||
public readonly ILogger Logger;
|
||||
public readonly ILspServices LspServices;
|
||||
_documentContext = documentContext;
|
||||
LspLogger = lspLoger;
|
||||
LspServices = lspServices;
|
||||
Logger = logger;
|
||||
}
|
||||
|
||||
public RazorRequestContext(
|
||||
DocumentContext? documentContext,
|
||||
ILspLogger lspLoger,
|
||||
ILogger logger,
|
||||
ILspServices lspServices)
|
||||
public DocumentContext GetRequiredDocumentContext()
|
||||
{
|
||||
if (_documentContext is null)
|
||||
{
|
||||
DocumentContext = documentContext;
|
||||
LspLogger = lspLoger;
|
||||
LspServices = lspServices;
|
||||
Logger = logger;
|
||||
throw new ArgumentNullException(nameof(DocumentContext));
|
||||
}
|
||||
|
||||
[MemberNotNull(nameof(DocumentContext))]
|
||||
public void RequireDocumentContext()
|
||||
{
|
||||
if (DocumentContext is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(DocumentContext));
|
||||
}
|
||||
}
|
||||
return _documentContext;
|
||||
}
|
||||
|
||||
public T GetRequiredService<T>() where T : class
|
||||
{
|
||||
return LspServices.GetRequiredService<T>();
|
||||
}
|
||||
public T GetRequiredService<T>() where T : class
|
||||
{
|
||||
return LspServices.GetRequiredService<T>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,24 +3,23 @@
|
|||
|
||||
using Microsoft.VisualStudio.LanguageServer.Protocol;
|
||||
|
||||
namespace Microsoft.AspNetCore.Razor.LanguageServer.Extensions
|
||||
{
|
||||
internal static class VSInternalClientCapabilitiesExtensions
|
||||
{
|
||||
internal static VSInternalClientCapabilities ToVSInternalClientCapabilities(this ClientCapabilities clientCapabilities)
|
||||
{
|
||||
if (clientCapabilities is VSInternalClientCapabilities vSInternalClientCapabilities)
|
||||
{
|
||||
return vSInternalClientCapabilities;
|
||||
}
|
||||
namespace Microsoft.AspNetCore.Razor.LanguageServer.Extensions;
|
||||
|
||||
return new VSInternalClientCapabilities()
|
||||
{
|
||||
TextDocument = clientCapabilities.TextDocument,
|
||||
SupportsVisualStudioExtensions = false,
|
||||
Experimental = clientCapabilities.Experimental,
|
||||
Workspace = clientCapabilities.Workspace,
|
||||
};
|
||||
internal static class VSInternalClientCapabilitiesExtensions
|
||||
{
|
||||
internal static VSInternalClientCapabilities ToVSInternalClientCapabilities(this ClientCapabilities clientCapabilities)
|
||||
{
|
||||
if (clientCapabilities is VSInternalClientCapabilities vSInternalClientCapabilities)
|
||||
{
|
||||
return vSInternalClientCapabilities;
|
||||
}
|
||||
|
||||
return new VSInternalClientCapabilities()
|
||||
{
|
||||
TextDocument = clientCapabilities.TextDocument,
|
||||
SupportsVisualStudioExtensions = false,
|
||||
Experimental = clientCapabilities.Experimental,
|
||||
Workspace = clientCapabilities.Workspace,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,58 +7,52 @@ using System.Collections.Immutable;
|
|||
using Microsoft.CommonLanguageServerProtocol.Framework;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Microsoft.AspNetCore.Razor.LanguageServer
|
||||
namespace Microsoft.AspNetCore.Razor.LanguageServer;
|
||||
|
||||
internal class LspServices : ILspServices
|
||||
{
|
||||
internal class LspServices : ILspServices
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
|
||||
public LspServices(IServiceCollection serviceCollection)
|
||||
{
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
serviceCollection.AddSingleton<ILspServices>(this);
|
||||
_serviceProvider = serviceCollection.BuildServiceProvider();
|
||||
}
|
||||
|
||||
public LspServices(IServiceCollection serviceCollection)
|
||||
public ImmutableArray<Type> GetRegisteredServices()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public T GetRequiredService<T>() where T : notnull
|
||||
{
|
||||
return _serviceProvider.GetRequiredService<T>();
|
||||
}
|
||||
|
||||
public IEnumerable<T> GetRequiredServices<T>()
|
||||
{
|
||||
var services = _serviceProvider.GetServices<T>();
|
||||
if (services is null)
|
||||
{
|
||||
serviceCollection.AddSingleton<ILspServices>(this);
|
||||
_serviceProvider = serviceCollection.BuildServiceProvider();
|
||||
throw new ArgumentNullException($"Missing services {nameof(T)}");
|
||||
}
|
||||
|
||||
public ImmutableArray<Type> GetRegisteredServices()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
return services;
|
||||
}
|
||||
|
||||
public T GetRequiredService<T>() where T : notnull
|
||||
{
|
||||
return _serviceProvider.GetRequiredService<T>();
|
||||
}
|
||||
public object? TryGetService(Type type)
|
||||
{
|
||||
var service = _serviceProvider.GetService(type);
|
||||
|
||||
public IEnumerable<T> GetRequiredServices<T>()
|
||||
{
|
||||
var services = _serviceProvider.GetServices<T>();
|
||||
if (services is null)
|
||||
{
|
||||
throw new ArgumentNullException($"Missing services {nameof(T)}");
|
||||
}
|
||||
return service;
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
public bool SupportsGetRegisteredServices()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public object? TryGetService(Type type)
|
||||
{
|
||||
var service = _serviceProvider.GetService(type);
|
||||
|
||||
return service;
|
||||
}
|
||||
|
||||
public bool SupportsGetRegisteredServices()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool SupportsGetRequiredServices()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,43 +6,42 @@ using System.Reflection;
|
|||
using System.Runtime.Serialization;
|
||||
using Microsoft.VisualStudio.LanguageServer.Protocol;
|
||||
|
||||
namespace Microsoft.AspNetCore.Razor.LanguageServer
|
||||
namespace Microsoft.AspNetCore.Razor.LanguageServer;
|
||||
|
||||
public static class ServerCapabilitiesExtensions
|
||||
{
|
||||
public static class ServerCapabilitiesExtensions
|
||||
private static readonly IReadOnlyDictionary<string, PropertyInfo> s_propertyMappings;
|
||||
|
||||
static ServerCapabilitiesExtensions()
|
||||
{
|
||||
private static readonly IReadOnlyDictionary<string, PropertyInfo> s_propertyMappings;
|
||||
var propertyInfos = typeof(VSInternalServerCapabilities).GetProperties(BindingFlags.Public | BindingFlags.Instance);
|
||||
|
||||
static ServerCapabilitiesExtensions()
|
||||
var dictionary = new Dictionary<string, PropertyInfo>();
|
||||
foreach (var propertyInfo in propertyInfos)
|
||||
{
|
||||
var propertyInfos = typeof(VSInternalServerCapabilities).GetProperties(BindingFlags.Public | BindingFlags.Instance);
|
||||
|
||||
var dictionary = new Dictionary<string, PropertyInfo>();
|
||||
foreach (var propertyInfo in propertyInfos)
|
||||
{
|
||||
var dataMemeberAttribute = propertyInfo.GetCustomAttribute<DataMemberAttribute>();
|
||||
var serverCapability = dataMemeberAttribute.Name;
|
||||
dictionary[serverCapability] = propertyInfo;
|
||||
}
|
||||
|
||||
s_propertyMappings = dictionary;
|
||||
var dataMemeberAttribute = propertyInfo.GetCustomAttribute<DataMemberAttribute>();
|
||||
var serverCapability = dataMemeberAttribute.Name;
|
||||
dictionary[serverCapability] = propertyInfo;
|
||||
}
|
||||
|
||||
internal static void ApplyRegistrationResult(this VSInternalServerCapabilities serverCapabilities, RegistrationExtensionResult registrationExtensionResult)
|
||||
s_propertyMappings = dictionary;
|
||||
}
|
||||
|
||||
internal static void ApplyRegistrationResult(this VSInternalServerCapabilities serverCapabilities, RegistrationExtensionResult registrationExtensionResult)
|
||||
{
|
||||
var serverCapability = registrationExtensionResult.ServerCapability;
|
||||
if (s_propertyMappings.ContainsKey(serverCapability))
|
||||
{
|
||||
var serverCapability = registrationExtensionResult.ServerCapability;
|
||||
if (s_propertyMappings.ContainsKey(serverCapability))
|
||||
{
|
||||
var propertyInfo = s_propertyMappings[serverCapability];
|
||||
var propertyInfo = s_propertyMappings[serverCapability];
|
||||
|
||||
propertyInfo.SetValue(serverCapabilities, registrationExtensionResult.Options);
|
||||
}
|
||||
else
|
||||
{
|
||||
serverCapabilities.Experimental ??= new Dictionary<string, object>();
|
||||
propertyInfo.SetValue(serverCapabilities, registrationExtensionResult.Options);
|
||||
}
|
||||
else
|
||||
{
|
||||
serverCapabilities.Experimental ??= new Dictionary<string, object>();
|
||||
|
||||
var dict = (Dictionary<string, object>)serverCapabilities.Experimental;
|
||||
dict[registrationExtensionResult.ServerCapability] = registrationExtensionResult.Options;
|
||||
}
|
||||
var dict = (Dictionary<string, object>)serverCapabilities.Experimental;
|
||||
dict[registrationExtensionResult.ServerCapability] = registrationExtensionResult.Options;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче