diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ExternalAccess.OmniSharp/Project/OmniSharpProjectKey.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ExternalAccess.OmniSharp/Project/OmniSharpProjectKey.cs index ca07a32be69..4bb8ee82175 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ExternalAccess.OmniSharp/Project/OmniSharpProjectKey.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ExternalAccess.OmniSharp/Project/OmniSharpProjectKey.cs @@ -10,7 +10,7 @@ public sealed class OmniSharpProjectKey public static OmniSharpProjectKey? From(CodeAnalysis.Project workspaceProject) { var key = ProjectKey.From(workspaceProject); - return key is null ? null : new(key); + return key is null ? null : new(key.Value); } internal ProjectKey Key { get; } diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultDocumentVersionCache.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultDocumentVersionCache.cs index fa20bfd3ff2..6c41ed47020 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultDocumentVersionCache.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultDocumentVersionCache.cs @@ -151,11 +151,6 @@ private void ProjectSnapshotManager_Changed(object? sender, ProjectChangeEventAr // Any event that has a project may have changed the state of the documents // and therefore requires us to mark all existing documents as latest. - if (args.ProjectKey is null) - { - return; - } - var project = ProjectSnapshotManager.GetLoadedProject(args.ProjectKey); if (project is null) { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationStateSynchronizer.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationStateSynchronizer.cs index 9cbd5b3c9cc..006f26ab7c0 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationStateSynchronizer.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationStateSynchronizer.cs @@ -133,11 +133,6 @@ void AddProject(string configurationFilePath, ProjectRazorJson projectRazorJson) void UpdateProject(ProjectKey projectKey, ProjectRazorJson? projectRazorJson) { - if (projectKey is null) - { - throw new ArgumentNullException(nameof(projectKey)); - } - if (projectRazorJson is null) { ResetProject(projectKey); diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/DefaultProjectSnapshotManager.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/DefaultProjectSnapshotManager.cs index 8545ac109fc..aa28da9c40e 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/DefaultProjectSnapshotManager.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/DefaultProjectSnapshotManager.cs @@ -88,11 +88,6 @@ internal override ImmutableArray GetOpenDocuments() public override IProjectSnapshot? GetLoadedProject(ProjectKey projectKey) { - if (projectKey is null) - { - throw new ArgumentNullException(nameof(projectKey)); - } - using var _ = _rwLocker.EnterReadLock(); if (_projects_needsLock.TryGetValue(projectKey, out var entry)) { @@ -136,11 +131,6 @@ public override bool IsDocumentOpen(string documentFilePath) internal override void DocumentAdded(ProjectKey projectKey, HostDocument document, TextLoader textLoader) { - if (projectKey is null) - { - throw new ArgumentNullException(nameof(projectKey)); - } - if (document is null) { throw new ArgumentNullException(nameof(document)); @@ -159,11 +149,6 @@ internal override void DocumentAdded(ProjectKey projectKey, HostDocument documen internal override void DocumentRemoved(ProjectKey projectKey, HostDocument document) { - if (projectKey is null) - { - throw new ArgumentNullException(nameof(projectKey)); - } - if (document is null) { throw new ArgumentNullException(nameof(document)); @@ -182,11 +167,6 @@ internal override void DocumentRemoved(ProjectKey projectKey, HostDocument docum internal override void DocumentOpened(ProjectKey projectKey, string documentFilePath, SourceText sourceText) { - if (projectKey is null) - { - throw new ArgumentNullException(nameof(projectKey)); - } - if (documentFilePath is null) { throw new ArgumentNullException(nameof(documentFilePath)); @@ -210,11 +190,6 @@ internal override void DocumentOpened(ProjectKey projectKey, string documentFile internal override void DocumentClosed(ProjectKey projectKey, string documentFilePath, TextLoader textLoader) { - if (projectKey is null) - { - throw new ArgumentNullException(nameof(projectKey)); - } - if (documentFilePath is null) { throw new ArgumentNullException(nameof(documentFilePath)); @@ -238,11 +213,6 @@ internal override void DocumentClosed(ProjectKey projectKey, string documentFile internal override void DocumentChanged(ProjectKey projectKey, string documentFilePath, SourceText sourceText) { - if (projectKey is null) - { - throw new ArgumentNullException(nameof(projectKey)); - } - if (documentFilePath is null) { throw new ArgumentNullException(nameof(documentFilePath)); @@ -266,11 +236,6 @@ internal override void DocumentChanged(ProjectKey projectKey, string documentFil internal override void DocumentChanged(ProjectKey projectKey, string documentFilePath, TextLoader textLoader) { - if (projectKey is null) - { - throw new ArgumentNullException(nameof(projectKey)); - } - if (documentFilePath is null) { throw new ArgumentNullException(nameof(documentFilePath)); @@ -359,11 +324,6 @@ internal override void ProjectConfigurationChanged(HostProject hostProject) internal override void ProjectWorkspaceStateChanged(ProjectKey projectKey, ProjectWorkspaceState? projectWorkspaceState) { - if (projectKey is null) - { - throw new ArgumentNullException(nameof(projectKey)); - } - if (projectWorkspaceState is null) { throw new ArgumentNullException(nameof(projectWorkspaceState)); @@ -382,11 +342,6 @@ internal override void ProjectWorkspaceStateChanged(ProjectKey projectKey, Proje internal override void ProjectRemoved(ProjectKey projectKey) { - if (projectKey is null) - { - throw new ArgumentNullException(nameof(projectKey)); - } - if (TryChangeEntry_UsesLock( projectKey, documentFilePath: null, @@ -451,7 +406,7 @@ internal override void ReportError(Exception exception, ProjectKey projectKey) throw new ArgumentNullException(nameof(exception)); } - var snapshot = projectKey is null ? null : GetLoadedProject(projectKey); + var snapshot = GetLoadedProject(projectKey); ErrorReporter.ReportError(exception, snapshot); } diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectChangeEventArgs.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectChangeEventArgs.cs index 8af0d909f2f..02545fd82c7 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectChangeEventArgs.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectChangeEventArgs.cs @@ -24,17 +24,17 @@ public ProjectChangeEventArgs(IProjectSnapshot? older, IProjectSnapshot? newer, DocumentFilePath = documentFilePath; Kind = kind; SolutionIsClosing = solutionIsClosing; - ProjectFilePath = older?.FilePath ?? newer?.FilePath; - ProjectKey = older?.Key ?? newer?.Key; + ProjectFilePath = (older ?? newer)!.FilePath; + ProjectKey = (older ?? newer)!.Key; } public IProjectSnapshot? Older { get; } public IProjectSnapshot? Newer { get; } - public ProjectKey? ProjectKey { get; } + public ProjectKey ProjectKey { get; } - public string? ProjectFilePath { get; } + public string ProjectFilePath { get; } public string? DocumentFilePath { get; } diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectConfigurationFilePathChangedEventArgs.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectConfigurationFilePathChangedEventArgs.cs index ec57b6c5793..1f70213003f 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectConfigurationFilePathChangedEventArgs.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectConfigurationFilePathChangedEventArgs.cs @@ -9,11 +9,6 @@ internal class ProjectConfigurationFilePathChangedEventArgs : EventArgs { public ProjectConfigurationFilePathChangedEventArgs(ProjectKey projectKey, string? configurationFilePath) { - if (projectKey is null) - { - throw new ArgumentNullException(nameof(projectKey)); - } - ProjectKey = projectKey; ConfigurationFilePath = configurationFilePath; } diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectKey.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectKey.cs index a04261c52ca..9565c71e337 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectKey.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectKey.cs @@ -13,7 +13,8 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem; /// A very light wrapper around a file path, used to ensure consistency across the code base for what constitutes the unique /// identifier for a project. /// -internal sealed class ProjectKey : IEquatable +[DebuggerDisplay("id: {Id}")] +internal readonly record struct ProjectKey : IEquatable { // ProjectKey represents the path of the intermediate output path, which is where the project.razor.json file will // end up. All creation logic is here in one place to ensure this is consistent. @@ -37,31 +38,11 @@ private ProjectKey(string id) public override int GetHashCode() { - return FilePathComparer.Instance.GetHashCode(Id); + return Id is null ? 0 : FilePathComparer.Instance.GetHashCode(Id); } - public override bool Equals(object? other) + public bool Equals(ProjectKey other) { - return Equals(other as ProjectKey); - } - - public bool Equals(ProjectKey? other) - { - return FilePathComparer.Instance.Equals(Id, other?.Id); - } - - public static bool operator ==(ProjectKey? lhs, ProjectKey? rhs) - { - return lhs?.Equals(rhs) ?? false; - } - - public static bool operator !=(ProjectKey? lhs, ProjectKey? rhs) - { - return !lhs?.Equals(rhs) ?? false; - } - - public override string ToString() - { - return "{id:" + Id + "}"; + return FilePathComparer.Instance.Equals(Id, other.Id); } } diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/WorkspaceProjectStateChangeDetector.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/WorkspaceProjectStateChangeDetector.cs index b85453641e5..b4f6edd02cb 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/WorkspaceProjectStateChangeDetector.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/WorkspaceProjectStateChangeDetector.cs @@ -468,9 +468,8 @@ private bool TryGetProjectSnapshot(Project? project, [NotNullWhen(true)] out IPr return false; } - var projectKey = ProjectKey.From(project); // ProjectKey could be null, if Roslyn doesn't know the IntermediateOutputPath for the project - if (projectKey is null) + if (ProjectKey.From(project) is not { } projectKey) { projectSnapshot = null; return false; diff --git a/src/Razor/src/Microsoft.VisualStudio.Editor.Razor/DefaultVisualStudioDocumentTracker.cs b/src/Razor/src/Microsoft.VisualStudio.Editor.Razor/DefaultVisualStudioDocumentTracker.cs index ccd4fed4bdd..865107a4f54 100644 --- a/src/Razor/src/Microsoft.VisualStudio.Editor.Razor/DefaultVisualStudioDocumentTracker.cs +++ b/src/Razor/src/Microsoft.VisualStudio.Editor.Razor/DefaultVisualStudioDocumentTracker.cs @@ -196,7 +196,7 @@ public void Subscribe() var projectKey = _projectManager.GetAllProjectKeys(projectPath).FirstOrDefault(); - if (projectKey is null || _projectManager.GetLoadedProject(projectKey) is not { } project) + if (_projectManager.GetLoadedProject(projectKey) is not { } project) { return new EphemeralProjectSnapshot(Workspace.Services, projectPath); } diff --git a/src/Razor/src/Microsoft.VisualStudio.Editor.Razor/Documents/EditorDocumentManagerListener.cs b/src/Razor/src/Microsoft.VisualStudio.Editor.Razor/Documents/EditorDocumentManagerListener.cs index 6cc2c0eb1df..b6ae353913b 100644 --- a/src/Razor/src/Microsoft.VisualStudio.Editor.Razor/Documents/EditorDocumentManagerListener.cs +++ b/src/Razor/src/Microsoft.VisualStudio.Editor.Razor/Documents/EditorDocumentManagerListener.cs @@ -113,13 +113,13 @@ private async Task ProjectManager_ChangedAsync(ProjectChangeEventArgs e, Cancell return; } - var key = new DocumentKey(e.ProjectFilePath.AssumeNotNull(), e.DocumentFilePath.AssumeNotNull()); + var key = new DocumentKey(e.ProjectFilePath, e.DocumentFilePath.AssumeNotNull()); // GetOrCreateDocument needs to be run on the UI thread await _joinableTaskContext.Factory.SwitchToMainThreadAsync(cancellationToken); var document = DocumentManager.GetOrCreateDocument( - key, e.ProjectKey.AssumeNotNull(), _onChangedOnDisk, _onChangedInEditor, _onOpened, _onClosed); + key, e.ProjectKey, _onChangedOnDisk, _onChangedInEditor, _onOpened, _onClosed); if (document.IsOpenInEditor) { _onOpened(document, EventArgs.Empty); @@ -136,7 +136,7 @@ private async Task ProjectManager_ChangedAsync(ProjectChangeEventArgs e, Cancell await _joinableTaskContext.Factory.SwitchToMainThreadAsync(cancellationToken); if (DocumentManager.TryGetDocument( - new DocumentKey(e.ProjectFilePath.AssumeNotNull(), e.DocumentFilePath.AssumeNotNull()), out var document)) + new DocumentKey(e.ProjectFilePath, e.DocumentFilePath.AssumeNotNull()), out var document)) { // This class 'owns' the document entry so it's safe for us to dispose it. document.Dispose(); diff --git a/src/Razor/src/Microsoft.VisualStudio.Editor.Razor/Documents/RazorCodeDocumentProvidingSnapshotChangeTrigger.cs b/src/Razor/src/Microsoft.VisualStudio.Editor.Razor/Documents/RazorCodeDocumentProvidingSnapshotChangeTrigger.cs index 36c6ab64c71..08254699044 100644 --- a/src/Razor/src/Microsoft.VisualStudio.Editor.Razor/Documents/RazorCodeDocumentProvidingSnapshotChangeTrigger.cs +++ b/src/Razor/src/Microsoft.VisualStudio.Editor.Razor/Documents/RazorCodeDocumentProvidingSnapshotChangeTrigger.cs @@ -55,7 +55,7 @@ private void ProjectManager_Changed(object sender, ProjectChangeEventArgs e) else if (e.Kind == ProjectChangeKind.DocumentAdded) { var documentFilePath = e.DocumentFilePath!; - _documentProjectMap[documentFilePath] = e.ProjectKey!; + _documentProjectMap[documentFilePath] = e.ProjectKey; if (_openDocuments.Contains(documentFilePath)) { _openDocuments.Remove(documentFilePath); diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/DefaultProjectConfigurationFilePathStore.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/DefaultProjectConfigurationFilePathStore.cs index bc2850b184b..8e9b138b375 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/DefaultProjectConfigurationFilePathStore.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/DefaultProjectConfigurationFilePathStore.cs @@ -31,11 +31,6 @@ public DefaultProjectConfigurationFilePathStore() public override void Set(ProjectKey projectKey, string configurationFilePath) { - if (projectKey is null) - { - throw new ArgumentNullException(nameof(projectKey)); - } - if (configurationFilePath is null) { throw new ArgumentNullException(nameof(configurationFilePath)); @@ -62,11 +57,6 @@ public override void Set(ProjectKey projectKey, string configurationFilePath) public override void Remove(ProjectKey projectKey) { - if (projectKey is null) - { - throw new ArgumentNullException(nameof(projectKey)); - } - lock (_mappingsLock) { if (!_mappings.Remove(projectKey)) @@ -82,11 +72,6 @@ public override void Remove(ProjectKey projectKey) public override bool TryGet(ProjectKey projectKey, [NotNullWhen(returnValue: true)] out string? configurationFilePath) { - if (projectKey is null) - { - throw new ArgumentNullException(nameof(projectKey)); - } - lock (_mappingsLock) { return _mappings.TryGetValue(projectKey, out configurationFilePath); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/DefaultRazorProjectServiceTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/DefaultRazorProjectServiceTest.cs index d8904bf104b..87e989cf9ff 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/DefaultRazorProjectServiceTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/DefaultRazorProjectServiceTest.cs @@ -458,7 +458,7 @@ public void OpenDocument_OpensAndAddsDocumentToOwnerProject() projectSnapshotManager.Setup(manager => manager.DocumentAdded(It.IsAny(), It.IsAny(), It.IsAny())) .Callback((projectKey, hostDocument, loader) => { - Assert.Same(ownerProject.Key, projectKey); + Assert.Equal(ownerProject.Key, projectKey); Assert.Equal(expectedDocumentFilePath, hostDocument.FilePath); Assert.NotNull(loader); @@ -515,7 +515,7 @@ public void AddDocument_AddsDocumentToOwnerProject() projectSnapshotManager.Setup(manager => manager.DocumentAdded(It.IsAny(), It.IsAny(), It.IsAny())) .Callback((projectKey, hostDocument, loader) => { - Assert.Same(ownerProject.Key, projectKey); + Assert.Equal(ownerProject.Key, projectKey); Assert.Equal(documentFilePath, hostDocument.FilePath); Assert.NotNull(loader); }); @@ -539,7 +539,7 @@ public void AddDocument_AddsDocumentToMiscellaneousProject() projectSnapshotManager.Setup(manager => manager.DocumentAdded(It.IsAny(), It.IsAny(), It.IsAny())) .Callback((projectKey, hostDocument, loader) => { - Assert.Same(miscellaneousProject.HostProject.Key, projectKey); + Assert.Equal(miscellaneousProject.HostProject.Key, projectKey); Assert.Equal(documentFilePath, hostDocument.FilePath); Assert.NotNull(loader); }); @@ -568,7 +568,7 @@ public void RemoveDocument_RemovesDocumentFromOwnerProject() projectSnapshotManager.Setup(manager => manager.DocumentRemoved(It.IsAny(), It.IsAny())) .Callback((projectKey, hostDocument) => { - Assert.Same(ownerProject.Key, projectKey); + Assert.Equal(ownerProject.Key, projectKey); Assert.Equal(documentFilePath, hostDocument.FilePath); }); projectSnapshotManager.Setup(manager => manager.IsDocumentOpen(It.IsAny())) @@ -604,7 +604,7 @@ public void RemoveOpenDocument_RemovesDocumentFromOwnerProject_MovesToMiscellane projectSnapshotManager.Setup(manager => manager.DocumentRemoved(It.IsAny(), It.IsAny())) .Callback((projectKey, hostDocument) => { - Assert.Same(ownerProject.Key, projectKey); + Assert.Equal(ownerProject.Key, projectKey); Assert.Equal(documentFilePath, hostDocument.FilePath); }); projectSnapshotManager.Setup(manager => manager.DocumentAdded(It.IsAny(), It.IsAny(), It.IsAny())) @@ -643,7 +643,7 @@ public void RemoveDocument_RemovesDocumentFromMiscellaneousProject() projectSnapshotManager.Setup(manager => manager.DocumentRemoved(It.IsAny(), It.IsAny())) .Callback((projectKey, hostDocument) => { - Assert.Same(miscellaneousProject.Key, projectKey); + Assert.Equal(miscellaneousProject.Key, projectKey); Assert.Equal(documentFilePath, hostDocument.FilePath); }); projectSnapshotManager.Setup(manager => manager.IsDocumentOpen(It.IsAny())) @@ -908,7 +908,7 @@ public void TryMigrateDocumentsFromRemovedProject_MigratesDocumentsToNonMiscProj projectSnapshotManager.Setup(manager => manager.DocumentAdded(It.IsAny(), It.IsAny(), It.IsAny())) .Callback((projectKey, hostDocument, textLoader) => { - Assert.Same(projectToBeMigratedTo.Key, projectKey); + Assert.Equal(projectToBeMigratedTo.Key, projectKey); Assert.NotNull(textLoader); migratedDocuments.Add(hostDocument); @@ -938,7 +938,7 @@ public void TryMigrateDocumentsFromRemovedProject_MigratesDocumentsToMiscProject projectSnapshotManager.Setup(manager => manager.DocumentAdded(It.IsAny(), It.IsAny(), It.IsAny())) .Callback((projectKey, hostDocument, textLoader) => { - Assert.Same(miscellaneousProject.Key, projectKey); + Assert.Equal(miscellaneousProject.Key, projectKey); Assert.NotNull(textLoader); migratedDocuments.Add(hostDocument); @@ -991,7 +991,7 @@ public void TryMigrateMiscellaneousDocumentsToProject_MigratesDocumentsToNewOwne projectSnapshotManager.Setup(manager => manager.DocumentAdded(It.IsAny(), It.IsAny(), It.IsAny())) .Callback((projectKey, hostDocument, textLoader) => { - Assert.Same(projectToBeMigratedTo.Key, projectKey); + Assert.Equal(projectToBeMigratedTo.Key, projectKey); Assert.NotNull(textLoader); migratedDocuments.Add(hostDocument); @@ -999,7 +999,7 @@ public void TryMigrateMiscellaneousDocumentsToProject_MigratesDocumentsToNewOwne projectSnapshotManager.Setup(manager => manager.DocumentRemoved(It.IsAny(), It.IsAny())) .Callback((projectKey, hostDocument) => { - Assert.Same(miscellaneousProject.Key, projectKey); + Assert.Equal(miscellaneousProject.Key, projectKey); Assert.DoesNotContain(hostDocument, migratedDocuments); }); diff --git a/src/Razor/test/Microsoft.VisualStudio.Editor.Razor.Test/Documents/EditorDocumentManagerBaseTest.cs b/src/Razor/test/Microsoft.VisualStudio.Editor.Razor.Test/Documents/EditorDocumentManagerBaseTest.cs index 079cce97482..7ab9eb8d160 100644 --- a/src/Razor/test/Microsoft.VisualStudio.Editor.Razor.Test/Documents/EditorDocumentManagerBaseTest.cs +++ b/src/Razor/test/Microsoft.VisualStudio.Editor.Razor.Test/Documents/EditorDocumentManagerBaseTest.cs @@ -38,7 +38,7 @@ public EditorDocumentManagerBaseTest(ITestOutputHelper testOutput) public void GetOrCreateDocument_CreatesAndCachesDocument() { // Arrange - var expected = _manager.GetOrCreateDocument(new DocumentKey(_project1, _file1), null, null, null, null, null); + var expected = _manager.GetOrCreateDocument(new DocumentKey(_project1, _file1), default, null, null, null, null); // Act _manager.TryGetDocument(new DocumentKey(_project1, _file1), out var actual); @@ -51,10 +51,10 @@ public void GetOrCreateDocument_CreatesAndCachesDocument() public void GetOrCreateDocument_NoOp() { // Arrange - var expected = _manager.GetOrCreateDocument(new DocumentKey(_project1, _file1), null, null, null, null, null); + var expected = _manager.GetOrCreateDocument(new DocumentKey(_project1, _file1), default, null, null, null, null); // Act - var actual = _manager.GetOrCreateDocument(new DocumentKey(_project1, _file1), null, null, null, null, null); + var actual = _manager.GetOrCreateDocument(new DocumentKey(_project1, _file1), default, null, null, null, null); // Assert Assert.Same(expected, actual); @@ -64,10 +64,10 @@ public void GetOrCreateDocument_NoOp() public void GetOrCreateDocument_SameFile_MulipleProjects() { // Arrange - var document1 = _manager.GetOrCreateDocument(new DocumentKey(_project1, _file1), null, null, null, null, null); + var document1 = _manager.GetOrCreateDocument(new DocumentKey(_project1, _file1), default, null, null, null, null); // Act - var document2 = _manager.GetOrCreateDocument(new DocumentKey(_project2, _file1), null, null, null, null, null); + var document2 = _manager.GetOrCreateDocument(new DocumentKey(_project2, _file1), default, null, null, null, null); // Assert Assert.NotSame(document1, document2); @@ -77,10 +77,10 @@ public void GetOrCreateDocument_SameFile_MulipleProjects() public void GetOrCreateDocument_MulipleFiles_SameProject() { // Arrange - var document1 = _manager.GetOrCreateDocument(new DocumentKey(_project1, _file1), null, null, null, null, null); + var document1 = _manager.GetOrCreateDocument(new DocumentKey(_project1, _file1), default, null, null, null, null); // Act - var document2 = _manager.GetOrCreateDocument(new DocumentKey(_project1, _file2), null, null, null, null, null); + var document2 = _manager.GetOrCreateDocument(new DocumentKey(_project1, _file2), default, null, null, null, null); // Assert Assert.NotSame(document1, document2); @@ -93,7 +93,7 @@ public void GetOrCreateDocument_WithBuffer_AttachesBuffer() _manager.Buffers.Add(_file1, _textBuffer); // Act - var document = _manager.GetOrCreateDocument(new DocumentKey(_project1, _file1), null, null, null, null, null); + var document = _manager.GetOrCreateDocument(new DocumentKey(_project1, _file1), default, null, null, null, null); // Assert Assert.True(document.IsOpenInEditor); @@ -107,8 +107,8 @@ public void GetOrCreateDocument_WithBuffer_AttachesBuffer() public void TryGetMatchingDocuments_MultipleDocuments() { // Arrange - var document1 = _manager.GetOrCreateDocument(new DocumentKey(_project1, _file1), null, null, null, null, null); - var document2 = _manager.GetOrCreateDocument(new DocumentKey(_project2, _file1), null, null, null, null, null); + var document1 = _manager.GetOrCreateDocument(new DocumentKey(_project1, _file1), default, null, null, null, null); + var document2 = _manager.GetOrCreateDocument(new DocumentKey(_project2, _file1), default, null, null, null, null); // Act _manager.TryGetMatchingDocuments(_file1, out var documents); @@ -124,8 +124,8 @@ public void TryGetMatchingDocuments_MultipleDocuments() public void RemoveDocument_MultipleDocuments_RemovesOne() { // Arrange - var document1 = _manager.GetOrCreateDocument(new DocumentKey(_project1, _file1), null, null, null, null, null); - var document2 = _manager.GetOrCreateDocument(new DocumentKey(_project2, _file1), null, null, null, null, null); + var document1 = _manager.GetOrCreateDocument(new DocumentKey(_project1, _file1), default, null, null, null, null); + var document2 = _manager.GetOrCreateDocument(new DocumentKey(_project2, _file1), default, null, null, null, null); // Act _manager.RemoveDocument(document1); @@ -141,8 +141,8 @@ public void RemoveDocument_MultipleDocuments_RemovesOne() public void DocumentOpened_MultipleDocuments_OpensAll() { // Arrange - var document1 = _manager.GetOrCreateDocument(new DocumentKey(_project1, _file1), null, null, null, null, null); - var document2 = _manager.GetOrCreateDocument(new DocumentKey(_project2, _file1), null, null, null, null, null); + var document1 = _manager.GetOrCreateDocument(new DocumentKey(_project1, _file1), default, null, null, null, null); + var document2 = _manager.GetOrCreateDocument(new DocumentKey(_project2, _file1), default, null, null, null, null); // Act _manager.DocumentOpened(_file1, _textBuffer); @@ -158,8 +158,8 @@ public void DocumentOpened_MultipleDocuments_OpensAll() public void DocumentOpened_MultipleDocuments_ClosesAll() { // Arrange - var document1 = _manager.GetOrCreateDocument(new DocumentKey(_project1, _file1), null, null, null, null, null); - var document2 = _manager.GetOrCreateDocument(new DocumentKey(_project2, _file1), null, null, null, null, null); + var document1 = _manager.GetOrCreateDocument(new DocumentKey(_project1, _file1), default, null, null, null, null); + var document2 = _manager.GetOrCreateDocument(new DocumentKey(_project2, _file1), default, null, null, null, null); _manager.DocumentOpened(_file1, _textBuffer); // Act diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/WorkspaceProjectStateChangeDetectorTest.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/WorkspaceProjectStateChangeDetectorTest.cs index 96c619b9169..cd85ae43d09 100644 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/WorkspaceProjectStateChangeDetectorTest.cs +++ b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/WorkspaceProjectStateChangeDetectorTest.cs @@ -210,9 +210,9 @@ await s_dispatcher.RunOnDispatcherThreadAsync(() => // Assert Assert.Equal(3, _workQueueTestAccessor.Work.Count); - Assert.Contains(_workQueueTestAccessor.Work, u => u.Key == ProjectKey.From(_projectNumberOne).Id); - Assert.Contains(_workQueueTestAccessor.Work, u => u.Key == ProjectKey.From(_projectNumberTwo).Id); - Assert.Contains(_workQueueTestAccessor.Work, u => u.Key == ProjectKey.From(_projectNumberThree).Id); + Assert.Contains(_workQueueTestAccessor.Work, u => u.Key == ProjectKey.From(_projectNumberOne).Value.Id); + Assert.Contains(_workQueueTestAccessor.Work, u => u.Key == ProjectKey.From(_projectNumberTwo).Value.Id); + Assert.Contains(_workQueueTestAccessor.Work, u => u.Key == ProjectKey.From(_projectNumberThree).Value.Id); _workQueueTestAccessor.BlockBackgroundWorkStart.Set(); _workQueueTestAccessor.NotifyBackgroundWorkCompleted.Wait(); @@ -260,9 +260,9 @@ await s_dispatcher.RunOnDispatcherThreadAsync(() => // Assert Assert.Equal(3, _workQueueTestAccessor.Work.Count); - Assert.Contains(_workQueueTestAccessor.Work, u => u.Key == ProjectKey.From(_projectNumberOne).Id); - Assert.Contains(_workQueueTestAccessor.Work, u => u.Key == ProjectKey.From(_projectNumberTwo).Id); - Assert.Contains(_workQueueTestAccessor.Work, u => u.Key == ProjectKey.From(_projectNumberThree).Id); + Assert.Contains(_workQueueTestAccessor.Work, u => u.Key == ProjectKey.From(_projectNumberOne).Value.Id); + Assert.Contains(_workQueueTestAccessor.Work, u => u.Key == ProjectKey.From(_projectNumberTwo).Value.Id); + Assert.Contains(_workQueueTestAccessor.Work, u => u.Key == ProjectKey.From(_projectNumberThree).Value.Id); _workQueueTestAccessor.BlockBackgroundWorkStart.Set(); _workQueueTestAccessor.NotifyBackgroundWorkCompleted.Wait();