зеркало из https://github.com/dotnet/razor.git
Transition to ExternalAccess Debugging APIs
- Removed our C# breakpoint & proximity expression resolvers because we can use the real ExternalAccess variants.
This commit is contained in:
Родитель
47ad861ab8
Коммит
094f682bbe
|
@ -102,7 +102,7 @@
|
|||
<MicrosoftCodeAnalysisAnalyzerTestingPackageVersion>$(Tooling_MicrosoftCodeAnalysisTestingVersion)</MicrosoftCodeAnalysisAnalyzerTestingPackageVersion>
|
||||
<MicrosoftCodeAnalysisTestingVerifiersXunitPackageVersion>$(Tooling_MicrosoftCodeAnalysisTestingVersion)</MicrosoftCodeAnalysisTestingVerifiersXunitPackageVersion>
|
||||
<MicrosoftNetCompilersToolsetPackageVersion>3.9.0-2.20573.10</MicrosoftNetCompilersToolsetPackageVersion>
|
||||
<MicrosoftServiceHubFrameworkPackageVersion>2.7.313-preview</MicrosoftServiceHubFrameworkPackageVersion>
|
||||
<MicrosoftServiceHubFrameworkPackageVersion>2.7.339</MicrosoftServiceHubFrameworkPackageVersion>
|
||||
<MicrosoftVisualStudioCoreUtilityPackageVersion>16.10.8</MicrosoftVisualStudioCoreUtilityPackageVersion>
|
||||
<MicrosoftVisualStudioComponentModelHostPackageVersion>16.0.467</MicrosoftVisualStudioComponentModelHostPackageVersion>
|
||||
<MicrosoftVisualStudioImageCatalogPackageVersion>16.8.30406.65-pre</MicrosoftVisualStudioImageCatalogPackageVersion>
|
||||
|
@ -147,20 +147,20 @@
|
|||
<VSMAC_NewtonsoftJsonPackageVersion>12.0.2</VSMAC_NewtonsoftJsonPackageVersion>
|
||||
<Tooling_MicrosoftCodeAnalysisAnalyzersPackageVersion>3.3.2</Tooling_MicrosoftCodeAnalysisAnalyzersPackageVersion>
|
||||
<Tooling_MicrosoftCodeAnalysisNetAnalyzersPackageVersion>5.0.3</Tooling_MicrosoftCodeAnalysisNetAnalyzersPackageVersion>
|
||||
<Tooling_MicrosoftCodeAnalysisExternalAccessRazorPackageVersion>3.10.0-1.21109.14</Tooling_MicrosoftCodeAnalysisExternalAccessRazorPackageVersion>
|
||||
<Tooling_MicrosoftCodeAnalysisPackageVersion>3.10.0-1.21109.14</Tooling_MicrosoftCodeAnalysisPackageVersion>
|
||||
<Tooling_MicrosoftCodeAnalysisCommonPackageVersion>3.10.0-1.21109.14</Tooling_MicrosoftCodeAnalysisCommonPackageVersion>
|
||||
<Tooling_MicrosoftCodeAnalysisCSharpFeaturesPackageVersion>3.10.0-1.21109.14</Tooling_MicrosoftCodeAnalysisCSharpFeaturesPackageVersion>
|
||||
<Tooling_MicrosoftCodeAnalysisCSharpPackageVersion>3.10.0-1.21109.14</Tooling_MicrosoftCodeAnalysisCSharpPackageVersion>
|
||||
<Tooling_MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>3.10.0-1.21109.14</Tooling_MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>
|
||||
<Tooling_MicrosoftCodeAnalysisEditorFeaturesTextPackageVersion>3.10.0-1.21109.14</Tooling_MicrosoftCodeAnalysisEditorFeaturesTextPackageVersion>
|
||||
<Tooling_MicrosoftCodeAnalysisFeaturesPackageVersion>3.10.0-1.21109.14</Tooling_MicrosoftCodeAnalysisFeaturesPackageVersion>
|
||||
<Tooling_MicrosoftCodeAnalysisRemoteServiceHubPackageVersion>3.10.0-1.21109.14</Tooling_MicrosoftCodeAnalysisRemoteServiceHubPackageVersion>
|
||||
<Tooling_MicrosoftCodeAnalysisVisualBasicWorkspacesPackageVersion>3.10.0-1.21109.14</Tooling_MicrosoftCodeAnalysisVisualBasicWorkspacesPackageVersion>
|
||||
<Tooling_MicrosoftCodeAnalysisWorkspacesCommonPackageVersion>3.10.0-1.21109.14</Tooling_MicrosoftCodeAnalysisWorkspacesCommonPackageVersion>
|
||||
<Tooling_MicrosoftCodeAnalysisExternalAccessRazorPackageVersion>3.10.0-2.21121.14</Tooling_MicrosoftCodeAnalysisExternalAccessRazorPackageVersion>
|
||||
<Tooling_MicrosoftCodeAnalysisPackageVersion>3.10.0-2.21121.14</Tooling_MicrosoftCodeAnalysisPackageVersion>
|
||||
<Tooling_MicrosoftCodeAnalysisCommonPackageVersion>3.10.0-2.21121.14</Tooling_MicrosoftCodeAnalysisCommonPackageVersion>
|
||||
<Tooling_MicrosoftCodeAnalysisCSharpFeaturesPackageVersion>3.10.0-2.21121.14</Tooling_MicrosoftCodeAnalysisCSharpFeaturesPackageVersion>
|
||||
<Tooling_MicrosoftCodeAnalysisCSharpPackageVersion>3.10.0-2.21121.14</Tooling_MicrosoftCodeAnalysisCSharpPackageVersion>
|
||||
<Tooling_MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>3.10.0-2.21121.14</Tooling_MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>
|
||||
<Tooling_MicrosoftCodeAnalysisEditorFeaturesTextPackageVersion>3.10.0-2.21121.14</Tooling_MicrosoftCodeAnalysisEditorFeaturesTextPackageVersion>
|
||||
<Tooling_MicrosoftCodeAnalysisFeaturesPackageVersion>3.10.0-2.21121.14</Tooling_MicrosoftCodeAnalysisFeaturesPackageVersion>
|
||||
<Tooling_MicrosoftCodeAnalysisRemoteServiceHubPackageVersion>3.10.0-2.21121.14</Tooling_MicrosoftCodeAnalysisRemoteServiceHubPackageVersion>
|
||||
<Tooling_MicrosoftCodeAnalysisVisualBasicWorkspacesPackageVersion>3.10.0-2.21121.14</Tooling_MicrosoftCodeAnalysisVisualBasicWorkspacesPackageVersion>
|
||||
<Tooling_MicrosoftCodeAnalysisWorkspacesCommonPackageVersion>3.10.0-2.21121.14</Tooling_MicrosoftCodeAnalysisWorkspacesCommonPackageVersion>
|
||||
<Tooling_MicrosoftCodeAnalysisBannedApiAnalyzersPackageVersion>$(Tooling_MicrosoftCodeAnalysisAnalyzersPackageVersion)</Tooling_MicrosoftCodeAnalysisBannedApiAnalyzersPackageVersion>
|
||||
<Tooling_RoslynDiagnosticsAnalyzersPackageVersion>$(Tooling_MicrosoftCodeAnalysisAnalyzersPackageVersion)</Tooling_RoslynDiagnosticsAnalyzersPackageVersion>
|
||||
<Tooling_MicrosoftVisualStudioLanguageServicesPackageVersion>3.10.0-1.21109.14</Tooling_MicrosoftVisualStudioLanguageServicesPackageVersion>
|
||||
<Tooling_MicrosoftVisualStudioLanguageServicesPackageVersion>3.10.0-2.21121.14</Tooling_MicrosoftVisualStudioLanguageServicesPackageVersion>
|
||||
<XunitAnalyzersPackageVersion>0.10.0</XunitAnalyzersPackageVersion>
|
||||
<XunitCombinatorialPackageVersion>1.4.1</XunitCombinatorialPackageVersion>
|
||||
<XunitVersion>2.4.1</XunitVersion>
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Threading;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.Text;
|
||||
|
||||
namespace Microsoft.VisualStudio.LanguageServerClient.Razor.Debugging
|
||||
{
|
||||
// This type is temporary and will be replaced by an ExternalAccess.Razor type once available.
|
||||
|
||||
internal abstract class CSharpBreakpointResolver
|
||||
{
|
||||
public abstract bool TryGetBreakpointSpan(SyntaxTree tree, int position, CancellationToken cancellationToken, out TextSpan breakpointSpan);
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Microsoft.CodeAnalysis;
|
||||
|
||||
namespace Microsoft.VisualStudio.LanguageServerClient.Razor.Debugging
|
||||
{
|
||||
internal abstract class CSharpProximityExpressionResolver
|
||||
{
|
||||
public abstract IReadOnlyList<string> GetProximityExpressions(SyntaxTree syntaxTree, int absoluteIndex, CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.Text;
|
||||
|
||||
namespace Microsoft.VisualStudio.LanguageServerClient.Razor.Debugging
|
||||
{
|
||||
// This type is temporary and will be replaced by an ExternalAccess.Razor type once available.
|
||||
|
||||
[Export(typeof(CSharpBreakpointResolver))]
|
||||
internal class DefaultCSharpBreakpointResolver : CSharpBreakpointResolver
|
||||
{
|
||||
private readonly MethodInfo _tryGetBreakpointSpan;
|
||||
|
||||
public DefaultCSharpBreakpointResolver()
|
||||
{
|
||||
try
|
||||
{
|
||||
var assemblyName = typeof(SyntaxTree).Assembly.GetName();
|
||||
assemblyName.Name = "Microsoft.CodeAnalysis.CSharp.Features";
|
||||
var assembly = Assembly.Load(assemblyName);
|
||||
var type = assembly.GetType("Microsoft.CodeAnalysis.CSharp.EditAndContinue.BreakpointSpans");
|
||||
_tryGetBreakpointSpan = type.GetMethod("TryGetBreakpointSpan");
|
||||
|
||||
if (_tryGetBreakpointSpan == null)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Error occured when acessing the TryGetBreakpointSpan method on Roslyn's BreakpointSpan's type. Roslyn may have changed in an unexpected way.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Error occured when creating an instance of Roslyn's BreakpointSpan's type. Roslyn may have changed in an unexpected way.",
|
||||
ex);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool TryGetBreakpointSpan(SyntaxTree tree, int position, CancellationToken cancellationToken, out TextSpan breakpointSpan)
|
||||
{
|
||||
var parameters = new object[] { tree, position, cancellationToken, new TextSpan() };
|
||||
var result = _tryGetBreakpointSpan.Invoke(obj: null, parameters);
|
||||
var boolResult = (bool)result;
|
||||
|
||||
if (boolResult)
|
||||
{
|
||||
breakpointSpan = (TextSpan)parameters[3];
|
||||
return true;
|
||||
}
|
||||
|
||||
breakpointSpan = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using Microsoft.CodeAnalysis;
|
||||
|
||||
namespace Microsoft.VisualStudio.LanguageServerClient.Razor.Debugging
|
||||
{
|
||||
[Export(typeof(CSharpProximityExpressionResolver))]
|
||||
internal class DefaultCSharpProximityExpressionResolver : CSharpProximityExpressionResolver
|
||||
{
|
||||
private readonly MethodInfo _getProximityExpressionAsync;
|
||||
|
||||
public DefaultCSharpProximityExpressionResolver()
|
||||
{
|
||||
try
|
||||
{
|
||||
var assemblyName = typeof(SyntaxTree).Assembly.GetName();
|
||||
assemblyName.Name = "Microsoft.CodeAnalysis.CSharp.Features";
|
||||
var assembly = Assembly.Load(assemblyName);
|
||||
var type = assembly.GetType("Microsoft.CodeAnalysis.CSharp.Debugging.CSharpProximityExpressionsService");
|
||||
_getProximityExpressionAsync = type.GetMethod(
|
||||
"Do",
|
||||
BindingFlags.NonPublic | BindingFlags.Static,
|
||||
binder: null,
|
||||
types: new[] { typeof(SyntaxTree), typeof(int), typeof(CancellationToken) },
|
||||
modifiers: Array.Empty<ParameterModifier>());
|
||||
|
||||
if (_getProximityExpressionAsync == null)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Error occured when acessing the Do method on Roslyn's CSharpProximityExpressionsService's type. Roslyn may have changed in an unexpected way.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Error occured when creating an instance of Roslyn's CSharpProximityExpressionsService's type. Roslyn may have changed in an unexpected way.",
|
||||
ex);
|
||||
}
|
||||
}
|
||||
|
||||
public override IReadOnlyList<string> GetProximityExpressions(SyntaxTree syntaxTree, int absoluteIndex, CancellationToken cancellationToken)
|
||||
{
|
||||
if (syntaxTree is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(syntaxTree));
|
||||
}
|
||||
|
||||
var parameters = new object[] { syntaxTree, absoluteIndex, cancellationToken };
|
||||
var result = _getProximityExpressionAsync.Invoke(obj: null, parameters);
|
||||
var expressions = (IReadOnlyList<string>)result;
|
||||
|
||||
return expressions;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,6 +8,7 @@ using System.Linq;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.ExternalAccess.Razor;
|
||||
using Microsoft.CodeAnalysis.Text;
|
||||
using Microsoft.VisualStudio.LanguageServer.ContainedLanguage;
|
||||
using Microsoft.VisualStudio.LanguageServer.Protocol;
|
||||
|
@ -23,15 +24,13 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor.Debugging
|
|||
private readonly LSPDocumentManager _documentManager;
|
||||
private readonly LSPProjectionProvider _projectionProvider;
|
||||
private readonly LSPDocumentMappingProvider _documentMappingProvider;
|
||||
private readonly CSharpBreakpointResolver _csharpBreakpointResolver;
|
||||
|
||||
[ImportingConstructor]
|
||||
public DefaultRazorBreakpointResolver(
|
||||
FileUriProvider fileUriProvider,
|
||||
LSPDocumentManager documentManager,
|
||||
LSPProjectionProvider projectionProvider,
|
||||
LSPDocumentMappingProvider documentMappingProvider,
|
||||
CSharpBreakpointResolver csharpBreakpointResolver)
|
||||
LSPDocumentMappingProvider documentMappingProvider)
|
||||
{
|
||||
if (fileUriProvider is null)
|
||||
{
|
||||
|
@ -53,16 +52,10 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor.Debugging
|
|||
throw new ArgumentNullException(nameof(documentMappingProvider));
|
||||
}
|
||||
|
||||
if (csharpBreakpointResolver is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(csharpBreakpointResolver));
|
||||
}
|
||||
|
||||
_fileUriProvider = fileUriProvider;
|
||||
_documentManager = documentManager;
|
||||
_projectionProvider = projectionProvider;
|
||||
_documentMappingProvider = documentMappingProvider;
|
||||
_csharpBreakpointResolver = csharpBreakpointResolver;
|
||||
}
|
||||
|
||||
public override async Task<Range> TryResolveBreakpointRangeAsync(ITextBuffer textBuffer, int lineIndex, int characterIndex, CancellationToken cancellationToken)
|
||||
|
@ -108,7 +101,7 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor.Debugging
|
|||
|
||||
var sourceText = virtualDocument.Snapshot.AsText();
|
||||
var syntaxTree = CSharpSyntaxTree.ParseText(sourceText, cancellationToken: cancellationToken);
|
||||
if (!_csharpBreakpointResolver.TryGetBreakpointSpan(syntaxTree, projectionResult.PositionIndex, cancellationToken, out var csharpBreakpointSpan))
|
||||
if (!RazorBreakpointSpans.TryGetBreakpointSpan(syntaxTree, projectionResult.PositionIndex, cancellationToken, out var csharpBreakpointSpan))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -5,9 +5,11 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.ExternalAccess.Razor;
|
||||
using Microsoft.CodeAnalysis.Text;
|
||||
using Microsoft.VisualStudio.LanguageServer.ContainedLanguage;
|
||||
using Microsoft.VisualStudio.LanguageServer.Protocol;
|
||||
|
@ -22,14 +24,12 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor.Debugging
|
|||
private readonly FileUriProvider _fileUriProvider;
|
||||
private readonly LSPDocumentManager _documentManager;
|
||||
private readonly LSPProjectionProvider _projectionProvider;
|
||||
private readonly CSharpProximityExpressionResolver _csharpProximityExpressionResolver;
|
||||
|
||||
[ImportingConstructor]
|
||||
public DefaultRazorProximityExpressionResolver(
|
||||
FileUriProvider fileUriProvider,
|
||||
LSPDocumentManager documentManager,
|
||||
LSPProjectionProvider projectionProvider,
|
||||
CSharpProximityExpressionResolver csharpProximityExpressionResolver)
|
||||
LSPProjectionProvider projectionProvider)
|
||||
{
|
||||
if (fileUriProvider is null)
|
||||
{
|
||||
|
@ -46,15 +46,9 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor.Debugging
|
|||
throw new ArgumentNullException(nameof(projectionProvider));
|
||||
}
|
||||
|
||||
if (csharpProximityExpressionResolver is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(csharpProximityExpressionResolver));
|
||||
}
|
||||
|
||||
_fileUriProvider = fileUriProvider;
|
||||
_documentManager = documentManager;
|
||||
_projectionProvider = projectionProvider;
|
||||
_csharpProximityExpressionResolver = csharpProximityExpressionResolver;
|
||||
}
|
||||
|
||||
public override async Task<IReadOnlyList<string>> TryResolveProximityExpressionsAsync(ITextBuffer textBuffer, int lineIndex, int characterIndex, CancellationToken cancellationToken)
|
||||
|
@ -100,10 +94,10 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor.Debugging
|
|||
|
||||
var sourceText = virtualDocument.Snapshot.AsText();
|
||||
var syntaxTree = CSharpSyntaxTree.ParseText(sourceText, cancellationToken: cancellationToken);
|
||||
var proximityExpressions = _csharpProximityExpressionResolver.GetProximityExpressions(syntaxTree, projectionResult.PositionIndex, cancellationToken);
|
||||
var proximityExpressions = RazorCSharpProximityExpressionResolverService.GetProximityExpressions(syntaxTree, projectionResult.PositionIndex, cancellationToken);
|
||||
|
||||
|
||||
return proximityExpressions;
|
||||
return proximityExpressions.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -247,13 +247,11 @@ $@"public class SomeRazorFile
|
|||
.Returns(Task.FromResult<RazorMapToDocumentRangesResponse>(null));
|
||||
}
|
||||
|
||||
var csharpBreakpointResolver = new DefaultCSharpBreakpointResolver();
|
||||
var razorBreakpointResolver = new DefaultRazorBreakpointResolver(
|
||||
uriProvider,
|
||||
documentManager,
|
||||
projectionProvider,
|
||||
documentMappingProvider,
|
||||
csharpBreakpointResolver);
|
||||
documentMappingProvider);
|
||||
|
||||
return razorBreakpointResolver;
|
||||
}
|
||||
|
|
|
@ -190,12 +190,10 @@ $@"public class SomeRazorFile
|
|||
Mock.Get(projectionProvider).Setup(projectionProvider => projectionProvider.GetProjectionAsync(It.IsAny<LSPDocumentSnapshot>(), It.IsAny<Position>(), CancellationToken.None))
|
||||
.Returns(Task.FromResult<ProjectionResult>(null));
|
||||
}
|
||||
var csharpProximityExpressionResolver = new DefaultCSharpProximityExpressionResolver();
|
||||
var razorProximityExpressionResolver = new DefaultRazorProximityExpressionResolver(
|
||||
uriProvider,
|
||||
documentManager,
|
||||
projectionProvider,
|
||||
csharpProximityExpressionResolver);
|
||||
projectionProvider);
|
||||
|
||||
return razorProximityExpressionResolver;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче