зеркало из https://github.com/dotnet/razor.git
Merge remote-tracking branch 'upstream/main' into CohostSigHelp
This commit is contained in:
Коммит
5cb9daf917
|
@ -62,10 +62,11 @@ internal class CohostFoldingRangeEndpoint(
|
|||
protected override RazorTextDocumentIdentifier? GetRazorTextDocumentIdentifier(FoldingRangeParams request)
|
||||
=> request.TextDocument.ToRazorTextDocumentIdentifier();
|
||||
|
||||
protected override async Task<FoldingRange[]?> HandleRequestAsync(FoldingRangeParams request, RazorCohostRequestContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
var razorDocument = context.TextDocument.AssumeNotNull();
|
||||
protected override Task<FoldingRange[]?> HandleRequestAsync(FoldingRangeParams request, RazorCohostRequestContext context, CancellationToken cancellationToken)
|
||||
=> HandleRequestAsync(context.TextDocument.AssumeNotNull(), cancellationToken);
|
||||
|
||||
private async Task<FoldingRange[]?> HandleRequestAsync(TextDocument razorDocument, CancellationToken cancellationToken)
|
||||
{
|
||||
_logger.LogDebug($"Getting folding ranges for {razorDocument.FilePath}");
|
||||
// TODO: Should we have a separate method/service for getting C# ranges, so we can kick off both tasks in parallel? Or are we better off transition to OOP once?
|
||||
var htmlRangesResult = await GetHtmlFoldingRangesAsync(razorDocument, cancellationToken).ConfigureAwait(false);
|
||||
|
@ -123,5 +124,13 @@ internal class CohostFoldingRangeEndpoint(
|
|||
|
||||
return result.Response.SelectAsArray(RemoteFoldingRange.FromLspFoldingRange);
|
||||
}
|
||||
|
||||
internal TestAccessor GetTestAccessor() => new(this);
|
||||
|
||||
internal readonly struct TestAccessor(CohostFoldingRangeEndpoint instance)
|
||||
{
|
||||
public Task<FoldingRange[]?> HandleRequestAsync(TextDocument razorDocument, CancellationToken cancellationToken)
|
||||
=> instance.HandleRequestAsync(razorDocument, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,17 +4,17 @@
|
|||
<body>
|
||||
<trans-unit id="cmdIdShowAllTagHelpers|ButtonText">
|
||||
<source>Show All Tag Helpers</source>
|
||||
<target state="new">Show All Tag Helpers</target>
|
||||
<target state="translated">Zobrazit všechny pomocné elementy značek</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdIdShowInScopeTagHelpers|ButtonText">
|
||||
<source>Show In Scope Tag Helpers</source>
|
||||
<target state="new">Show In Scope Tag Helpers</target>
|
||||
<target state="translated">Zobrazit pomocné elementy značek v oboru</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdIdShowReferencedTagHelpers|ButtonText">
|
||||
<source>Show Referenced Tag Helpers</source>
|
||||
<target state="new">Show Referenced Tag Helpers</target>
|
||||
<target state="translated">Zobrazit odkazované pomocné elementy značek</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdidRazorSyntaxVisualizer|ButtonText">
|
||||
|
|
|
@ -4,17 +4,17 @@
|
|||
<body>
|
||||
<trans-unit id="cmdIdShowAllTagHelpers|ButtonText">
|
||||
<source>Show All Tag Helpers</source>
|
||||
<target state="new">Show All Tag Helpers</target>
|
||||
<target state="translated">Alle Tag-Hilfsprogramme anzeigen</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdIdShowInScopeTagHelpers|ButtonText">
|
||||
<source>Show In Scope Tag Helpers</source>
|
||||
<target state="new">Show In Scope Tag Helpers</target>
|
||||
<target state="translated">Tag-Hilfsprogramme im Bereich anzeigen</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdIdShowReferencedTagHelpers|ButtonText">
|
||||
<source>Show Referenced Tag Helpers</source>
|
||||
<target state="new">Show Referenced Tag Helpers</target>
|
||||
<target state="translated">Referenzierte Tag-Hilfsprogramme anzeigen</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdidRazorSyntaxVisualizer|ButtonText">
|
||||
|
|
|
@ -4,17 +4,17 @@
|
|||
<body>
|
||||
<trans-unit id="cmdIdShowAllTagHelpers|ButtonText">
|
||||
<source>Show All Tag Helpers</source>
|
||||
<target state="new">Show All Tag Helpers</target>
|
||||
<target state="translated">Mostrar todos los asistentes de etiquetas</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdIdShowInScopeTagHelpers|ButtonText">
|
||||
<source>Show In Scope Tag Helpers</source>
|
||||
<target state="new">Show In Scope Tag Helpers</target>
|
||||
<target state="translated">Mostrar asistentes de etiquetas de ámbito</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdIdShowReferencedTagHelpers|ButtonText">
|
||||
<source>Show Referenced Tag Helpers</source>
|
||||
<target state="new">Show Referenced Tag Helpers</target>
|
||||
<target state="translated">Mostrar asistentes de etiquetas a los que se hace referencia</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdidRazorSyntaxVisualizer|ButtonText">
|
||||
|
|
|
@ -4,17 +4,17 @@
|
|||
<body>
|
||||
<trans-unit id="cmdIdShowAllTagHelpers|ButtonText">
|
||||
<source>Show All Tag Helpers</source>
|
||||
<target state="new">Show All Tag Helpers</target>
|
||||
<target state="translated">Afficher toutes les balises d’assistance</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdIdShowInScopeTagHelpers|ButtonText">
|
||||
<source>Show In Scope Tag Helpers</source>
|
||||
<target state="new">Show In Scope Tag Helpers</target>
|
||||
<target state="translated">Afficher les application d’assistance des balises dans l’étendue</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdIdShowReferencedTagHelpers|ButtonText">
|
||||
<source>Show Referenced Tag Helpers</source>
|
||||
<target state="new">Show Referenced Tag Helpers</target>
|
||||
<target state="translated">Afficher les application d’assistance de balise référencée</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdidRazorSyntaxVisualizer|ButtonText">
|
||||
|
|
|
@ -4,17 +4,17 @@
|
|||
<body>
|
||||
<trans-unit id="cmdIdShowAllTagHelpers|ButtonText">
|
||||
<source>Show All Tag Helpers</source>
|
||||
<target state="new">Show All Tag Helpers</target>
|
||||
<target state="translated">Mostra tutti gli helper tag</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdIdShowInScopeTagHelpers|ButtonText">
|
||||
<source>Show In Scope Tag Helpers</source>
|
||||
<target state="new">Show In Scope Tag Helpers</target>
|
||||
<target state="translated">Mostra gli helper tag nell’ambito</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdIdShowReferencedTagHelpers|ButtonText">
|
||||
<source>Show Referenced Tag Helpers</source>
|
||||
<target state="new">Show Referenced Tag Helpers</target>
|
||||
<target state="translated">Mostra gli helper tag di riferimento</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdidRazorSyntaxVisualizer|ButtonText">
|
||||
|
|
|
@ -4,17 +4,17 @@
|
|||
<body>
|
||||
<trans-unit id="cmdIdShowAllTagHelpers|ButtonText">
|
||||
<source>Show All Tag Helpers</source>
|
||||
<target state="new">Show All Tag Helpers</target>
|
||||
<target state="translated">すべてのタグ ヘルパーの表示</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdIdShowInScopeTagHelpers|ButtonText">
|
||||
<source>Show In Scope Tag Helpers</source>
|
||||
<target state="new">Show In Scope Tag Helpers</target>
|
||||
<target state="translated">スコープ内のタグ ヘルパーの表示</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdIdShowReferencedTagHelpers|ButtonText">
|
||||
<source>Show Referenced Tag Helpers</source>
|
||||
<target state="new">Show Referenced Tag Helpers</target>
|
||||
<target state="translated">参照タグ ヘルパーの表示</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdidRazorSyntaxVisualizer|ButtonText">
|
||||
|
|
|
@ -4,17 +4,17 @@
|
|||
<body>
|
||||
<trans-unit id="cmdIdShowAllTagHelpers|ButtonText">
|
||||
<source>Show All Tag Helpers</source>
|
||||
<target state="new">Show All Tag Helpers</target>
|
||||
<target state="translated">모든 태그 도우미 표시</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdIdShowInScopeTagHelpers|ButtonText">
|
||||
<source>Show In Scope Tag Helpers</source>
|
||||
<target state="new">Show In Scope Tag Helpers</target>
|
||||
<target state="translated">범위 태그 도우미에서 표시</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdIdShowReferencedTagHelpers|ButtonText">
|
||||
<source>Show Referenced Tag Helpers</source>
|
||||
<target state="new">Show Referenced Tag Helpers</target>
|
||||
<target state="translated">참조된 태그 도우미 표시</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdidRazorSyntaxVisualizer|ButtonText">
|
||||
|
|
|
@ -4,17 +4,17 @@
|
|||
<body>
|
||||
<trans-unit id="cmdIdShowAllTagHelpers|ButtonText">
|
||||
<source>Show All Tag Helpers</source>
|
||||
<target state="new">Show All Tag Helpers</target>
|
||||
<target state="translated">Pokaż wszystkich pomocników tagów</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdIdShowInScopeTagHelpers|ButtonText">
|
||||
<source>Show In Scope Tag Helpers</source>
|
||||
<target state="new">Show In Scope Tag Helpers</target>
|
||||
<target state="translated">Pokaż pomocników tagów objętych zakresem</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdIdShowReferencedTagHelpers|ButtonText">
|
||||
<source>Show Referenced Tag Helpers</source>
|
||||
<target state="new">Show Referenced Tag Helpers</target>
|
||||
<target state="translated">Pokaż pomocników tagów, których dotyczy odwołanie</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdidRazorSyntaxVisualizer|ButtonText">
|
||||
|
|
|
@ -4,17 +4,17 @@
|
|||
<body>
|
||||
<trans-unit id="cmdIdShowAllTagHelpers|ButtonText">
|
||||
<source>Show All Tag Helpers</source>
|
||||
<target state="new">Show All Tag Helpers</target>
|
||||
<target state="translated">Mostrar todos os auxiliares de marcas</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdIdShowInScopeTagHelpers|ButtonText">
|
||||
<source>Show In Scope Tag Helpers</source>
|
||||
<target state="new">Show In Scope Tag Helpers</target>
|
||||
<target state="translated">Mostrar auxiliares de marcas no escopo</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdIdShowReferencedTagHelpers|ButtonText">
|
||||
<source>Show Referenced Tag Helpers</source>
|
||||
<target state="new">Show Referenced Tag Helpers</target>
|
||||
<target state="translated">Mostrar auxiliares de marcas referenciados</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdidRazorSyntaxVisualizer|ButtonText">
|
||||
|
|
|
@ -4,17 +4,17 @@
|
|||
<body>
|
||||
<trans-unit id="cmdIdShowAllTagHelpers|ButtonText">
|
||||
<source>Show All Tag Helpers</source>
|
||||
<target state="new">Show All Tag Helpers</target>
|
||||
<target state="translated">Показать все тег-хелперы</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdIdShowInScopeTagHelpers|ButtonText">
|
||||
<source>Show In Scope Tag Helpers</source>
|
||||
<target state="new">Show In Scope Tag Helpers</target>
|
||||
<target state="translated">Показать тег-хелперы в области</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdIdShowReferencedTagHelpers|ButtonText">
|
||||
<source>Show Referenced Tag Helpers</source>
|
||||
<target state="new">Show Referenced Tag Helpers</target>
|
||||
<target state="translated">Показать указанные тег-хелперы</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdidRazorSyntaxVisualizer|ButtonText">
|
||||
|
|
|
@ -4,17 +4,17 @@
|
|||
<body>
|
||||
<trans-unit id="cmdIdShowAllTagHelpers|ButtonText">
|
||||
<source>Show All Tag Helpers</source>
|
||||
<target state="new">Show All Tag Helpers</target>
|
||||
<target state="translated">Tüm Etiket Yardımcılarını Göster</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdIdShowInScopeTagHelpers|ButtonText">
|
||||
<source>Show In Scope Tag Helpers</source>
|
||||
<target state="new">Show In Scope Tag Helpers</target>
|
||||
<target state="translated">Kapsam Etiketi Yardımcılarında Göster</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdIdShowReferencedTagHelpers|ButtonText">
|
||||
<source>Show Referenced Tag Helpers</source>
|
||||
<target state="new">Show Referenced Tag Helpers</target>
|
||||
<target state="translated">Başvurulan Etiket Yardımcılarını Göster</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdidRazorSyntaxVisualizer|ButtonText">
|
||||
|
|
|
@ -4,17 +4,17 @@
|
|||
<body>
|
||||
<trans-unit id="cmdIdShowAllTagHelpers|ButtonText">
|
||||
<source>Show All Tag Helpers</source>
|
||||
<target state="new">Show All Tag Helpers</target>
|
||||
<target state="translated">显示所有标记帮助程序</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdIdShowInScopeTagHelpers|ButtonText">
|
||||
<source>Show In Scope Tag Helpers</source>
|
||||
<target state="new">Show In Scope Tag Helpers</target>
|
||||
<target state="translated">显示作用域内标记帮助程序</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdIdShowReferencedTagHelpers|ButtonText">
|
||||
<source>Show Referenced Tag Helpers</source>
|
||||
<target state="new">Show Referenced Tag Helpers</target>
|
||||
<target state="translated">显示引用的标记帮助程序</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdidRazorSyntaxVisualizer|ButtonText">
|
||||
|
|
|
@ -4,17 +4,17 @@
|
|||
<body>
|
||||
<trans-unit id="cmdIdShowAllTagHelpers|ButtonText">
|
||||
<source>Show All Tag Helpers</source>
|
||||
<target state="new">Show All Tag Helpers</target>
|
||||
<target state="translated">顯示所有標籤協助程式</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdIdShowInScopeTagHelpers|ButtonText">
|
||||
<source>Show In Scope Tag Helpers</source>
|
||||
<target state="new">Show In Scope Tag Helpers</target>
|
||||
<target state="translated">顯示涵蓋在範圍內的標籤協助程式</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdIdShowReferencedTagHelpers|ButtonText">
|
||||
<source>Show Referenced Tag Helpers</source>
|
||||
<target state="new">Show Referenced Tag Helpers</target>
|
||||
<target state="translated">顯示參照的標籤協助程式</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="cmdidRazorSyntaxVisualizer|ButtonText">
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the MIT license. See License.txt in the project root for license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Microsoft.AspNetCore.Razor.Language;
|
||||
using Microsoft.AspNetCore.Razor.ProjectEngineHost;
|
||||
using Microsoft.AspNetCore.Razor.Test.Common.ProjectSystem;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.Host;
|
||||
using Microsoft.CodeAnalysis.Host.Mef;
|
||||
using Microsoft.CodeAnalysis.Razor.Workspaces;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
|
@ -63,14 +63,6 @@ public abstract class WorkspaceTestBase(ITestOutputHelper testOutput) : ToolingT
|
|||
private protected TestProjectSnapshotManager CreateProjectSnapshotManager(IProjectEngineFactoryProvider projectEngineFactoryProvider)
|
||||
=> new(projectEngineFactoryProvider, LoggerFactory, DisposalToken);
|
||||
|
||||
protected virtual void ConfigureWorkspaceServices(List<IWorkspaceService> services)
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void ConfigureLanguageServices(List<ILanguageService> services)
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void ConfigureWorkspace(AdhocWorkspace workspace)
|
||||
{
|
||||
}
|
||||
|
@ -96,13 +88,7 @@ public abstract class WorkspaceTestBase(ITestOutputHelper testOutput) : ToolingT
|
|||
Configure = ConfigureProjectEngine,
|
||||
};
|
||||
|
||||
var workspaceServices = new List<IWorkspaceService>();
|
||||
ConfigureWorkspaceServices(workspaceServices);
|
||||
|
||||
var languageServices = new List<ILanguageService>();
|
||||
ConfigureLanguageServices(languageServices);
|
||||
|
||||
_hostServices = TestServices.Create(workspaceServices, languageServices);
|
||||
_hostServices = MefHostServices.DefaultHost;
|
||||
_workspace = TestWorkspace.Create(_hostServices, ConfigureWorkspace);
|
||||
AddDisposable(_workspace);
|
||||
_workspaceProvider = new TestWorkspaceProvider(_workspace);
|
||||
|
|
|
@ -19,7 +19,7 @@ using Xunit.Abstractions;
|
|||
|
||||
namespace Microsoft.VisualStudio.Razor.LanguageClient.Cohost;
|
||||
|
||||
public abstract class CohostTestBase(ITestOutputHelper testOutputHelper) : WorkspaceTestBase(testOutputHelper)
|
||||
public abstract class CohostEndpointTestBase(ITestOutputHelper testOutputHelper) : WorkspaceTestBase(testOutputHelper)
|
||||
{
|
||||
private const string CSharpVirtualDocumentSuffix = ".g.cs";
|
||||
private ExportProvider? _exportProvider;
|
|
@ -0,0 +1,289 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the MIT license. See License.txt in the project root for license information.
|
||||
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Razor;
|
||||
using Microsoft.AspNetCore.Razor.Language;
|
||||
using Microsoft.AspNetCore.Razor.PooledObjects;
|
||||
using Microsoft.CodeAnalysis.Razor.Workspaces;
|
||||
using Microsoft.CodeAnalysis.Testing;
|
||||
using Microsoft.CodeAnalysis.Text;
|
||||
using Microsoft.VisualStudio.LanguageServer.Protocol;
|
||||
using Roslyn.Test.Utilities;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Microsoft.VisualStudio.Razor.LanguageClient.Cohost;
|
||||
|
||||
public class CohostFoldingRangeEndpointTest(ITestOutputHelper testOutputHelper) : CohostEndpointTestBase(testOutputHelper)
|
||||
{
|
||||
[Fact]
|
||||
public Task IfStatements()
|
||||
=> VerifyFoldingRangesAsync("""
|
||||
<div>
|
||||
@if (true) {[|
|
||||
<div>
|
||||
Hello World
|
||||
</div>
|
||||
}|]
|
||||
</div>
|
||||
|
||||
@if (true) {[|
|
||||
<div>
|
||||
Hello World
|
||||
</div>
|
||||
}|]
|
||||
|
||||
@if (true) {[|
|
||||
}|]
|
||||
""");
|
||||
|
||||
[Fact]
|
||||
public Task LockStatement()
|
||||
=> VerifyFoldingRangesAsync("""
|
||||
@lock (new object()) {[|
|
||||
}|]
|
||||
""");
|
||||
|
||||
[Fact]
|
||||
public Task UsingStatement()
|
||||
=> VerifyFoldingRangesAsync("""
|
||||
@using (new object()) {[|
|
||||
}|]
|
||||
""");
|
||||
|
||||
[Fact]
|
||||
public Task IfElseStatements()
|
||||
=> VerifyFoldingRangesAsync("""
|
||||
<div>
|
||||
@if (true) {[|
|
||||
<div>
|
||||
Hello World
|
||||
</div>
|
||||
else {[|
|
||||
<div>
|
||||
Goodbye World
|
||||
</div>
|
||||
}|]
|
||||
}|]
|
||||
</div>
|
||||
""");
|
||||
|
||||
[Fact]
|
||||
public Task Usings()
|
||||
=> VerifyFoldingRangesAsync("""
|
||||
@using System[|
|
||||
@using System.Text|]
|
||||
|
||||
<p>hello!</p>
|
||||
|
||||
@using System.Buffers[|
|
||||
@using System.Drawing
|
||||
@using System.CodeDom|]
|
||||
|
||||
<p>hello!</p>
|
||||
""");
|
||||
|
||||
[Fact]
|
||||
public Task CSharpStatement()
|
||||
=> VerifyFoldingRangesAsync("""
|
||||
<p>hello!</p>
|
||||
|
||||
@{[|
|
||||
var helloWorld = "";
|
||||
}|]
|
||||
|
||||
@(DateTime
|
||||
.Now)
|
||||
|
||||
<p>hello!</p>
|
||||
""");
|
||||
|
||||
[Fact]
|
||||
public Task CSharpStatement_Nested()
|
||||
=> VerifyFoldingRangesAsync("""
|
||||
<p>hello!</p>
|
||||
|
||||
<div>
|
||||
|
||||
@{[|
|
||||
var helloWorld = "";
|
||||
}|]
|
||||
|
||||
</div>
|
||||
|
||||
@(DateTime
|
||||
.Now)
|
||||
|
||||
<p>hello!</p>
|
||||
""");
|
||||
|
||||
[Fact]
|
||||
public Task CSharpStatement_NotSingleLine()
|
||||
=> VerifyFoldingRangesAsync("""
|
||||
<p>hello!</p>
|
||||
|
||||
@{ var helloWorld = ""; }
|
||||
|
||||
<p>hello!</p>
|
||||
""");
|
||||
|
||||
[Fact]
|
||||
public Task CodeBlock()
|
||||
=> VerifyFoldingRangesAsync("""
|
||||
<p>hello!</p>
|
||||
|
||||
@code {[|
|
||||
var helloWorld = "";
|
||||
}|]
|
||||
|
||||
<p>hello!</p>
|
||||
""");
|
||||
|
||||
[Fact]
|
||||
public Task CodeBlock_Mvc()
|
||||
=> VerifyFoldingRangesAsync("""
|
||||
<p>hello!</p>
|
||||
|
||||
@functions {[|
|
||||
var helloWorld = "";
|
||||
}|]
|
||||
|
||||
<p>hello!</p>
|
||||
""",
|
||||
fileKind: FileKinds.Legacy);
|
||||
|
||||
[Fact]
|
||||
public Task Section()
|
||||
=> VerifyFoldingRangesAsync("""
|
||||
<p>hello!</p>
|
||||
|
||||
@section Hello {[|
|
||||
<p>Hello</p>
|
||||
}|]
|
||||
|
||||
<p>hello!</p>
|
||||
""",
|
||||
fileKind: FileKinds.Legacy);
|
||||
|
||||
[Fact]
|
||||
public Task Section_Invalid()
|
||||
=> VerifyFoldingRangesAsync("""
|
||||
<p>hello!</p>
|
||||
|
||||
@section {
|
||||
<p>Hello</p>
|
||||
}
|
||||
|
||||
<p>hello!</p>
|
||||
""",
|
||||
fileKind: FileKinds.Legacy);
|
||||
|
||||
[Fact]
|
||||
public Task CSharpCodeInCodeBlocks()
|
||||
=> VerifyFoldingRangesAsync("""
|
||||
<div>
|
||||
Hello @_name
|
||||
</div>
|
||||
|
||||
@code {[|
|
||||
private string _name = "Dave";
|
||||
|
||||
public void M() {[|
|
||||
}|]
|
||||
}|]
|
||||
""");
|
||||
|
||||
[Fact]
|
||||
public Task HtmlAndCSharp()
|
||||
=> VerifyFoldingRangesAsync("""
|
||||
<div>{|html:
|
||||
Hello @_name
|
||||
|
||||
<div>{|html:
|
||||
Nests aren't just for birds!
|
||||
</div>|}
|
||||
</div>|}
|
||||
|
||||
@code {[|
|
||||
private string _name = "Dave";
|
||||
|
||||
public void M() {[|
|
||||
}|]
|
||||
}|]
|
||||
""");
|
||||
|
||||
private async Task VerifyFoldingRangesAsync(string input, string? fileKind = null)
|
||||
{
|
||||
TestFileMarkupParser.GetSpans(input, out var source, out ImmutableDictionary<string, ImmutableArray<TextSpan>> spans);
|
||||
var document = CreateProjectAndRazorDocument(source, fileKind);
|
||||
var inputText = await document.GetTextAsync(DisposalToken);
|
||||
|
||||
var htmlSpans = spans.GetValueOrDefault("html").NullToEmpty();
|
||||
var htmlRanges = htmlSpans
|
||||
.Select(span =>
|
||||
{
|
||||
inputText.GetLineAndOffset(span.Start, out var startLine, out var startCharacter);
|
||||
inputText.GetLineAndOffset(span.End, out var endLine, out var endCharacter);
|
||||
return new FoldingRange()
|
||||
{
|
||||
StartLine = startLine,
|
||||
StartCharacter = startCharacter,
|
||||
EndLine = endLine,
|
||||
EndCharacter = endCharacter
|
||||
};
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
var requestInvoker = new TestLSPRequestInvoker([(Methods.TextDocumentFoldingRangeName, htmlRanges)]);
|
||||
|
||||
var endpoint = new CohostFoldingRangeEndpoint(RemoteServiceInvoker, TestHtmlDocumentSynchronizer.Instance, requestInvoker, LoggerFactory);
|
||||
|
||||
var result = await endpoint.GetTestAccessor().HandleRequestAsync(document, DisposalToken);
|
||||
|
||||
if (spans.Count == 0)
|
||||
{
|
||||
Assert.Null(result);
|
||||
return;
|
||||
}
|
||||
|
||||
var actual = GenerateTestInput(inputText, htmlSpans, result.AssumeNotNull());
|
||||
|
||||
AssertEx.EqualOrDiff(input, actual);
|
||||
}
|
||||
|
||||
private static string GenerateTestInput(SourceText inputText, ImmutableArray<TextSpan> htmlSpans, FoldingRange[] result)
|
||||
{
|
||||
var markerPositions = result
|
||||
.SelectMany(r =>
|
||||
new[] {
|
||||
(index: inputText.GetRequiredAbsoluteIndex(r.StartLine, r.StartCharacter.AssumeNotNull()), isStart: true),
|
||||
(index: inputText.GetRequiredAbsoluteIndex(r.EndLine, r.EndCharacter.AssumeNotNull()), isStart: false)
|
||||
});
|
||||
|
||||
var actual = new StringBuilder(inputText.ToString());
|
||||
foreach (var marker in markerPositions.OrderByDescending(p => p.index))
|
||||
{
|
||||
actual.Insert(marker.index, GetMarker(marker.index, marker.isStart, htmlSpans));
|
||||
}
|
||||
|
||||
static string GetMarker(int index, bool isStart, ImmutableArray<TextSpan> htmlSpans)
|
||||
{
|
||||
if (isStart)
|
||||
{
|
||||
return htmlSpans.Any(r => r.Start == index)
|
||||
? "{|html:"
|
||||
: "[|";
|
||||
}
|
||||
|
||||
return htmlSpans.Any(r => r.End == index)
|
||||
? "|}"
|
||||
: "|]";
|
||||
}
|
||||
|
||||
return actual.ToString();
|
||||
}
|
||||
}
|
|
@ -14,7 +14,7 @@ using Xunit.Abstractions;
|
|||
|
||||
namespace Microsoft.VisualStudio.Razor.LanguageClient.Cohost;
|
||||
|
||||
public class CohostLinkedEditingRangeEndpointTest(ITestOutputHelper testOutputHelper) : CohostTestBase(testOutputHelper)
|
||||
public class CohostLinkedEditingRangeEndpointTest(ITestOutputHelper testOutputHelper) : CohostEndpointTestBase(testOutputHelper)
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("$$PageTitle", "PageTitle")]
|
||||
|
|
|
@ -21,7 +21,7 @@ using Xunit.Abstractions;
|
|||
|
||||
namespace Microsoft.VisualStudio.Razor.LanguageClient.Cohost;
|
||||
|
||||
public class CohostSemanticTokensRangeEndpointTest(ITestOutputHelper testOutputHelper) : CohostTestBase(testOutputHelper)
|
||||
public class CohostSemanticTokensRangeEndpointTest(ITestOutputHelper testOutputHelper) : CohostEndpointTestBase(testOutputHelper)
|
||||
{
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the MIT license. See License.txt in the project root for license information.
|
||||
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Razor.Test.Common.VisualStudio;
|
||||
using Microsoft.CodeAnalysis;
|
||||
|
||||
namespace Microsoft.VisualStudio.Razor.LanguageClient.Cohost;
|
||||
|
||||
internal sealed class TestHtmlDocumentSynchronizer : IHtmlDocumentSynchronizer
|
||||
{
|
||||
public static TestHtmlDocumentSynchronizer Instance = new();
|
||||
|
||||
public Task<HtmlDocumentResult?> TryGetSynchronizedHtmlDocumentAsync(TextDocument razorDocument, CancellationToken cancellationToken)
|
||||
{
|
||||
var filePath = razorDocument.FilePath + ".g.html";
|
||||
return Task.FromResult<HtmlDocumentResult?>(new HtmlDocumentResult(new System.Uri(filePath), VsMocks.CreateTextBuffer(core: false)));
|
||||
}
|
||||
|
||||
public Task<bool> TrySynchronizeAsync(TextDocument document, CancellationToken cancellationToken)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer;
|
||||
|
@ -17,9 +18,15 @@ namespace Microsoft.VisualStudio.Razor.LanguageClient;
|
|||
internal class TestLSPRequestInvoker : LSPRequestInvoker
|
||||
{
|
||||
private readonly CSharpTestLspServer _csharpServer;
|
||||
private readonly Dictionary<string, object> _htmlResponses;
|
||||
|
||||
public TestLSPRequestInvoker() { }
|
||||
|
||||
public TestLSPRequestInvoker(List<(string method, object response)> htmlResponses)
|
||||
{
|
||||
_htmlResponses = htmlResponses.ToDictionary(kvp => kvp.method, kvp => kvp.response);
|
||||
}
|
||||
|
||||
public TestLSPRequestInvoker(CSharpTestLspServer csharpServer)
|
||||
{
|
||||
if (csharpServer is null)
|
||||
|
@ -104,6 +111,11 @@ internal class TestLSPRequestInvoker : LSPRequestInvoker
|
|||
return new ReinvocationResponse<TOut>(languageClientName: RazorLSPConstants.RazorCSharpLanguageServerName, result);
|
||||
}
|
||||
|
||||
if (_htmlResponses.TryGetValue(method, out var response))
|
||||
{
|
||||
return new ReinvocationResponse<TOut>(languageClientName: "html", (TOut)response);
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче