Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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.Language;
using Microsoft.VisualStudio.LanguageServer.Protocol;

namespace Microsoft.AspNetCore.Razor.LanguageServer.Hover;

internal sealed partial class HoverService
{
internal TestAccessor GetTestAccessor() => new(this);

internal sealed class TestAccessor(HoverService instance)
{
public Task<VSInternalHover?> GetHoverInfoAsync(
string documentFilePath,
RazorCodeDocument codeDocument,
SourceLocation location,
VSInternalClientCapabilities clientCapabilities,
CancellationToken cancellationToken)
=> instance.GetHoverInfoAsync(documentFilePath, codeDocument, location, clientCapabilities, cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

namespace Microsoft.AspNetCore.Razor.LanguageServer.Hover;

internal sealed class HoverService(
internal sealed partial class HoverService(
LSPTagHelperTooltipFactory lspTagHelperTooltipFactory,
VSLSPTagHelperTooltipFactory vsLspTagHelperTooltipFactory,
IRazorDocumentMappingService mappingService,
Expand Down Expand Up @@ -94,15 +94,13 @@ internal sealed class HoverService(
return response;
}

public TestAccessor GetTestAccessor() => new(this);

public async Task<VSInternalHover?> GetHoverInfoAsync(string documentFilePath, RazorCodeDocument codeDocument, SourceLocation location, VSInternalClientCapabilities clientCapabilities, CancellationToken cancellationToken)
private async Task<VSInternalHover?> GetHoverInfoAsync(
string documentFilePath,
RazorCodeDocument codeDocument,
SourceLocation location,
VSInternalClientCapabilities clientCapabilities,
CancellationToken cancellationToken)
{
if (codeDocument is null)
{
throw new ArgumentNullException(nameof(codeDocument));
}

var syntaxTree = codeDocument.GetSyntaxTree();

var owner = syntaxTree.Root.FindInnermostNode(location.AbsoluteIndex);
Expand Down Expand Up @@ -350,10 +348,4 @@ private static VisualStudioMarkupKind GetHoverContentFormat(ClientCapabilities c
var hoverKind = hoverContentFormat?.Contains(VisualStudioMarkupKind.Markdown) == true ? VisualStudioMarkupKind.Markdown : VisualStudioMarkupKind.PlainText;
return hoverKind;
}

public class TestAccessor(HoverService service)
{
public Task<VSInternalHover?> GetHoverInfoAsync(string documentFilePath, RazorCodeDocument codeDocument, SourceLocation location, VSInternalClientCapabilities clientCapabilities, CancellationToken cancellationToken)
=> service.GetHoverInfoAsync(documentFilePath, codeDocument, location, clientCapabilities, cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem;

internal interface ISnapshotResolver
{
Task InitializeAsync(CancellationToken cancellationToken);

/// <summary>
/// Finds all the projects where the document path starts with the path of the folder that contains the project file.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ public SnapshotResolver(IProjectSnapshotManager projectManager, ILoggerFactory l
MiscellaneousHostProject = new HostProject(normalizedPath, normalizedPath, FallbackRazorConfiguration.Latest, rootNamespace: null, "Miscellaneous Files");
}

public Task InitializeAsync(CancellationToken cancellationToken)
{
// This is called when the language server is initialized.

return _projectManager.UpdateAsync(
(updater, miscHostProject) => updater.ProjectAdded(miscHostProject),
state: MiscellaneousHostProject,
cancellationToken);
}

/// <inheritdoc/>
public ImmutableArray<IProjectSnapshot> FindPotentialProjects(string documentFilePath)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts;
using Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.CommonLanguageServerProtocol.Framework;
using Microsoft.VisualStudio.LanguageServer.Protocol;
Expand All @@ -20,6 +21,9 @@ public async Task HandleNotificationAsync(InitializedParams request, RazorReques
var onStartedItems = requestContext.LspServices.GetRequiredServices<IOnInitialized>();
var capabilitiesService = requestContext.GetRequiredService<IClientCapabilitiesService>();

var snapshotResolver = requestContext.LspServices.GetRequiredService<ISnapshotResolver>();
await snapshotResolver.InitializeAsync(cancellationToken).ConfigureAwait(false);

var fileChangeDetectorManager = requestContext.LspServices.GetRequiredService<RazorFileChangeDetectorManager>();
await fileChangeDetectorManager.InitializedAsync(cancellationToken).ConfigureAwait(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public async Task TryCreateTooltip_Markup_NoAssociatedTagHelperDescriptions_Retu
{
// Arrange
var snapshotResolver = new TestSnapshotResolver();
await snapshotResolver.InitializeAsync(DisposalToken);
var descriptionFactory = new DefaultLSPTagHelperTooltipFactory(snapshotResolver);
var elementDescription = AggregateBoundElementDescription.Empty;

Expand All @@ -82,6 +83,7 @@ public async Task TryCreateTooltip_Markup_Element_SingleAssociatedTagHelper_Retu
{
// Arrange
var snapshotResolver = new TestSnapshotResolver();
await snapshotResolver.InitializeAsync(DisposalToken);
var descriptionFactory = new DefaultLSPTagHelperTooltipFactory(snapshotResolver);
var associatedTagHelperInfos = new[]
{
Expand All @@ -104,6 +106,7 @@ public async Task TryCreateTooltip_Markup_Element_PlainText_NoBold()
{
// Arrange
var snapshotResolver = new TestSnapshotResolver();
await snapshotResolver.InitializeAsync(DisposalToken);
var descriptionFactory = new DefaultLSPTagHelperTooltipFactory(snapshotResolver);
var associatedTagHelperInfos = new[]
{
Expand All @@ -123,10 +126,11 @@ public async Task TryCreateTooltip_Markup_Element_PlainText_NoBold()
}

[Fact]
public void TryCreateTooltip_Markup_Attribute_PlainText_NoBold()
public async Task TryCreateTooltip_Markup_Attribute_PlainText_NoBold()
{
// Arrange
var snapshotResolver = new TestSnapshotResolver();
await snapshotResolver.InitializeAsync(DisposalToken);
var descriptionFactory = new DefaultLSPTagHelperTooltipFactory(snapshotResolver);
var associatedAttributeDescriptions = new[]
{
Expand Down Expand Up @@ -154,6 +158,7 @@ public async Task TryCreateTooltip_Markup_Element_MultipleAssociatedTagHelpers_R
{
// Arrange
var snapshotResolver = new TestSnapshotResolver();
await snapshotResolver.InitializeAsync(DisposalToken);
var descriptionFactory = new DefaultLSPTagHelperTooltipFactory(snapshotResolver);
var associatedTagHelperInfos = new[]
{
Expand All @@ -178,10 +183,11 @@ public async Task TryCreateTooltip_Markup_Element_MultipleAssociatedTagHelpers_R
}

[Fact]
public void TryCreateTooltip_Markup_Attribute_SingleAssociatedAttribute_ReturnsTrue()
public async Task TryCreateTooltip_Markup_Attribute_SingleAssociatedAttribute_ReturnsTrue()
{
// Arrange
var snapshotResolver = new TestSnapshotResolver();
await snapshotResolver.InitializeAsync(DisposalToken);
var descriptionFactory = new DefaultLSPTagHelperTooltipFactory(snapshotResolver);
var associatedAttributeDescriptions = new[]
{
Expand All @@ -205,10 +211,11 @@ public void TryCreateTooltip_Markup_Attribute_SingleAssociatedAttribute_ReturnsT
}

[Fact]
public void TryCreateTooltip_Markup_Attribute_MultipleAssociatedAttributes_ReturnsTrue()
public async Task TryCreateTooltip_Markup_Attribute_MultipleAssociatedAttributes_ReturnsTrue()
{
// Arrange
var snapshotResolver = new TestSnapshotResolver();
await snapshotResolver.InitializeAsync(DisposalToken);
var descriptionFactory = new DefaultLSPTagHelperTooltipFactory(snapshotResolver);
var associatedAttributeDescriptions = new[]
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ public async Task TryCreateTooltip_ClassifiedTextElement_NoAssociatedTagHelperDe
{
// Arrange
var snapshotResolver = new TestSnapshotResolver();
await snapshotResolver.InitializeAsync(DisposalToken);
var descriptionFactory = new DefaultVSLSPTagHelperTooltipFactory(snapshotResolver);
var elementDescription = AggregateBoundElementDescription.Empty;

Expand All @@ -186,6 +187,7 @@ public async Task TryCreateTooltip_ClassifiedTextElement_Element_SingleAssociate
{
// Arrange
var snapshotResolver = new TestSnapshotResolver();
await snapshotResolver.InitializeAsync(DisposalToken);
var descriptionFactory = new DefaultVSLSPTagHelperTooltipFactory(snapshotResolver);
var associatedTagHelperInfos = new[]
{
Expand Down Expand Up @@ -227,6 +229,7 @@ public async Task TryCreateTooltip_ClassifiedTextElement_Element_NamespaceContai
{
// Arrange
var snapshotResolver = new TestSnapshotResolver();
await snapshotResolver.InitializeAsync(DisposalToken);
var descriptionFactory = new DefaultVSLSPTagHelperTooltipFactory(snapshotResolver);
var associatedTagHelperInfos = new[]
{
Expand Down Expand Up @@ -267,6 +270,7 @@ public async Task TryCreateTooltip_ClassifiedTextElement_Element_MultipleAssocia
{
// Arrange
var snapshotResolver = new TestSnapshotResolver();
await snapshotResolver.InitializeAsync(DisposalToken);
var descriptionFactory = new DefaultVSLSPTagHelperTooltipFactory(snapshotResolver);
var associatedTagHelperInfos = new[]
{
Expand Down Expand Up @@ -317,10 +321,11 @@ public async Task TryCreateTooltip_ClassifiedTextElement_Element_MultipleAssocia
}

[Fact]
public void TryCreateTooltip_ClassifiedTextElement_NoAssociatedAttributeDescriptions_ReturnsFalse()
public async Task TryCreateTooltip_ClassifiedTextElement_NoAssociatedAttributeDescriptions_ReturnsFalse()
{
// Arrange
var snapshotResolver = new TestSnapshotResolver();
await snapshotResolver.InitializeAsync(DisposalToken);
var descriptionFactory = new DefaultVSLSPTagHelperTooltipFactory(snapshotResolver);
var elementDescription = AggregateBoundAttributeDescription.Empty;

Expand All @@ -333,10 +338,11 @@ public void TryCreateTooltip_ClassifiedTextElement_NoAssociatedAttributeDescript
}

[Fact]
public void TryCreateTooltip_ClassifiedTextElement_Attribute_SingleAssociatedAttribute_ReturnsTrue_NestedTypes()
public async Task TryCreateTooltip_ClassifiedTextElement_Attribute_SingleAssociatedAttribute_ReturnsTrue_NestedTypes()
{
// Arrange
var snapshotResolver = new TestSnapshotResolver();
await snapshotResolver.InitializeAsync(DisposalToken);
var descriptionFactory = new DefaultVSLSPTagHelperTooltipFactory(snapshotResolver);
var associatedAttributeDescriptions = new[]
{
Expand Down Expand Up @@ -382,10 +388,11 @@ public void TryCreateTooltip_ClassifiedTextElement_Attribute_SingleAssociatedAtt
}

[Fact]
public void TryCreateTooltip_ClassifiedTextElement_Attribute_MultipleAssociatedAttributes_ReturnsTrue()
public async Task TryCreateTooltip_ClassifiedTextElement_Attribute_MultipleAssociatedAttributes_ReturnsTrue()
{
// Arrange
var snapshotResolver = new TestSnapshotResolver();
await snapshotResolver.InitializeAsync(DisposalToken);
var descriptionFactory = new DefaultVSLSPTagHelperTooltipFactory(snapshotResolver);
var associatedAttributeDescriptions = new[]
{
Expand Down Expand Up @@ -461,6 +468,7 @@ public async Task TryCreateTooltip_ContainerElement_NoAssociatedTagHelperDescrip
{
// Arrange
var snapshotResolver = new TestSnapshotResolver();
await snapshotResolver.InitializeAsync(DisposalToken);
var descriptionFactory = new DefaultVSLSPTagHelperTooltipFactory(snapshotResolver);
var elementDescription = AggregateBoundElementDescription.Empty;

Expand All @@ -476,6 +484,7 @@ public async Task TryCreateTooltip_ContainerElement_Attribute_MultipleAssociated
{
// Arrange
var snapshotResolver = new TestSnapshotResolver();
await snapshotResolver.InitializeAsync(DisposalToken);
var descriptionFactory = new DefaultVSLSPTagHelperTooltipFactory(snapshotResolver);
var associatedTagHelperInfos = new[]
{
Expand Down Expand Up @@ -556,10 +565,11 @@ public async Task TryCreateTooltip_ContainerElement_Attribute_MultipleAssociated
}

[Fact]
public void TryCreateTooltip_ContainerElement_NoAssociatedAttributeDescriptions_ReturnsFalse()
public async Task TryCreateTooltip_ContainerElement_NoAssociatedAttributeDescriptions_ReturnsFalse()
{
// Arrange
var snapshotResolver = new TestSnapshotResolver();
await snapshotResolver.InitializeAsync(DisposalToken);
var descriptionFactory = new DefaultVSLSPTagHelperTooltipFactory(snapshotResolver);
var elementDescription = AggregateBoundAttributeDescription.Empty;

Expand All @@ -572,10 +582,11 @@ public void TryCreateTooltip_ContainerElement_NoAssociatedAttributeDescriptions_
}

[Fact]
public void TryCreateTooltip_ContainerElement_Attribute_MultipleAssociatedAttributes_ReturnsTrue()
public async Task TryCreateTooltip_ContainerElement_Attribute_MultipleAssociatedAttributes_ReturnsTrue()
{
// Arrange
var snapshotResolver = new TestSnapshotResolver();
await snapshotResolver.InitializeAsync(DisposalToken);
var descriptionFactory = new DefaultVSLSPTagHelperTooltipFactory(snapshotResolver);
var associatedAttributeDescriptions = new[]
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@

namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion;

public class LegacyRazorCompletionResolveEndpointTest : LanguageServerTestBase
public class LegacyRazorCompletionResolveEndpointTest(ITestOutputHelper testOutput) : LanguageServerTestBase(testOutput)
{
private readonly LSPTagHelperTooltipFactory _lspTagHelperTooltipFactory;
private readonly VSLSPTagHelperTooltipFactory _vsLspTagHelperTooltipFactory;
private readonly CompletionListCache _completionListCache;
private readonly VSInternalCompletionSetting _completionCapability;
private readonly VSInternalClientCapabilities _defaultClientCapability;

public LegacyRazorCompletionResolveEndpointTest(ITestOutputHelper testOutput)
: base(testOutput)
private LSPTagHelperTooltipFactory _lspTagHelperTooltipFactory;
private VSLSPTagHelperTooltipFactory _vsLspTagHelperTooltipFactory;
private CompletionListCache _completionListCache;
private VSInternalCompletionSetting _completionCapability;
private VSInternalClientCapabilities _defaultClientCapability;

protected async override Task InitializeAsync()
{
var snapshotResolver = new TestSnapshotResolver();
await snapshotResolver.InitializeAsync(DisposalToken);
_lspTagHelperTooltipFactory = new Mock<LSPTagHelperTooltipFactory>(MockBehavior.Strict, snapshotResolver).Object;
_vsLspTagHelperTooltipFactory = new Mock<VSLSPTagHelperTooltipFactory>(MockBehavior.Strict, snapshotResolver).Object;
_completionListCache = new CompletionListCache();
Expand Down Expand Up @@ -97,6 +97,7 @@ public async Task Handle_Resolve_DirectiveAttributeCompletion_ReturnsCompletionI
{
// Arrange
var snapshotResolver = new TestSnapshotResolver();
await snapshotResolver.InitializeAsync(DisposalToken);
var lspDescriptionFactory = new Mock<LSPTagHelperTooltipFactory>(MockBehavior.Strict, snapshotResolver);
var markdown = new MarkupContent
{
Expand Down Expand Up @@ -126,6 +127,7 @@ public async Task Handle_Resolve_DirectiveAttributeParameterCompletion_ReturnsCo
{
// Arrange
var snapshotResolver = new TestSnapshotResolver();
await snapshotResolver.InitializeAsync(DisposalToken);
var descriptionFactory = new Mock<LSPTagHelperTooltipFactory>(MockBehavior.Strict, snapshotResolver);
var markdown = new MarkupContent
{
Expand Down Expand Up @@ -155,6 +157,7 @@ public async Task Handle_Resolve_TagHelperElementCompletion_ReturnsCompletionIte
{
// Arrange
var snapshotResolver = new TestSnapshotResolver();
await snapshotResolver.InitializeAsync(DisposalToken);
var lspDescriptionFactory = new Mock<LSPTagHelperTooltipFactory>(MockBehavior.Strict, snapshotResolver);
var markdown = new MarkupContent
{
Expand Down Expand Up @@ -184,6 +187,7 @@ public async Task Handle_Resolve_TagHelperAttribute_ReturnsCompletionItemWithDoc
{
// Arrange
var snapshotResolver = new TestSnapshotResolver();
await snapshotResolver.InitializeAsync(DisposalToken);
var lspDescriptionFactory = new Mock<LSPTagHelperTooltipFactory>(MockBehavior.Strict, snapshotResolver);
var markdown = new MarkupContent
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,21 @@

namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion;

public class RazorCompletionItemResolverTest : LanguageServerTestBase
public class RazorCompletionItemResolverTest(ITestOutputHelper testOutput) : LanguageServerTestBase(testOutput)
{
private readonly LSPTagHelperTooltipFactory _lspTagHelperTooltipFactory;
private readonly VSLSPTagHelperTooltipFactory _vsLspTagHelperTooltipFactory;
private readonly VSInternalCompletionSetting _completionCapability;
private readonly VSInternalClientCapabilities _defaultClientCapability;
private readonly VSInternalClientCapabilities _vsClientCapability;
private readonly AggregateBoundAttributeDescription _attributeDescription;
private readonly AggregateBoundElementDescription _elementDescription;

public RazorCompletionItemResolverTest(ITestOutputHelper testOutput)
: base(testOutput)
private LSPTagHelperTooltipFactory _lspTagHelperTooltipFactory;
private VSLSPTagHelperTooltipFactory _vsLspTagHelperTooltipFactory;
private VSInternalCompletionSetting _completionCapability;
private VSInternalClientCapabilities _defaultClientCapability;
private VSInternalClientCapabilities _vsClientCapability;
private AggregateBoundAttributeDescription _attributeDescription;
private AggregateBoundElementDescription _elementDescription;

protected async override Task InitializeAsync()
{
var snapshotResolver = new TestSnapshotResolver();
await snapshotResolver.InitializeAsync(DisposalToken);

_lspTagHelperTooltipFactory = new DefaultLSPTagHelperTooltipFactory(snapshotResolver);
_vsLspTagHelperTooltipFactory = new DefaultVSLSPTagHelperTooltipFactory(snapshotResolver);
_completionCapability = new VSInternalCompletionSetting()
Expand Down
Loading