Consume Latest LSP Platform & Utilize Microsoft.VisualStudio.Utilities.LogHub (#3312)

* Update Versions.props

* Update Microsoft.VisualStudio.LanguageServerClient.Razor.csproj

* Log Hub Implementation With Activity Tracing

* Fix VSThread warning

* PR Feedback Part 1

* React to roslyn API changes

* PR Feedback 2

* PR Feedback 3

* Create feedback RazorLogs zip file

* Remove duplicate StreamJsonRpc

* Support Log Hub Error Levels (#3127)

```csharp

            _logger.LogInformation("This is information");
            _logger.LogWarning("This is a warning");

            try
            {
                throw new Exception("SOME EXCEPTION");
            }
            catch (Exception e)
            {
                _logger.LogError(e, "This is a error");
            }
```

* Remove default listener from loghub trace source (#3158)

* Remove default listener from loghub trace source

Copy of https://github.com/dotnet/roslyn/pull/51248/files

* Update src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Logging/RazorLogHubTraceProvider.cs

* HTMLCSharpLanguageServer Log Handlers (#3129)

* Support Log Hub Error Levels

```csharp

            _logger.LogInformation("This is information");
            _logger.LogWarning("This is a warning");

            try
            {
                throw new Exception("SOME EXCEPTION");
            }
            catch (Exception e)
            {
                _logger.LogError(e, "This is a error");
            }
```

* Create BaseHandlerTest.cs

* Hover Handler Logging

* Cleanup

* Handler Logging

* Completion Logging

* Update src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/HtmlCSharp/CompletionResolveHandler.cs

Co-authored-by: Ryan Brandenburg <rybrande@microsoft.com>

* Update src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/HtmlCSharp/CompletionResolveHandler.cs

Co-authored-by: Ryan Brandenburg <rybrande@microsoft.com>

* PR Feedback

* Fix test

* Move projection failed logging to projection provider

* Update DefaultLSPProjectionProviderTest.cs

* InitializeLogHubLoggerAsync for pre-initialization

* PR Feedback

Co-authored-by: Ryan Brandenburg <rybrande@microsoft.com>

* LogHub Feedback (#3200)

* Address Log Hub Feedback

Creating a separate PR as I'm only pushing approved code to https://github.com/dotnet/aspnetcore-tooling/pull/3116 to keep things more manageable.

* Fix build

* VS Utilities

* Update Log File Identifiers

* Update Versions.props

* Update dependencies

* Update RazorLogHubTraceProvider.cs

* PR Feedback

* Update Log File Identifiers to use Razor Prefix

* Suppress Warnings from LSP Platform Changes (#3314)

* Suppress Warnings from LSP Platform Changes

These obsoletions are under discussion, suppressing to not block PRs.

* Update TestLanguageServiceBroker.cs

* Fix Tests

* Update RazorHtmlPublishDiagnosticsInterceptorTest.cs

Co-authored-by: Ryan Brandenburg <rybrande@microsoft.com>
This commit is contained in:
Tanay Parikh 2021-03-22 13:12:03 -07:00 коммит произвёл GitHub
Родитель 46b62c1677
Коммит eeeaaa2ae8
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
13 изменённых файлов: 29 добавлений и 29 удалений

Просмотреть файл

@ -88,7 +88,7 @@
<Tooling_HtmlEditorPackageVersion>16.10.57-preview1</Tooling_HtmlEditorPackageVersion>
<!-- Several packages share the MS.CA.Testing version -->
<Tooling_MicrosoftCodeAnalysisTestingVersion>1.0.1-beta1.21103.2</Tooling_MicrosoftCodeAnalysisTestingVersion>
<MicrosoftVisualStudioShellPackagesVersion>16.9.30921.310</MicrosoftVisualStudioShellPackagesVersion>
<MicrosoftVisualStudioShellPackagesVersion>16.9.30927.25</MicrosoftVisualStudioShellPackagesVersion>
</PropertyGroup>
<PropertyGroup Label="Manual">
<MicrosoftExtensionsNonCapturingTimerSourcesPackageVersion>5.0.0-preview.4.20205.1</MicrosoftExtensionsNonCapturingTimerSourcesPackageVersion>
@ -103,17 +103,16 @@
<MicrosoftCodeAnalysisAnalyzerTestingPackageVersion>$(Tooling_MicrosoftCodeAnalysisTestingVersion)</MicrosoftCodeAnalysisAnalyzerTestingPackageVersion>
<MicrosoftCodeAnalysisTestingVerifiersXunitPackageVersion>$(Tooling_MicrosoftCodeAnalysisTestingVersion)</MicrosoftCodeAnalysisTestingVerifiersXunitPackageVersion>
<MicrosoftNetCompilersToolsetPackageVersion>3.9.0-2.20573.10</MicrosoftNetCompilersToolsetPackageVersion>
<MicrosoftServiceHubFrameworkPackageVersion>2.7.339</MicrosoftServiceHubFrameworkPackageVersion>
<MicrosoftServiceHubFrameworkPackageVersion>2.7.454</MicrosoftServiceHubFrameworkPackageVersion>
<MicrosoftVisualStudioCoreUtilityPackageVersion>16.10.8</MicrosoftVisualStudioCoreUtilityPackageVersion>
<MicrosoftVisualStudioComponentModelHostPackageVersion>16.9.184-preview</MicrosoftVisualStudioComponentModelHostPackageVersion>
<MicrosoftVisualStudioComponentModelHostPackageVersion>16.9.214</MicrosoftVisualStudioComponentModelHostPackageVersion>
<MicrosoftVisualStudioImageCatalogPackageVersion>$(MicrosoftVisualStudioShellPackagesVersion)</MicrosoftVisualStudioImageCatalogPackageVersion>
<MicrosoftVisualStudioEditorPackageVersion>16.8.272</MicrosoftVisualStudioEditorPackageVersion>
<MicrosoftVisualStudioEditorPackageVersion>16.9.214</MicrosoftVisualStudioEditorPackageVersion>
<MicrosoftVisualStudioLanguagePackageVersion>16.10.8</MicrosoftVisualStudioLanguagePackageVersion>
<MicrosoftVisualStudioLanguageIntellisensePackageVersion>16.10.8</MicrosoftVisualStudioLanguageIntellisensePackageVersion>
<MicrosoftVisualStudioLanguageServerClientImplementationPackageVersion>16.9.150</MicrosoftVisualStudioLanguageServerClientImplementationPackageVersion>
<MicrosoftVisualStudioLanguageServerClientImplementationPackageVersion>16.10.138</MicrosoftVisualStudioLanguageServerClientImplementationPackageVersion>
<MicrosoftVisualStudioPackageLanguageService150PackageVersion>16.7.30204.53-pre</MicrosoftVisualStudioPackageLanguageService150PackageVersion>
<MicrosoftVisualStudioLiveSharePackageVersion>0.3.1074</MicrosoftVisualStudioLiveSharePackageVersion>
<MicrosoftVisualStudioLogHubPackageVersion>16.9.1043</MicrosoftVisualStudioLogHubPackageVersion>
<MicrosoftVisualStudioOLEInteropPackageVersion>7.10.6071</MicrosoftVisualStudioOLEInteropPackageVersion>
<MicrosoftVisualStudioProjectSystemManagedVSPackageVersion>16.8.1-beta1-10222-04</MicrosoftVisualStudioProjectSystemManagedVSPackageVersion>
<MicrosoftVisualStudioProjectSystemSDKPackageVersion>16.10.81-pre</MicrosoftVisualStudioProjectSystemSDKPackageVersion>

Просмотреть файл

@ -83,12 +83,14 @@ namespace Microsoft.VisualStudio.LanguageServer.ContainedLanguage
var serializedParams = JToken.FromObject(parameters);
#pragma warning disable CS0618 // Type or member is obsolete
var (_, resultToken) = await _languageServiceBroker.RequestAsync(
new[] { contentType },
capabilitiesFilter,
method,
serializedParams,
cancellationToken).ConfigureAwait(false);
#pragma warning restore CS0618 // Type or member is obsolete
var result = resultToken != null ? resultToken.ToObject<TOut>(_serializer) : default;
return result;
@ -103,12 +105,14 @@ namespace Microsoft.VisualStudio.LanguageServer.ContainedLanguage
var serializedParams = JToken.FromObject(parameters);
#pragma warning disable CS0618 // Type or member is obsolete
var clientAndResultTokenPairs = await _languageServiceBroker.RequestMultipleAsync(
new[] { contentType },
capabilitiesFilter,
method,
serializedParams,
cancellationToken).ConfigureAwait(false);
#pragma warning restore CS0618 // Type or member is obsolete
// a little ugly - tuple deconstruction in lambda arguments doesn't work - https://github.com/dotnet/csharplang/issues/258
var results = clientAndResultTokenPairs.Select((clientAndResultToken) => clientAndResultToken.Item2 != null ? clientAndResultToken.Item2.ToObject<TOut>(_serializer) : default);

Просмотреть файл

@ -50,7 +50,7 @@ namespace Microsoft.VisualStudio.LanguageServer.ContainedLanguage.MessageInterce
}
}
public Task<JToken> HandleRequestAsync(string methodName, JToken methodParam, Func<JToken, Task<JToken>> sendRequest)
public Task<JToken?> HandleRequestAsync(string methodName, JToken methodParam, Func<JToken, Task<JToken?>> sendRequest)
{
// until we have a request operation that needs to support interception, just pass the request through
return sendRequest(methodParam);

Просмотреть файл

@ -17,9 +17,6 @@
<PackageReference Include="Microsoft.VisualStudio.LanguageServer.Client.Implementation" Version="$(MicrosoftVisualStudioLanguageServerClientImplementationPackageVersion)" />
<PackageReference Include="Microsoft.VisualStudio.Text.Data" Version="$(MicrosoftVisualStudioTextDataPackageVersion)" />
<PackageReference Include="Microsoft.VisualStudio.Text.UI" Version="$(MicrosoftVisualStudioTextUIPackageVersion)" />
<!-- We must pin the LogHub dependency for now until the Microsoft.VisualStudio.LanguageServer.Client.Implementation package is able to take a dependency on the latest -->
<PackageReference Include="Microsoft.VisualStudio.LogHub" Version="$(MicrosoftVisualStudioLogHubPackageVersion)" />
</ItemGroup>
</Project>

Просмотреть файл

@ -33,7 +33,9 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor.HtmlCSharp
_languageServiceBroker = languageServiceBroker;
#pragma warning disable CS0618 // Type or member is obsolete
_languageServiceBroker.ClientNotifyAsync += ClientNotifyAsyncListenerAsync;
#pragma warning restore CS0618 // Type or member is obsolete
}
public override bool TryListenForProgress(
@ -167,7 +169,9 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor.HtmlCSharp
public void Dispose()
{
#pragma warning disable CS0618 // Type or member is obsolete
_languageServiceBroker.ClientNotifyAsync -= ClientNotifyAsyncListenerAsync;
#pragma warning restore CS0618 // Type or member is obsolete
foreach (var token in _activeRequests.Keys)
{

Просмотреть файл

@ -140,7 +140,9 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor.HtmlCSharp
private VSServerCapabilities GetMergedServerCapabilities(List<ILanguageClient> relevantLanguageClients)
{
#pragma warning disable CS0618 // Type or member is obsolete
foreach (var languageClientInstance in _languageServiceBroker.ActiveLanguageClients)
#pragma warning restore CS0618 // Type or member is obsolete
{
if (relevantLanguageClients.Contains(languageClientInstance.Client))
{
@ -436,7 +438,9 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor.HtmlCSharp
var relevantLanguageClients = new List<ILanguageClient>();
var clientLoadTasks = new List<Task>();
#pragma warning disable CS0618 // Type or member is obsolete
foreach (var languageClientAndMetadata in _languageServiceBroker.LanguageClients)
#pragma warning restore CS0618 // Type or member is obsolete
{
if (!(languageClientAndMetadata.Metadata is ILanguageClientMetadata metadata))
{

Просмотреть файл

@ -15,7 +15,7 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor.Logging
[Export(typeof(HTMLCSharpLanguageServerLogHubLoggerProvider))]
internal class HTMLCSharpLanguageServerLogHubLoggerProvider : ILoggerProvider
{
private static readonly string LogFileIdentifier = "HTMLCSharpLanguageServer";
private static readonly string LogFileIdentifier = "Razor.HTMLCSharpLanguageServerClient";
private LogHubLoggerProvider _loggerProvider;

Просмотреть файл

@ -6,7 +6,7 @@ using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.ServiceHub.Framework;
using Microsoft.VisualStudio.LogHub;
using Microsoft.VisualStudio.RpcContracts.Logging;
using VSShell = Microsoft.VisualStudio.Shell;
namespace Microsoft.VisualStudio.LanguageServerClient.Razor.Logging
@ -16,7 +16,8 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor.Logging
internal class RazorLogHubTraceProvider
{
private static readonly LoggerOptions _logOptions = new(
privacySetting: PrivacyFlags.CanContainPersonallyIdentifibleInformation | PrivacyFlags.CanContainPrivateInformation);
requestedLoggingLevel: new LoggingLevelSettings(SourceLevels.Information | SourceLevels.ActivityTracing),
privacySetting: PrivacyFlags.MayContainPersonallyIdentifibleInformation | PrivacyFlags.MayContainPrivateInformation);
private readonly SemaphoreSlim _initializationSemaphore = null;
private IServiceBroker _serviceBroker = null;
@ -37,14 +38,9 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor.Logging
logName: $"{logIdentifier}.{logHubSessionId}",
serviceId: new ServiceMoniker($"Razor.{logIdentifier}"));
using var traceConfig = await TraceConfiguration.CreateTraceConfigurationInstanceAsync(_serviceBroker, cancellationToken).ConfigureAwait(false);
using var traceConfig = await LogHub.TraceConfiguration.CreateTraceConfigurationInstanceAsync(_serviceBroker, cancellationToken).ConfigureAwait(false);
var traceSource = await traceConfig.RegisterLogSourceAsync(_logId, _logOptions, cancellationToken).ConfigureAwait(false);
// Trace source(s) have the debug output in VS as a default listener causing excessive noise.
traceSource.Listeners.Remove("Default");
traceSource.Switch.Level = SourceLevels.ActivityTracing | SourceLevels.Information;
return traceSource;
}

Просмотреть файл

@ -36,9 +36,6 @@
<PackageReference Include="Microsoft.VisualStudio.ProjectSystem.SDK" Version="$(MicrosoftVisualStudioProjectSystemSDKPackageVersion)" />
<PackageReference Include="Microsoft.VisualStudio.LanguageServer.Client.Implementation" Version="$(MicrosoftVisualStudioLanguageServerClientImplementationPackageVersion)" />
<PackageReference Include="Microsoft.VisualStudio.Language.Intellisense" Version="$(MicrosoftVisualStudioLanguageIntellisensePackageVersion)" />
<!-- We must pin the LogHub dependency for now until the Microsoft.VisualStudio.LanguageServer.Client.Implementation package is able to take a dependency on the latest -->
<PackageReference Include="Microsoft.VisualStudio.LogHub" Version="$(MicrosoftVisualStudioLogHubPackageVersion)" />
</ItemGroup>
<!-- Workaround for Microsoft.VisualStudio.SDK.EmbedInteropTypes not working correctly-->

Просмотреть файл

@ -30,7 +30,7 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor
[ContentType(RazorLSPConstants.RazorLSPContentTypeName)]
internal class RazorLanguageServerClient : ILanguageClient, ILanguageClientCustomMessage2, ILanguageClientPriority
{
private static readonly string LogFileIdentifier = "RazorLanguageServer";
private static readonly string LogFileIdentifier = "Razor.RazorLanguageServerClient";
private readonly RazorLanguageServerCustomMessageTarget _customMessageTarget;
private readonly ILanguageClientMiddleLayer _middleLayer;

Просмотреть файл

@ -509,7 +509,7 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor.HtmlCSharp
});
bool CanDiagnosticBeFiltered(Diagnostic d) =>
(diagnosticsToIgnore.Contains(d.Code) &&
(diagnosticsToIgnore.Contains(d.Code.Value.Second) &&
d.Severity != DiagnosticSeverity.Error);
});

Просмотреть файл

@ -77,8 +77,6 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor.HtmlCSharp
public IStreamingRequestBroker<WorkspaceDocumentDiagnosticsParams, WorkspaceDiagnosticReport[]> WorkspaceDiagnosticsBroker => throw new NotImplementedException();
IStreamingRequestBroker<SemanticTokensParams, SumType<ResolvableSemanticTokens, ResolvableSemanticTokensEdits>> ILanguageServiceBroker.SemanticTokensBroker => throw new NotImplementedException();
public IRequestBroker<KindAndModifier, IconMapping> KindDescriptionResolveBroker => throw new NotImplementedException();
public TestLanguageServiceBroker(Action<string, string> callback)

Просмотреть файл

@ -311,8 +311,9 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor
});
bool CanDiagnosticBeFiltered(Diagnostic d) =>
(diagnosticsToIgnore.Contains(d.Code) &&
d.Severity != DiagnosticSeverity.Error);
d.Code.HasValue &&
diagnosticsToIgnore.Contains(d.Code.Value.Second) &&
d.Severity != DiagnosticSeverity.Error;
});
return diagnosticsProvider.Object;