Don't register cohost types with the Razor project system (#9830)

Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1939874

After talking to Dustin this morning I decided to slightly
change tact with cohosting, and not worry about having it be able to
co-exist with the current language server. That means this RPS
regression is easy to fix just by disconnecting the cohost
OpenDocumentGenerator from that system. Yes, that means co-hosting is
now slightly worse, but if we move away from co-existence, then it
matters a lot less, as we no longer expect it to fully work, it just
needs to work enough to let us all get our work done. This PR doesn't
change that.

In reality what this change does is that if cohosting is on, and the old
server is off, then semantic tokens won't be correct for files that were
already open when you stared VS. You have to close and reopen the file.
No big deal IMO
This commit is contained in:
David Wengier 2024-01-19 07:42:29 +11:00 коммит произвёл GitHub
Родитель 6566bbb906 24b594e6f9
Коммит 6bab09ce40
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
1 изменённых файлов: 1 добавлений и 39 удалений

Просмотреть файл

@ -6,7 +6,6 @@ using System.Composition;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor;
using Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Logging;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
@ -21,7 +20,6 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor.Cohost;
[Shared]
[Export(typeof(OpenDocumentGenerator))]
[Export(typeof(IProjectSnapshotChangeTrigger))]
[method: ImportingConstructor]
internal sealed class OpenDocumentGenerator(
LanguageServerFeatureOptions languageServerFeatureOptions,
@ -29,7 +27,7 @@ internal sealed class OpenDocumentGenerator(
CSharpVirtualDocumentAddListener csharpVirtualDocumentAddListener,
ISnapshotResolver snapshotResolver,
JoinableTaskContext joinableTaskContext,
IRazorLoggerFactory loggerFactory) : IProjectSnapshotChangeTrigger
IRazorLoggerFactory loggerFactory)
{
private readonly LanguageServerFeatureOptions _languageServerFeatureOptions = languageServerFeatureOptions ?? throw new ArgumentNullException(nameof(languageServerFeatureOptions));
private readonly TrackingLSPDocumentManager _documentManager = documentManager as TrackingLSPDocumentManager ?? throw new ArgumentNullException(nameof(documentManager));
@ -38,19 +36,6 @@ internal sealed class OpenDocumentGenerator(
private readonly JoinableTaskFactory _joinableTaskFactory = joinableTaskContext.Factory;
private readonly ILogger _logger = loggerFactory.CreateLogger<OpenDocumentGenerator>();
private ProjectSnapshotManager? _projectManager;
public void Initialize(ProjectSnapshotManagerBase projectManager)
{
if (!_languageServerFeatureOptions.UseRazorCohostServer)
{
return;
}
_projectManager = projectManager;
_projectManager.Changed += ProjectManager_Changed;
}
public async Task DocumentOpenedOrChangedAsync(string textDocumentPath, int version, CancellationToken cancellationToken)
{
// We are purposefully trigger code generation here directly, rather than using the project manager events that the above call
@ -179,27 +164,4 @@ internal sealed class OpenDocumentGenerator(
_ = documentSnapshot.TryGetVirtualDocument<HtmlVirtualDocumentSnapshot>(out var htmlVirtualDocumentSnapshot);
return htmlVirtualDocumentSnapshot;
}
private void ProjectManager_Changed(object sender, ProjectChangeEventArgs e)
{
// We only respond to ProjectChanged events, as opens and changes are handled by LSP endpoints, which call into this class too
if (e.Kind == ProjectChangeKind.ProjectChanged)
{
var newProject = e.Newer.AssumeNotNull();
foreach (var documentFilePath in newProject.DocumentFilePaths)
{
if (_projectManager!.IsDocumentOpen(documentFilePath) &&
newProject.GetDocument(documentFilePath) is { } document &&
_documentManager.TryGetDocument(new Uri(document.FilePath), out var documentSnapshot))
{
// This is not ideal, but we need to re-use the existing snapshot version because our system uses the version
// of the text buffer, but a project change doesn't change the text buffer.
// See https://github.com/dotnet/razor/issues/9197 for more info and some issues this causes
// This should all be moot eventually in Cohosting eventually anyway (ie, this whole file should be deleted)
_ = UpdateGeneratedDocumentsAsync(document, documentSnapshot.Version, CancellationToken.None);
}
}
}
}
}