Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,6 @@ internal override ImmutableArray<string> 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))
{
Expand Down Expand Up @@ -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));
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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));
Expand Down Expand Up @@ -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));
Expand All @@ -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,
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public ProjectChangeEventArgs(IProjectSnapshot? older, IProjectSnapshot? newer,
Kind = kind;
SolutionIsClosing = solutionIsClosing;
ProjectFilePath = older?.FilePath ?? newer?.FilePath;
ProjectKey = older?.Key ?? newer?.Key;
ProjectKey = (older ?? newer)!.Key;
}

public IProjectSnapshot? Older { get; }

public IProjectSnapshot? Newer { get; }

public ProjectKey? ProjectKey { get; }
public ProjectKey ProjectKey { get; }

public string? ProjectFilePath { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ 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.
/// </summary>
internal sealed class ProjectKey : IEquatable<ProjectKey>
internal readonly struct ProjectKey : IEquatable<ProjectKey>
{
// 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.
Expand All @@ -37,27 +37,27 @@ 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)
{
return Equals(other as ProjectKey);
return other is ProjectKey key && Equals(key);
}

public bool Equals(ProjectKey? other)
public bool Equals(ProjectKey other)
{
return FilePathComparer.Instance.Equals(Id, other?.Id);
return FilePathComparer.Instance.Equals(Id, other.Id);
}

public static bool operator ==(ProjectKey? lhs, ProjectKey? rhs)
public static bool operator ==(ProjectKey lhs, ProjectKey rhs)
{
return lhs?.Equals(rhs) ?? false;
return lhs.Equals(rhs);
}

public static bool operator !=(ProjectKey? lhs, ProjectKey? rhs)
public static bool operator !=(ProjectKey lhs, ProjectKey rhs)
{
return !lhs?.Equals(rhs) ?? false;
return !lhs.Equals(rhs);
}

public override string ToString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,13 +470,13 @@ private bool TryGetProjectSnapshot(Project? project, [NotNullWhen(true)] out IPr

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.HasValue)
{
projectSnapshot = null;
return false;
}

projectSnapshot = ProjectSnapshotManager.GetLoadedProject(projectKey);
projectSnapshot = ProjectSnapshotManager.GetLoadedProject(projectKey.GetValueOrDefault());
return projectSnapshot is not null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private async Task ProjectManager_ChangedAsync(ProjectChangeEventArgs e, Cancell
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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))
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ public void OpenDocument_OpensAndAddsDocumentToOwnerProject()
projectSnapshotManager.Setup(manager => manager.DocumentAdded(It.IsAny<ProjectKey>(), It.IsAny<HostDocument>(), It.IsAny<TextLoader>()))
.Callback<ProjectKey, HostDocument, TextLoader>((projectKey, hostDocument, loader) =>
{
Assert.Same(ownerProject.Key, projectKey);
Assert.Equal(ownerProject.Key, projectKey);
Assert.Equal(expectedDocumentFilePath, hostDocument.FilePath);
Assert.NotNull(loader);

Expand Down Expand Up @@ -515,7 +515,7 @@ public void AddDocument_AddsDocumentToOwnerProject()
projectSnapshotManager.Setup(manager => manager.DocumentAdded(It.IsAny<ProjectKey>(), It.IsAny<HostDocument>(), It.IsAny<TextLoader>()))
.Callback<ProjectKey, HostDocument, TextLoader>((projectKey, hostDocument, loader) =>
{
Assert.Same(ownerProject.Key, projectKey);
Assert.Equal(ownerProject.Key, projectKey);
Assert.Equal(documentFilePath, hostDocument.FilePath);
Assert.NotNull(loader);
});
Expand All @@ -539,7 +539,7 @@ public void AddDocument_AddsDocumentToMiscellaneousProject()
projectSnapshotManager.Setup(manager => manager.DocumentAdded(It.IsAny<ProjectKey>(), It.IsAny<HostDocument>(), It.IsAny<TextLoader>()))
.Callback<ProjectKey, HostDocument, TextLoader>((projectKey, hostDocument, loader) =>
{
Assert.Same(miscellaneousProject.HostProject.Key, projectKey);
Assert.Equal(miscellaneousProject.HostProject.Key, projectKey);
Assert.Equal(documentFilePath, hostDocument.FilePath);
Assert.NotNull(loader);
});
Expand Down Expand Up @@ -568,7 +568,7 @@ public void RemoveDocument_RemovesDocumentFromOwnerProject()
projectSnapshotManager.Setup(manager => manager.DocumentRemoved(It.IsAny<ProjectKey>(), It.IsAny<HostDocument>()))
.Callback<ProjectKey, HostDocument>((projectKey, hostDocument) =>
{
Assert.Same(ownerProject.Key, projectKey);
Assert.Equal(ownerProject.Key, projectKey);
Assert.Equal(documentFilePath, hostDocument.FilePath);
});
projectSnapshotManager.Setup(manager => manager.IsDocumentOpen(It.IsAny<string>()))
Expand Down Expand Up @@ -604,7 +604,7 @@ public void RemoveOpenDocument_RemovesDocumentFromOwnerProject_MovesToMiscellane
projectSnapshotManager.Setup(manager => manager.DocumentRemoved(It.IsAny<ProjectKey>(), It.IsAny<HostDocument>()))
.Callback<ProjectKey, HostDocument>((projectKey, hostDocument) =>
{
Assert.Same(ownerProject.Key, projectKey);
Assert.Equal(ownerProject.Key, projectKey);
Assert.Equal(documentFilePath, hostDocument.FilePath);
});
projectSnapshotManager.Setup(manager => manager.DocumentAdded(It.IsAny<ProjectKey>(), It.IsAny<HostDocument>(), It.IsAny<TextLoader>()))
Expand Down Expand Up @@ -643,7 +643,7 @@ public void RemoveDocument_RemovesDocumentFromMiscellaneousProject()
projectSnapshotManager.Setup(manager => manager.DocumentRemoved(It.IsAny<ProjectKey>(), It.IsAny<HostDocument>()))
.Callback<ProjectKey, HostDocument>((projectKey, hostDocument) =>
{
Assert.Same(miscellaneousProject.Key, projectKey);
Assert.Equal(miscellaneousProject.Key, projectKey);
Assert.Equal(documentFilePath, hostDocument.FilePath);
});
projectSnapshotManager.Setup(manager => manager.IsDocumentOpen(It.IsAny<string>()))
Expand Down Expand Up @@ -908,7 +908,7 @@ public void TryMigrateDocumentsFromRemovedProject_MigratesDocumentsToNonMiscProj
projectSnapshotManager.Setup(manager => manager.DocumentAdded(It.IsAny<ProjectKey>(), It.IsAny<HostDocument>(), It.IsAny<TextLoader>()))
.Callback<ProjectKey, HostDocument, TextLoader>((projectKey, hostDocument, textLoader) =>
{
Assert.Same(projectToBeMigratedTo.Key, projectKey);
Assert.Equal(projectToBeMigratedTo.Key, projectKey);
Assert.NotNull(textLoader);

migratedDocuments.Add(hostDocument);
Expand Down Expand Up @@ -938,7 +938,7 @@ public void TryMigrateDocumentsFromRemovedProject_MigratesDocumentsToMiscProject
projectSnapshotManager.Setup(manager => manager.DocumentAdded(It.IsAny<ProjectKey>(), It.IsAny<HostDocument>(), It.IsAny<TextLoader>()))
.Callback<ProjectKey, HostDocument, TextLoader>((projectKey, hostDocument, textLoader) =>
{
Assert.Same(miscellaneousProject.Key, projectKey);
Assert.Equal(miscellaneousProject.Key, projectKey);
Assert.NotNull(textLoader);

migratedDocuments.Add(hostDocument);
Expand Down Expand Up @@ -991,15 +991,15 @@ public void TryMigrateMiscellaneousDocumentsToProject_MigratesDocumentsToNewOwne
projectSnapshotManager.Setup(manager => manager.DocumentAdded(It.IsAny<ProjectKey>(), It.IsAny<HostDocument>(), It.IsAny<TextLoader>()))
.Callback<ProjectKey, HostDocument, TextLoader>((projectKey, hostDocument, textLoader) =>
{
Assert.Same(projectToBeMigratedTo.Key, projectKey);
Assert.Equal(projectToBeMigratedTo.Key, projectKey);
Assert.NotNull(textLoader);

migratedDocuments.Add(hostDocument);
});
projectSnapshotManager.Setup(manager => manager.DocumentRemoved(It.IsAny<ProjectKey>(), It.IsAny<HostDocument>()))
.Callback<ProjectKey, HostDocument>((projectKey, hostDocument) =>
{
Assert.Same(miscellaneousProject.Key, projectKey);
Assert.Equal(miscellaneousProject.Key, projectKey);

Assert.DoesNotContain(hostDocument, migratedDocuments);
});
Expand Down
Loading