Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
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
Expand Up @@ -38,7 +38,6 @@
<Compile Include="$(MSBuildThisFileDirectory)Formatting\CohostOnTypeFormattingEndpoint.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Formatting\CohostRangeFormattingEndpoint.cs" />
<Compile Include="$(MSBuildThisFileDirectory)OnAutoInsert\CohostOnAutoInsertEndpoint.cs" />
<Compile Include="$(MSBuildThisFileDirectory)OnAutoInsert\CohostOnAutoInsertTriggerCharacterProviders.cs" />
<Compile Include="$(MSBuildThisFileDirectory)RazorAnalyzerAssemblyRedirector.cs" />
<Compile Include="$(MSBuildThisFileDirectory)RazorConfigurationChangedServiceFactory.cs" />
<Compile Include="$(MSBuildThisFileDirectory)RazorMiscellaneousProjectInfoService.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
using System.Collections.Immutable;
using System.Composition;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Razor.CohostingShared;
using Microsoft.CodeAnalysis.LanguageServer.Handler;
using Microsoft.CodeAnalysis.Razor.AutoInsert;
using Microsoft.CodeAnalysis.Razor.Cohost;
using Microsoft.CodeAnalysis.Razor.Formatting;
using Microsoft.CodeAnalysis.Razor.Logging;
Expand All @@ -33,9 +30,6 @@ internal sealed class CohostOnAutoInsertEndpoint(
IIncompatibleProjectService incompatibleProjectService,
IRemoteServiceInvoker remoteServiceInvoker,
IClientSettingsManager clientSettingsManager,
#pragma warning disable RS0030 // Do not use banned APIs
[ImportMany] IEnumerable<IOnAutoInsertTriggerCharacterProvider> onAutoInsertTriggerCharacterProviders,
#pragma warning restore RS0030 // Do not use banned APIs
IHtmlRequestInvoker requestInvoker,
ILoggerFactory loggerFactory)
: AbstractCohostDocumentEndpoint<VSInternalDocumentOnAutoInsertParams, VSInternalDocumentOnAutoInsertResponseItem?>(incompatibleProjectService), IDynamicRegistrationProvider
Expand All @@ -45,22 +39,18 @@ internal sealed class CohostOnAutoInsertEndpoint(
private readonly IHtmlRequestInvoker _requestInvoker = requestInvoker;
private readonly ILogger _logger = loggerFactory.GetOrCreateLogger<CohostOnAutoInsertEndpoint>();

private readonly string[] _triggerCharacters = CalculateTriggerChars(onAutoInsertTriggerCharacterProviders);
private static readonly string[] s_razorOnAutoInsertTriggerCharacters = [">"];
private static readonly string[] s_htmlAllowedAutoInsertTriggerCharacters = ["="];
private static readonly string[] s_csharpAllowedAutoInsertTriggerCharacters = ["'", "/", "\n", "\""];

private static string[] CalculateTriggerChars(IEnumerable<IOnAutoInsertTriggerCharacterProvider> onAutoInsertTriggerCharacterProviders)
{
var providerTriggerCharacters = onAutoInsertTriggerCharacterProviders.Select((provider) => provider.TriggerCharacter);

HashSet<string> triggerCharacters = [
.. providerTriggerCharacters,
private static readonly string[] s_triggerCharacters = [
.. s_razorOnAutoInsertTriggerCharacters,
#if !VSCODE
// VS Code's auto insert functionality is poly-filled by Roslyn. The Html server has no support for it.
.. AutoInsertService.HtmlAllowedAutoInsertTriggerCharacters,
// VS Code's auto insert functionality is poly-filled by Roslyn. The Html server has no support for it.
.. s_htmlAllowedAutoInsertTriggerCharacters,
#endif
.. AutoInsertService.CSharpAllowedAutoInsertTriggerCharacters ];

return [.. triggerCharacters];
}
.. s_csharpAllowedAutoInsertTriggerCharacters
];

protected override bool MutatesSolutionState => false;

Expand All @@ -75,7 +65,7 @@ public ImmutableArray<Registration> GetRegistrations(VSInternalClientCapabilitie
Method = VSInternalMethods.OnAutoInsertName,
RegisterOptions = new VSInternalDocumentOnAutoInsertRegistrationOptions()
{
TriggerCharacters = _triggerCharacters
TriggerCharacters = s_triggerCharacters
}
}];
}
Expand Down Expand Up @@ -165,5 +155,11 @@ internal readonly struct TestAccessor(CohostOnAutoInsertEndpoint instance)
TextDocument razorDocument,
CancellationToken cancellationToken)
=> instance.HandleRequestAsync(request, razorDocument, cancellationToken);

public static string[] GetRazorOnAutoInsertTriggerCharacters() => s_razorOnAutoInsertTriggerCharacters;

public static string[] GetHtmlAllowedAutoInsertTriggerCharacters() => s_htmlAllowedAutoInsertTriggerCharacters;

public static string[] GetCSharpAllowedAutoInsertTriggerCharacters() => s_csharpAllowedAutoInsertTriggerCharacters;
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Immutable;
using System.Composition;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using Microsoft.AspNetCore.Razor.Language;
Expand All @@ -11,9 +12,11 @@

using RazorSyntaxNode = Microsoft.AspNetCore.Razor.Language.Syntax.SyntaxNode;

namespace Microsoft.CodeAnalysis.Razor.AutoInsert;
namespace Microsoft.CodeAnalysis.Remote.Razor.AutoInsert;

internal class AutoClosingTagOnAutoInsertProvider : IOnAutoInsertProvider
[Shared]
[Export(typeof(IOnAutoInsertProvider))]
internal sealed class AutoClosingTagOnAutoInsertProvider : IOnAutoInsertProvider
{
// From http://dev.w3.org/html5/spec/Overview.html#elements-0
private static readonly ImmutableHashSet<string> s_voidElements = ImmutableHashSet.Create(StringComparer.OrdinalIgnoreCase,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Composition;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.Language.Legacy;
using Microsoft.AspNetCore.Razor.Language.Syntax;
using Microsoft.CodeAnalysis.Text;

namespace Microsoft.CodeAnalysis.Razor.AutoInsert;
namespace Microsoft.CodeAnalysis.Remote.Razor.AutoInsert;

internal class CloseTextTagOnAutoInsertProvider : IOnAutoInsertProvider
[Shared]
[Export(typeof(IOnAutoInsertProvider))]
internal sealed class CloseTextTagOnAutoInsertProvider : IOnAutoInsertProvider
{
public string TriggerCharacter => ">";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
using System.Diagnostics.CodeAnalysis;
using Microsoft.AspNetCore.Razor.Language;

namespace Microsoft.CodeAnalysis.Razor.AutoInsert;
namespace Microsoft.CodeAnalysis.Remote.Razor.AutoInsert;

internal interface IOnAutoInsertProvider : IOnAutoInsertTriggerCharacterProvider
internal interface IOnAutoInsertProvider
{
string TriggerCharacter { get; }

bool TryResolveInsertion(
Position position,
RazorCodeDocument codeDocument,
Expand Down

This file was deleted.

Loading
Loading