Skip to content

Commit

Permalink
Merge pull request #8115 from DustinCampbell/nullability
Browse files Browse the repository at this point in the history
Add and fix nullability annotations in Microsoft.CodeAnalysis.Razor.Workspaces
  • Loading branch information
DustinCampbell committed Feb 1, 2023
2 parents b42d501 + 8fa69e5 commit bae9d9e
Show file tree
Hide file tree
Showing 192 changed files with 1,780 additions and 1,755 deletions.
@@ -1,13 +1,12 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;

namespace Microsoft.Extensions.Internal;

internal struct HashCodeCombiner
internal ref struct HashCodeCombiner
{
private long _combinedHash64;

Expand Down
Expand Up @@ -34,7 +34,7 @@ public class RazorCSharpFormattingBenchmark : RazorLanguageServerBenchmarkBase

private Uri DocumentUri { get; set; }

private DocumentSnapshot DocumentSnapshot { get; set; }
private IDocumentSnapshot DocumentSnapshot { get; set; }

private SourceText DocumentText { get; set; }

Expand Down
Expand Up @@ -25,7 +25,7 @@ public class RazorCodeActionsBenchmark : RazorLanguageServerBenchmarkBase
private string? _filePath;
private Uri? DocumentUri { get; set; }
private CodeActionEndpoint? CodeActionEndpoint { get; set; }
private DocumentSnapshot? DocumentSnapshot { get; set; }
private IDocumentSnapshot? DocumentSnapshot { get; set; }
private SourceText? DocumentText { get; set; }
private Range? RazorCodeActionRange { get; set; }
private Range? CSharpCodeActionRange { get; set; }
Expand Down
Expand Up @@ -24,7 +24,7 @@ public class RazorCompletionBenchmark : RazorLanguageServerBenchmarkBase
private string? _filePath;
private Uri? DocumentUri { get; set; }
private RazorCompletionEndpoint? CompletionEndpoint { get; set; }
private DocumentSnapshot? DocumentSnapshot { get; set; }
private IDocumentSnapshot? DocumentSnapshot { get; set; }
private SourceText? DocumentText { get; set; }
private Position? RazorPosition { get; set; }
private RazorRequestContext RazorRequestContext { get; set; }
Expand Down
Expand Up @@ -40,7 +40,7 @@ protected internal virtual void Builder(IServiceCollection collection)

private protected IRazorLogger Logger { get; }

internal DocumentSnapshot GetDocumentSnapshot(string projectFilePath, string filePath, string targetPath)
internal IDocumentSnapshot GetDocumentSnapshot(string projectFilePath, string filePath, string targetPath)
{
var hostProject = new HostProject(projectFilePath, RazorConfiguration.Default, rootNamespace: null);
using var fileStream = new FileStream(filePath, FileMode.Open);
Expand Down
Expand Up @@ -28,7 +28,7 @@ public class RazorSemanticTokensBenchmark : RazorLanguageServerBenchmarkBase

private Uri DocumentUri => DocumentContext.Uri;

private DocumentSnapshot DocumentSnapshot => DocumentContext.Snapshot;
private IDocumentSnapshot DocumentSnapshot => DocumentContext.Snapshot;

private VersionedDocumentContext DocumentContext { get; set; }

Expand Down Expand Up @@ -94,7 +94,7 @@ private static LspServices GetLspServices()
throw new NotImplementedException();
}

private async Task UpdateDocumentAsync(int newVersion, DocumentSnapshot documentSnapshot, CancellationToken cancellationToken)
private async Task UpdateDocumentAsync(int newVersion, IDocumentSnapshot documentSnapshot, CancellationToken cancellationToken)
{
await ProjectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(
() => VersionCache.TrackDocumentVersion(documentSnapshot, newVersion), cancellationToken).ConfigureAwait(false);
Expand Down
Expand Up @@ -28,7 +28,7 @@ public class RazorSemanticTokensScrollingBenchmark : RazorLanguageServerBenchmar

private Uri DocumentUri => DocumentContext.Uri;

private DocumentSnapshot DocumentSnapshot => DocumentContext.Snapshot;
private IDocumentSnapshot DocumentSnapshot => DocumentContext.Snapshot;

private Range Range { get; set; }

Expand Down Expand Up @@ -106,7 +106,7 @@ public async Task RazorSemanticTokensRangeScrollingAsync()
}
}

private async Task UpdateDocumentAsync(int newVersion, DocumentSnapshot documentSnapshot)
private async Task UpdateDocumentAsync(int newVersion, IDocumentSnapshot documentSnapshot)
{
await ProjectSnapshotManagerDispatcher!.RunOnDispatcherThreadAsync(
() => VersionCache!.TrackDocumentVersion(documentSnapshot, newVersion), CancellationToken.None).ConfigureAwait(false);
Expand Down
Expand Up @@ -13,10 +13,10 @@ public abstract partial class ProjectSnapshotManagerBenchmarkBase
{
private class StaticProjectSnapshotProjectEngineFactory : ProjectSnapshotProjectEngineFactory
{
public override IProjectEngineFactory FindFactory(ProjectSnapshot project)
public override IProjectEngineFactory FindFactory(IProjectSnapshot project)
=> throw new NotImplementedException();

public override IProjectEngineFactory FindSerializableFactory(ProjectSnapshot project)
public override IProjectEngineFactory FindSerializableFactory(IProjectSnapshot project)
=> throw new NotImplementedException();

public override RazorProjectEngine Create(
Expand Down
Expand Up @@ -27,7 +27,7 @@ public StaticTagHelperResolver(IReadOnlyList<TagHelperDescriptor> tagHelpers, IT

public override Task<TagHelperResolutionResult> GetTagHelpersAsync(
Project project,
ProjectSnapshot projectSnapshot,
IProjectSnapshot projectSnapshot,
CancellationToken cancellationToken = default)
=> Task.FromResult(new TagHelperResolutionResult(_tagHelpers, Array.Empty<RazorDiagnostic>()));
}
Expand Down
Expand Up @@ -10,17 +10,17 @@ namespace Microsoft.AspNetCore.Razor.Microbenchmarks;

public abstract partial class ProjectSnapshotManagerBenchmarkBase
{
private class TestErrorReporter : ErrorReporter
private class TestErrorReporter : IErrorReporter
{
public override void ReportError(Exception exception)
public void ReportError(Exception exception)
{
}

public override void ReportError(Exception exception, ProjectSnapshot? project)
public void ReportError(Exception exception, IProjectSnapshot? project)
{
}

public override void ReportError(Exception exception, Project workspaceProject)
public void ReportError(Exception exception, Project workspaceProject)
{
}
}
Expand Down
Expand Up @@ -28,7 +28,7 @@ public ProjectSnapshotSerializationBenchmark()
}

public JsonSerializer Serializer { get; set; }
private ProjectSnapshot ProjectSnapshot { get; }
private IProjectSnapshot ProjectSnapshot { get; }

[Benchmark(Description = "Razor ProjectSnapshot Roundtrip JsonConverter Serialization")]
public void TagHelper_JsonConvert_Serialization_RoundTrip()
Expand Down
@@ -1,9 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.

using System.Collections.Generic;

namespace Microsoft.AspNetCore.Razor;
namespace System.Collections.Generic;

internal static class KeyValuePairExtensions
{
Expand Down
@@ -0,0 +1,29 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.

using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime;
using System.Runtime.CompilerServices;

namespace Microsoft.AspNetCore.Razor;

internal static class NullableExtensions
{
[DebuggerStepThrough]
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
public static T AssumeNotNull<T>(
[NotNull] this T? obj,
[CallerArgumentExpression(nameof(obj))] string? objExpression = null)
where T : class
=> obj ?? throw new InvalidOperationException($"Expected '{objExpression}' to be non-null.");

[DebuggerStepThrough]
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
public static T AssumeNotNull<T>(
[NotNull] this T? obj,
[CallerArgumentExpression(nameof(obj))] string? objExpression = null)
where T : struct
=> obj ?? throw new InvalidOperationException($"Expected '{objExpression}' to be non-null.");
}
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Composition;
using System.Diagnostics;
Expand Down

0 comments on commit bae9d9e

Please sign in to comment.