Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No more project.razor.bin files (in VS, at least) #10475

Merged
merged 45 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
3d0c7b2
Rename VisualStudioHostServicesProvider parameter and field to match …
DustinCampbell May 31, 2024
d7137c7
Remove unneeded null arg checks
DustinCampbell May 31, 2024
01ff3d2
Rename RazorLanguageServerHost.Create parameter
DustinCampbell May 31, 2024
e8e85eb
Add new RazorProjectInfoPublisher implementation
DustinCampbell May 31, 2024
02c1f55
Add MEF exported VS RazorProjectInfoManager
DustinCampbell May 31, 2024
397bdf6
Add RazorProjectInfoListener in language server and update project se…
DustinCampbell May 31, 2024
c447e69
Stop updating ProjectConfigurationFileStore
DustinCampbell May 31, 2024
6735145
Clean up LanguageServerTestBase a bit
DustinCampbell May 31, 2024
b38dc0f
Remove FallbackProjectManager ProjectConfigurationFileStore test
DustinCampbell May 31, 2024
b0ce980
Merge publisher with base class and add tests
DustinCampbell Jun 5, 2024
a84ec47
Rename to RazorProjectInfoDriver
DustinCampbell Jun 6, 2024
29a4800
Don't export `RazorProjectInfoDriver` as a MEF service
DustinCampbell Jun 6, 2024
b5158d7
Ensure that the `RazorLanguageServerHost` is disposed
DustinCampbell Jun 6, 2024
23997ca
Make `RazorProjectService` implement `IRazorProjectInfoListener`
DustinCampbell Jun 6, 2024
c9d68ae
Add extra logging and don't attempt to add misc-project a second time
DustinCampbell Jun 7, 2024
7211fd8
Remove old RazorProjectInfoPublisher
DustinCampbell Jun 7, 2024
f272897
Improve ProjectWorkspaceStateGenerator logging
DustinCampbell Jun 7, 2024
7d19960
Remove RazorProjectInfoEndpointPublisher
DustinCampbell Jun 11, 2024
caaa0d7
Remove ProjectConfigurationFilePathStore
DustinCampbell Jun 11, 2024
c437c02
Convert WorkspaceDirectoryPathResolver to interface and implement on …
DustinCampbell Jun 11, 2024
439aa7a
Implement FileWatcherBasedRazorProjectInfoDriver
DustinCampbell Jun 11, 2024
4ac135e
Remove MonitorProjectConfigurationFilePathEndpoint
DustinCampbell Jun 11, 2024
5f6036e
Remove ProjectInfoEndpoint
DustinCampbell Jun 11, 2024
a61c4e1
Remove ProjectConfigurationFileChangeDetector
DustinCampbell Jun 11, 2024
8bf0031
Log errors in FileWatcherBasedRazorProjectInfoDriver
DustinCampbell Jun 11, 2024
cb0923f
Remove ProjectConfigurationStateSynchronizer
DustinCampbell Jun 11, 2024
25bc05d
Remove unused IProjectFileChangeListener interface
DustinCampbell Jun 11, 2024
7699f26
Remove ProjectConfigurationFileChangeEventArgs
DustinCampbell Jun 11, 2024
9860d0e
Remove UseProjectConfigurationEndpoint option and feature flag
DustinCampbell Jun 11, 2024
b448b99
Remove MonitorWorkspaceFolderForConfigurationFiles option
DustinCampbell Jun 11, 2024
06644b9
Remove RazorProjectInfoDeserializer
DustinCampbell Jun 11, 2024
72ed38a
Don't add extra IWorkspaceRootPathProvider to the service collection
DustinCampbell Jun 11, 2024
34969de
Make a couple of tweaks to FileWatcherBasedRazorProjectInfoDriver
DustinCampbell Jun 11, 2024
6f50764
Ensure that RazorProjectInfoService waits for driver to initializer
DustinCampbell Jun 11, 2024
d6eb60c
Make IWorkspaceRootPathProvider.GetRootPath(...) async
DustinCampbell Jun 11, 2024
0d449f3
Don't open file for reading twice
DustinCampbell Jun 12, 2024
22e2511
Trim "Microsoft.CodeAnalysis.Razor." from ILogger category name
DustinCampbell Jun 12, 2024
cb203a1
RazorProjectService shouldn't implement IOnInitialized
DustinCampbell Jun 12, 2024
76ab7e4
Remove RazorProjectInfoFileSerializer
DustinCampbell Jun 12, 2024
6cfeab0
Don't dispose services twice
DustinCampbell Jun 12, 2024
547ad38
Fix ValidateMultipleJsonFiles integration test
DustinCampbell Jun 12, 2024
b880899
Remove OpenExistingProject_WithReopenedFile_NoProjectRazorJson integr…
DustinCampbell Jun 13, 2024
af6e0d8
Remove version of OpenExistingProject_WithReopenedFile integration te…
DustinCampbell Jun 13, 2024
8e085c4
Fix initialization contract for RazorProjectInfo drivers
DustinCampbell Jun 13, 2024
c58e948
Don't spin in GetRootPathAsync waiting for initialize
DustinCampbell Jun 13, 2024
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 @@ -35,7 +35,7 @@ public RazorLanguageServerBenchmarkBase()
serverStream,
razorLoggerFactory,
NoOpTelemetryReporter.Instance,
configure: (collection) =>
configureServices: (collection) =>
{
collection.AddSingleton<IOnInitialized, NoopClientNotifierService>();
collection.AddSingleton<IClientConnection, NoopClientNotifierService>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,26 @@
// Licensed under the MIT license. See License.txt in the project root for license information.

using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.Threading;
using Microsoft.CodeAnalysis.Razor;
using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.CommonLanguageServerProtocol.Framework;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Microsoft.VisualStudio.RpcContracts.Settings;
using Microsoft.VisualStudio.Threading;

namespace Microsoft.AspNetCore.Razor.LanguageServer;

internal class CapabilitiesManager : IInitializeManager<InitializeParams, InitializeResult>, IClientCapabilitiesService
internal sealed class CapabilitiesManager : IInitializeManager<InitializeParams, InitializeResult>, IClientCapabilitiesService, IWorkspaceRootPathProvider
{
private InitializeParams? _initializeParams;
private readonly ILspServices _lspServices;
private readonly TaskCompletionSource<InitializeParams> _initializeParamsTaskSource;
private readonly AsyncLazy<string> _lazyRootPath;

public bool HasInitialized => _initializeParams is not null;
public bool HasInitialized => _initializeParamsTaskSource.Task.IsCompleted;

public bool CanGetClientCapabilities => HasInitialized;

Expand All @@ -23,16 +30,17 @@ internal class CapabilitiesManager : IInitializeManager<InitializeParams, Initia
public CapabilitiesManager(ILspServices lspServices)
{
_lspServices = lspServices;

_initializeParamsTaskSource = new();

#pragma warning disable VSTHRD012 // Provide JoinableTaskFactory where allowed
_lazyRootPath = new(ComputeRootPathAsync);
#pragma warning restore VSTHRD012
}

public InitializeParams GetInitializeParams()
{
if (_initializeParams is null)
{
throw new InvalidOperationException($"{nameof(GetInitializeParams)} was called before '{Methods.InitializeName}'");
}

return _initializeParams;
return _initializeParamsTaskSource.Task.VerifyCompleted();
}

public InitializeResult GetInitializeResult()
Expand All @@ -49,16 +57,40 @@ public InitializeResult GetInitializeResult()
provider.ApplyCapabilities(serverCapabilities, vsClientCapabilities);
}

var initializeResult = new InitializeResult
return new InitializeResult
{
Capabilities = serverCapabilities,
};

return initializeResult;
}

public void SetInitializeParams(InitializeParams request)
{
_initializeParams = request;
if (_initializeParamsTaskSource.Task.IsCompleted)
{
throw new InvalidOperationException($"{nameof(SetInitializeParams)} already called.");
}

_initializeParamsTaskSource.TrySetResult(request);
}

private async Task<string> ComputeRootPathAsync()
{
#pragma warning disable VSTHRD003 // Avoid awaiting foreign Tasks
var initializeParams = await _initializeParamsTaskSource.Task.ConfigureAwaitRunInline();
#pragma warning restore VSTHRD003 // Avoid awaiting foreign Tasks

if (initializeParams.RootUri is Uri rootUri)
{
return rootUri.GetAbsoluteOrUNCPath();
}

// RootUri was added in LSP3, fall back to RootPath

#pragma warning disable CS0618 // Type or member is obsolete
return initializeParams.RootPath.AssumeNotNull();
#pragma warning restore CS0618 // Type or member is obsolete
}

public Task<string> GetRootPathAsync(CancellationToken cancellationToken)
=> _lazyRootPath.GetValueAsync(cancellationToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,9 @@ public override bool ReturnCodeActionAndRenamePathsWithPrefixedSlash

public override bool UsePreciseSemanticTokenRanges => false;

public override bool MonitorWorkspaceFolderForConfigurationFiles => true;

public override bool UseRazorCohostServer => false;

public override bool DisableRazorLanguageServer => false;

public override bool ForceRuntimeCodeGeneration => false;

public override bool UseProjectConfigurationEndpoint => false;
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ protected RazorDiagnosticsPublisher(

public void Dispose()
{
if (_disposeTokenSource.IsCancellationRequested)
{
return;
}

_disposeTokenSource.Cancel();
_disposeTokenSource.Dispose();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.CodeAnalysis.Razor.SemanticTokens;
using Microsoft.CodeAnalysis.Razor.Serialization;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.CommonLanguageServerProtocol.Framework;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -48,6 +47,7 @@ public static void AddLifeCycleServices(this IServiceCollection services, RazorL
services.AddSingleton<CapabilitiesManager>();
services.AddSingleton<IInitializeManager<InitializeParams, InitializeResult>, CapabilitiesManager>(sp => sp.GetRequiredService<CapabilitiesManager>());
services.AddSingleton<IClientCapabilitiesService>(sp => sp.GetRequiredService<CapabilitiesManager>());
services.AddSingleton<IWorkspaceRootPathProvider>(sp => sp.GetRequiredService<CapabilitiesManager>());
services.AddSingleton<AbstractRequestContextFactory<RazorRequestContext>, RazorRequestContextFactory>();

services.AddSingleton<ICapabilitiesProvider, RazorLanguageServerCapability>();
Expand Down Expand Up @@ -211,31 +211,13 @@ public static void AddDocumentManagementServices(this IServiceCollection service

services.AddSingleton<RemoteTextLoaderFactory, DefaultRemoteTextLoaderFactory>();
services.AddSingleton<IRazorProjectService, RazorProjectService>();
services.AddSingleton<IRazorStartupService>((services) => (RazorProjectService)services.GetRequiredService<IRazorProjectService>());
services.AddSingleton<IRazorStartupService, OpenDocumentGenerator>();
services.AddSingleton<IRazorDocumentMappingService, RazorDocumentMappingService>();
services.AddSingleton<RazorFileChangeDetectorManager>();
services.AddSingleton<IOnInitialized>(sp => sp.GetRequiredService<RazorFileChangeDetectorManager>());

if (featureOptions.UseProjectConfigurationEndpoint)
{
services.AddSingleton<IRazorProjectInfoFileSerializer, RazorProjectInfoFileSerializer>();
services.AddSingleton<ProjectConfigurationStateManager>();
}
else
{
services.AddSingleton<IProjectConfigurationFileChangeListener, ProjectConfigurationStateSynchronizer>();
}

services.AddSingleton<IRazorFileChangeListener, RazorFileSynchronizer>();

// If we're not monitoring the whole workspace folder for configuration changes, then we don't actually need the the file change
// detector wired up via DI, as the razor/monitorProjectConfigurationFilePath endpoint will directly construct one. This means
// it can be a little simpler, and doesn't need to worry about which folders it's told to listen to.
if (featureOptions.MonitorWorkspaceFolderForConfigurationFiles)
{
services.AddSingleton<IFileChangeDetector, ProjectConfigurationFileChangeDetector>();
}

services.AddSingleton<IFileChangeDetector, RazorFileChangeDetector>();

// Document processed listeners
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ internal class ConfigurableLanguageServerFeatureOptions : LanguageServerFeatureO
private readonly bool? _usePreciseSemanticTokenRanges;
private readonly bool? _updateBuffersForClosedDocuments;
private readonly bool? _includeProjectKeyInGeneratedFilePath;
private readonly bool? _monitorWorkspaceFolderForConfigurationFiles;
private readonly bool? _useRazorCohostServer;
private readonly bool? _disableRazorLanguageServer;
private readonly bool? _forceRuntimeCodeGeneration;
private readonly bool? _useProjectConfigurationEndpoint;

public override bool SupportsFileManipulation => _supportsFileManipulation ?? _defaults.SupportsFileManipulation;
public override string ProjectConfigurationFileName => _projectConfigurationFileName ?? _defaults.ProjectConfigurationFileName;
Expand All @@ -40,11 +38,9 @@ internal class ConfigurableLanguageServerFeatureOptions : LanguageServerFeatureO
public override bool UsePreciseSemanticTokenRanges => _usePreciseSemanticTokenRanges ?? _defaults.UsePreciseSemanticTokenRanges;
public override bool UpdateBuffersForClosedDocuments => _updateBuffersForClosedDocuments ?? _defaults.UpdateBuffersForClosedDocuments;
public override bool IncludeProjectKeyInGeneratedFilePath => _includeProjectKeyInGeneratedFilePath ?? _defaults.IncludeProjectKeyInGeneratedFilePath;
public override bool MonitorWorkspaceFolderForConfigurationFiles => _monitorWorkspaceFolderForConfigurationFiles ?? _defaults.MonitorWorkspaceFolderForConfigurationFiles;
public override bool UseRazorCohostServer => _useRazorCohostServer ?? _defaults.UseRazorCohostServer;
public override bool DisableRazorLanguageServer => _disableRazorLanguageServer ?? _defaults.DisableRazorLanguageServer;
public override bool ForceRuntimeCodeGeneration => _forceRuntimeCodeGeneration ?? _defaults.ForceRuntimeCodeGeneration;
public override bool UseProjectConfigurationEndpoint => _useProjectConfigurationEndpoint ?? _defaults.UseProjectConfigurationEndpoint;

public ConfigurableLanguageServerFeatureOptions(string[] args)
{
Expand All @@ -67,11 +63,9 @@ public ConfigurableLanguageServerFeatureOptions(string[] args)
TryProcessBoolOption(nameof(UsePreciseSemanticTokenRanges), ref _usePreciseSemanticTokenRanges, option, args, i);
TryProcessBoolOption(nameof(UpdateBuffersForClosedDocuments), ref _updateBuffersForClosedDocuments, option, args, i);
TryProcessBoolOption(nameof(IncludeProjectKeyInGeneratedFilePath), ref _includeProjectKeyInGeneratedFilePath, option, args, i);
TryProcessBoolOption(nameof(MonitorWorkspaceFolderForConfigurationFiles), ref _monitorWorkspaceFolderForConfigurationFiles, option, args, i);
TryProcessBoolOption(nameof(UseRazorCohostServer), ref _useRazorCohostServer, option, args, i);
TryProcessBoolOption(nameof(DisableRazorLanguageServer), ref _disableRazorLanguageServer, option, args, i);
TryProcessBoolOption(nameof(ForceRuntimeCodeGeneration), ref _forceRuntimeCodeGeneration, option, args, i);
TryProcessBoolOption(nameof(UseProjectConfigurationEndpoint), ref _useProjectConfigurationEndpoint, option, args, i);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.Telemetry;
using Microsoft.CodeAnalysis.Razor.Logging;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualStudio.LanguageServer.Protocol;
Expand Down Expand Up @@ -42,10 +43,11 @@ public static RazorLanguageServerHost Create(
Stream output,
ILoggerFactory loggerFactory,
ITelemetryReporter telemetryReporter,
Action<IServiceCollection>? configure = null,
Action<IServiceCollection>? configureServices = null,
LanguageServerFeatureOptions? featureOptions = null,
RazorLSPOptions? razorLSPOptions = null,
ILspServerActivationTracker? lspServerActivationTracker = null,
IRazorProjectInfoDriver? projectInfoDriver = null,
TraceSource? traceSource = null)
{
var (jsonRpc, jsonSerializer) = CreateJsonRpc(input, output);
Expand All @@ -61,9 +63,10 @@ public static RazorLanguageServerHost Create(
jsonSerializer,
loggerFactory,
featureOptions,
configure,
configureServices,
razorLSPOptions,
lspServerActivationTracker,
projectInfoDriver,
telemetryReporter);

var host = new RazorLanguageServerHost(server);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// 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;

namespace Microsoft.AspNetCore.Razor.LanguageServer;

internal interface IProjectConfigurationFileChangeListener
internal interface IWorkspaceRootPathProvider
{
void ProjectConfigurationFileChanged(ProjectConfigurationFileChangeEventArgs args);
Task<string> GetRootPathAsync(CancellationToken cancellationToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public OpenDocumentGenerator(

public void Dispose()
{
if (_disposeTokenSource.IsCancellationRequested)
{
return;
}

_disposeTokenSource.Cancel();
_disposeTokenSource.Dispose();
}
Expand Down
Loading