Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -59,19 +59,16 @@ public static void AddLifeCycleServices(this IServiceCollection services, RazorL
services.AddSingleton<IOnInitialized>(clientConnection);
}

public static void AddFormattingServices(this IServiceCollection services, LanguageServerFeatureOptions featureOptions)
public static void AddFormattingServices(this IServiceCollection services)
{
// Formatting
services.AddSingleton<IRazorFormattingService, RazorFormattingService>();

if (!featureOptions.UseRazorCohostServer)
{
services.AddSingleton<IHtmlFormatter, HtmlFormatter>();
services.AddSingleton<IHtmlFormatter, HtmlFormatter>();

services.AddHandlerWithCapabilities<DocumentFormattingEndpoint>();
services.AddHandlerWithCapabilities<DocumentOnTypeFormattingEndpoint>();
services.AddHandlerWithCapabilities<DocumentRangeFormattingEndpoint>();
}
services.AddHandlerWithCapabilities<DocumentFormattingEndpoint>();
services.AddHandlerWithCapabilities<DocumentOnTypeFormattingEndpoint>();
services.AddHandlerWithCapabilities<DocumentRangeFormattingEndpoint>();
}

public static void AddCompletionServices(this IServiceCollection services)
Expand Down Expand Up @@ -113,17 +110,14 @@ public static void AddHoverServices(this IServiceCollection services)
services.AddHandlerWithCapabilities<HoverEndpoint>();
}

public static void AddSemanticTokensServices(this IServiceCollection services, LanguageServerFeatureOptions featureOptions)
public static void AddSemanticTokensServices(this IServiceCollection services)
{
if (!featureOptions.UseRazorCohostServer)
{
services.AddHandlerWithCapabilities<SemanticTokensRangeEndpoint>();
// Ensure that we don't add the default service if something else has added one.
services.TryAddSingleton<IRazorSemanticTokensInfoService, RazorSemanticTokensInfoService>();
services.AddSingleton<ICSharpSemanticTokensProvider, LSPCSharpSemanticTokensProvider>();
services.AddHandlerWithCapabilities<SemanticTokensRangeEndpoint>();
// Ensure that we don't add the default service if something else has added one.
services.TryAddSingleton<IRazorSemanticTokensInfoService, RazorSemanticTokensInfoService>();
services.AddSingleton<ICSharpSemanticTokensProvider, LSPCSharpSemanticTokensProvider>();

services.AddSingleton<ISemanticTokensLegendService, RazorSemanticTokensLegendService>();
}
services.AddSingleton<ISemanticTokensLegendService, RazorSemanticTokensLegendService>();

services.AddHandler<RazorSemanticTokensRefreshEndpoint>();

Expand Down Expand Up @@ -168,18 +162,15 @@ public static void AddCodeActionsServices(this IServiceCollection services)
services.AddSingleton<IHtmlCodeActionResolver, HtmlCodeActionResolver>();
}

public static void AddTextDocumentServices(this IServiceCollection services, LanguageServerFeatureOptions featureOptions)
public static void AddTextDocumentServices(this IServiceCollection services)
{
if (!featureOptions.UseRazorCohostServer)
{
services.AddHandlerWithCapabilities<TextDocumentTextPresentationEndpoint>();
services.AddHandlerWithCapabilities<TextDocumentUriPresentationEndpoint>();

services.AddSingleton<ISpellCheckService, SpellCheckService>();
services.AddSingleton<ICSharpSpellCheckRangeProvider, LspCSharpSpellCheckRangeProvider>();
services.AddHandlerWithCapabilities<DocumentSpellCheckEndpoint>();
services.AddHandler<WorkspaceSpellCheckEndpoint>();
}
services.AddHandlerWithCapabilities<TextDocumentTextPresentationEndpoint>();
services.AddHandlerWithCapabilities<TextDocumentUriPresentationEndpoint>();

services.AddSingleton<ISpellCheckService, SpellCheckService>();
services.AddSingleton<ICSharpSpellCheckRangeProvider, LspCSharpSpellCheckRangeProvider>();
services.AddHandlerWithCapabilities<DocumentSpellCheckEndpoint>();
services.AddHandler<WorkspaceSpellCheckEndpoint>();

services.AddHandlerWithCapabilities<DocumentDidChangeEndpoint>();
services.AddHandler<DocumentDidCloseEndpoint>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,9 @@ public void DocumentProcessed(RazorCodeDocument codeDocument, DocumentSnapshot d
return;
}

// If cohosting is on, then it is responsible for updating the Html buffer
if (!_languageServerFeatureOptions.UseRazorCohostServer)
{
var htmlText = codeDocument.GetHtmlSourceText();
var htmlText = codeDocument.GetHtmlSourceText();

_publisher.PublishHtml(document.Project.Key, filePath, htmlText, hostDocumentVersion);
}
_publisher.PublishHtml(document.Project.Key, filePath, htmlText, hostDocumentVersion);

var csharpText = codeDocument.GetCSharpSourceText();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void Dispose()
_jsonRpc.Dispose();
}

private static ILspLogger CreateILspLogger(ILoggerFactory loggerFactory, ITelemetryReporter telemetryReporter)
private static ClaspLoggingBridge CreateILspLogger(ILoggerFactory loggerFactory, ITelemetryReporter telemetryReporter)
{
return new ClaspLoggingBridge(loggerFactory, telemetryReporter);
}
Expand Down Expand Up @@ -127,40 +127,37 @@ protected override ILspServices ConstructLspServices()

services.AddLifeCycleServices(this, _clientConnection, _lspServerActivationTracker);

services.AddSemanticTokensServices(featureOptions);
services.AddSemanticTokensServices();
services.AddDocumentManagementServices();
services.AddFormattingServices(featureOptions);
services.AddFormattingServices();
services.AddOptionsServices(_lspOptions);
services.AddTextDocumentServices(featureOptions);
services.AddTextDocumentServices();

if (!featureOptions.UseRazorCohostServer)
{
// Diagnostics
services.AddDiagnosticServices();
// Diagnostics
services.AddDiagnosticServices();

services.AddCodeActionsServices();
services.AddCodeActionsServices();

// Completion
services.AddCompletionServices();
// Completion
services.AddCompletionServices();

// Auto insert
services.AddSingleton<IOnAutoInsertProvider, CloseTextTagOnAutoInsertProvider>();
services.AddSingleton<IOnAutoInsertProvider, AutoClosingTagOnAutoInsertProvider>();
// Auto insert
services.AddSingleton<IOnAutoInsertProvider, CloseTextTagOnAutoInsertProvider>();
services.AddSingleton<IOnAutoInsertProvider, AutoClosingTagOnAutoInsertProvider>();

services.AddSingleton<IAutoInsertService, AutoInsertService>();
services.AddSingleton<IAutoInsertService, AutoInsertService>();

// Folding Range Providers
services.AddSingleton<IRazorFoldingRangeProvider, RazorCodeBlockFoldingProvider>();
services.AddSingleton<IRazorFoldingRangeProvider, RazorCSharpStatementFoldingProvider>();
services.AddSingleton<IRazorFoldingRangeProvider, RazorCSharpStatementKeywordFoldingProvider>();
services.AddSingleton<IRazorFoldingRangeProvider, SectionDirectiveFoldingProvider>();
services.AddSingleton<IRazorFoldingRangeProvider, UsingsFoldingRangeProvider>();
// Folding Range Providers
services.AddSingleton<IRazorFoldingRangeProvider, RazorCodeBlockFoldingProvider>();
services.AddSingleton<IRazorFoldingRangeProvider, RazorCSharpStatementFoldingProvider>();
services.AddSingleton<IRazorFoldingRangeProvider, RazorCSharpStatementKeywordFoldingProvider>();
services.AddSingleton<IRazorFoldingRangeProvider, SectionDirectiveFoldingProvider>();
services.AddSingleton<IRazorFoldingRangeProvider, UsingsFoldingRangeProvider>();

services.AddSingleton<IFoldingRangeService, FoldingRangeService>();
services.AddSingleton<IFoldingRangeService, FoldingRangeService>();

// Hover
services.AddHoverServices();
}
// Hover
services.AddHoverServices();

// Other
services.AddSingleton<IRazorComponentSearchEngine, RazorComponentSearchEngine>();
Expand All @@ -171,54 +168,51 @@ protected override ILspServices ConstructLspServices()
// Defaults: For when the caller hasn't provided them through the `configure` action.
services.TryAddSingleton<IHostServicesProvider, DefaultHostServicesProvider>();

AddHandlers(services, featureOptions);
AddHandlers(services);

var lspServices = new LspServices(services);

return lspServices;

static void AddHandlers(IServiceCollection services, LanguageServerFeatureOptions featureOptions)
static void AddHandlers(IServiceCollection services)
{
// Not calling AddHandler because we want to register this endpoint as an IOnInitialized too
services.AddSingleton<RazorConfigurationEndpoint>();
services.AddSingleton<IMethodHandler, RazorConfigurationEndpoint>(s => s.GetRequiredService<RazorConfigurationEndpoint>());
// Transient because it should only be used once and I'm hoping it doesn't stick around.
services.AddTransient<IOnInitialized>(sp => sp.GetRequiredService<RazorConfigurationEndpoint>());

if (!featureOptions.UseRazorCohostServer)
{
services.AddHandlerWithCapabilities<ImplementationEndpoint>();
services.AddHandlerWithCapabilities<ImplementationEndpoint>();

services.AddSingleton<IRazorComponentDefinitionService, RazorComponentDefinitionService>();
services.AddHandlerWithCapabilities<DefinitionEndpoint>();
services.AddSingleton<IRazorComponentDefinitionService, RazorComponentDefinitionService>();
services.AddHandlerWithCapabilities<DefinitionEndpoint>();

services.AddSingleton<IRenameService, RenameService>();
services.AddHandlerWithCapabilities<RenameEndpoint>();
services.AddSingleton<IRenameService, RenameService>();
services.AddHandlerWithCapabilities<RenameEndpoint>();

services.AddHandlerWithCapabilities<OnAutoInsertEndpoint>();
services.AddHandlerWithCapabilities<DocumentHighlightEndpoint>();
services.AddHandlerWithCapabilities<SignatureHelpEndpoint>();
services.AddHandlerWithCapabilities<LinkedEditingRangeEndpoint>();
services.AddHandlerWithCapabilities<FoldingRangeEndpoint>();
services.AddHandlerWithCapabilities<OnAutoInsertEndpoint>();
services.AddHandlerWithCapabilities<DocumentHighlightEndpoint>();
services.AddHandlerWithCapabilities<SignatureHelpEndpoint>();
services.AddHandlerWithCapabilities<LinkedEditingRangeEndpoint>();
services.AddHandlerWithCapabilities<FoldingRangeEndpoint>();

services.AddSingleton<IInlayHintService, InlayHintService>();
services.AddHandlerWithCapabilities<InlayHintEndpoint>();
services.AddHandler<InlayHintResolveEndpoint>();
services.AddSingleton<IInlayHintService, InlayHintService>();
services.AddHandlerWithCapabilities<InlayHintEndpoint>();
services.AddHandler<InlayHintResolveEndpoint>();

services.AddHandlerWithCapabilities<DocumentSymbolEndpoint>();
services.AddSingleton<IDocumentSymbolService, DocumentSymbolService>();
services.AddHandlerWithCapabilities<DocumentSymbolEndpoint>();
services.AddSingleton<IDocumentSymbolService, DocumentSymbolService>();

services.AddHandlerWithCapabilities<DocumentColorEndpoint>();
services.AddHandler<ColorPresentationEndpoint>();
services.AddHandlerWithCapabilities<DocumentColorEndpoint>();
services.AddHandler<ColorPresentationEndpoint>();

services.AddHandlerWithCapabilities<ProjectContextsEndpoint>();
services.AddHandlerWithCapabilities<ProjectContextsEndpoint>();

services.AddHandlerWithCapabilities<FindAllReferencesEndpoint>();
services.AddHandlerWithCapabilities<FindAllReferencesEndpoint>();

services.AddHandlerWithCapabilities<ValidateBreakpointRangeEndpoint>();
services.AddHandler<RazorBreakpointSpanEndpoint>();
services.AddHandler<RazorProximityExpressionsEndpoint>();
}
services.AddHandlerWithCapabilities<ValidateBreakpointRangeEndpoint>();
services.AddHandler<RazorBreakpointSpanEndpoint>();
services.AddHandler<RazorProximityExpressionsEndpoint>();

services.AddHandler<WrapWithTagEndpoint>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.ProjectSystem;
using Microsoft.AspNetCore.Razor.Telemetry;
using Microsoft.CodeAnalysis.ExternalAccess.Razor;
using Microsoft.CodeAnalysis.Razor.Logging;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.VisualStudio.LanguageServer.ContainedLanguage;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Microsoft.VisualStudio.Razor.LanguageClient.Cohost;
using Microsoft.VisualStudio.Razor.Settings;
using Microsoft.VisualStudio.Razor.Snippets;
using Microsoft.VisualStudio.Text;
Expand All @@ -35,8 +33,6 @@ internal partial class RazorCustomMessageTarget
private readonly LanguageServerFeatureOptions _languageServerFeatureOptions;
private readonly ProjectSnapshotManager _projectManager;
private readonly SnippetCompletionItemProvider _snippetCompletionItemProvider;
private readonly IWorkspaceProvider _workspaceProvider;
private readonly IHtmlDocumentSynchronizer _htmlDocumentSynchronizer;
private readonly FormattingOptionsProvider _formattingOptionsProvider;
private readonly IClientSettingsManager _editorSettingsManager;
private readonly LSPDocumentSynchronizer _documentSynchronizer;
Expand All @@ -56,25 +52,13 @@ public RazorCustomMessageTarget(
LanguageServerFeatureOptions languageServerFeatureOptions,
ProjectSnapshotManager projectManager,
SnippetCompletionItemProvider snippetCompletionItemProvider,
IWorkspaceProvider workspaceProvider,
IHtmlDocumentSynchronizer htmlDocumentSynchronizer,
ILoggerFactory loggerFactory)
{
if (documentManager is null)
{
throw new ArgumentNullException(nameof(documentManager));
}

if (documentManager is not TrackingLSPDocumentManager trackingDocumentManager)
{
throw new ArgumentException($"The LSP document manager should be of type {typeof(TrackingLSPDocumentManager).FullName}", nameof(documentManager));
}

if (joinableTaskContext is null)
{
throw new ArgumentNullException(nameof(joinableTaskContext));
}

_documentManager = trackingDocumentManager;
_joinableTaskFactory = joinableTaskContext.Factory;

Expand All @@ -87,8 +71,6 @@ public RazorCustomMessageTarget(
_languageServerFeatureOptions = languageServerFeatureOptions ?? throw new ArgumentNullException(nameof(languageServerFeatureOptions));
_projectManager = projectManager ?? throw new ArgumentNullException(nameof(projectManager));
_snippetCompletionItemProvider = snippetCompletionItemProvider ?? throw new ArgumentNullException(nameof(snippetCompletionItemProvider));
_workspaceProvider = workspaceProvider;
_htmlDocumentSynchronizer = htmlDocumentSynchronizer;
_logger = loggerFactory.GetOrCreateLogger<RazorCustomMessageTarget>();
}

Expand Down Expand Up @@ -133,19 +115,13 @@ public RazorCustomMessageTarget(
private record struct DelegationRequestDetails(string LanguageServerName, Uri ProjectedUri, ITextBuffer TextBuffer);

private async Task<SynchronizedResult<TVirtualDocumentSnapshot>> TrySynchronizeVirtualDocumentAsync<TVirtualDocumentSnapshot>(
int requiredHostDocumentVersion,
TextDocumentIdentifier hostDocument,
CancellationToken cancellationToken,
bool rejectOnNewerParallelRequest = true,
[CallerMemberName] string? caller = null)
where TVirtualDocumentSnapshot : VirtualDocumentSnapshot
int requiredHostDocumentVersion,
TextDocumentIdentifier hostDocument,
CancellationToken cancellationToken,
bool rejectOnNewerParallelRequest = true,
[CallerMemberName] string? caller = null)
where TVirtualDocumentSnapshot : VirtualDocumentSnapshot
{
if (_languageServerFeatureOptions.UseRazorCohostServer &&
typeof(TVirtualDocumentSnapshot) == typeof(HtmlVirtualDocumentSnapshot))
{
return await TempForCohost_TrySynchronizeVirtualDocumentAsync<TVirtualDocumentSnapshot>(hostDocument, cancellationToken);
}

_logger.LogDebug($"Trying to synchronize for {caller} to version {requiredHostDocumentVersion} of {hostDocument.Uri} for {hostDocument.GetProjectContext()?.Id ?? "(no project context)"}");

// For Html documents we don't do anything fancy, just call the standard service
Expand Down Expand Up @@ -205,47 +181,6 @@ private async Task<SynchronizedResult<TVirtualDocumentSnapshot>> TrySynchronizeV
return result;
}

private async Task<SynchronizedResult<TVirtualDocumentSnapshot>> TempForCohost_TrySynchronizeVirtualDocumentAsync<TVirtualDocumentSnapshot>(TextDocumentIdentifier hostDocument, CancellationToken cancellationToken)
where TVirtualDocumentSnapshot : VirtualDocumentSnapshot
{
Debug.Assert(typeof(TVirtualDocumentSnapshot) == typeof(HtmlVirtualDocumentSnapshot));
// Cohosting is responsible for Html, so we have to go through its service instead
var workspace = _workspaceProvider.GetWorkspace();
var documentIds = workspace.CurrentSolution.GetDocumentIdsWithFilePath(RazorUri.GetDocumentFilePathFromUri(hostDocument.Uri));

if (documentIds.Length != 1)
{
_logger.LogError($"Couldn't get document id from the workspace for {hostDocument.Uri}");
return new SynchronizedResult<TVirtualDocumentSnapshot>(false, null);
}

var document = workspace.CurrentSolution.GetAdditionalDocument(documentIds[0]);
if (document is null)
{
_logger.LogError($"Couldn't get document from the workspace for {documentIds[0]} which should be {hostDocument.Uri}");
return new SynchronizedResult<TVirtualDocumentSnapshot>(false, null);
}

if (!await _htmlDocumentSynchronizer.TrySynchronizeAsync(document, cancellationToken).ConfigureAwait(false))
{
return new SynchronizedResult<TVirtualDocumentSnapshot>(false, null);
}

if (!_documentManager.TryGetDocument(hostDocument.Uri, out var snapshot))
{
_logger.LogError($"Couldn't find document in LSPDocumentManager for {hostDocument.Uri}");
return new SynchronizedResult<TVirtualDocumentSnapshot>(false, null);
}

if (!snapshot.TryGetVirtualDocument<TVirtualDocumentSnapshot>(out var virtualDocument))
{
_logger.LogError($"Couldn't find virtual document snapshot for {hostDocument.Uri}");
return new SynchronizedResult<TVirtualDocumentSnapshot>(false, null);
}

return new SynchronizedResult<TVirtualDocumentSnapshot>(true, virtualDocument);
}

private SynchronizedResult<TVirtualDocumentSnapshot>? TryReturnPossiblyFutureSnapshot<TVirtualDocumentSnapshot>(
int requiredHostDocumentVersion, TextDocumentIdentifier hostDocument)
where TVirtualDocumentSnapshot : VirtualDocumentSnapshot
Expand Down
Loading