Skip to content

Commit

Permalink
Fix some null annotations on IDynamicFileInfoProvider
Browse files Browse the repository at this point in the history
The only "interesting" annotation here is we're now potentially calling
the providers with a null project file path; there's nothing that
generally prevented that from happening before, so I'm updating
annotations to match.
  • Loading branch information
jasonmalinowski committed Mar 1, 2023
1 parent 6960e05 commit 2a9f4ed
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ internal interface IRazorDynamicFileInfoProvider
/// <param name="projectFilePath">full path to project file (ex, csproj)</param>
/// <param name="filePath">full path to non source file (ex, cshtml)</param>
/// <returns>null if this provider can't handle the given file</returns>
Task<RazorDynamicFileInfo> GetDynamicFileInfoAsync(ProjectId projectId, string projectFilePath, string filePath, CancellationToken cancellationToken);
Task<RazorDynamicFileInfo> GetDynamicFileInfoAsync(ProjectId projectId, string? projectFilePath, string filePath, CancellationToken cancellationToken);

/// <summary>
/// let provider know certain file has been removed
/// </summary>
/// <param name="projectId"><see cref="ProjectId"/> this file belongs to</param>
/// <param name="projectFilePath">full path to project file (ex, csproj)</param>
/// <param name="filePath">full path to non source file (ex, cshtml)</param>
Task RemoveDynamicFileInfoAsync(ProjectId projectId, string projectFilePath, string filePath, CancellationToken cancellationToken);
Task RemoveDynamicFileInfoAsync(ProjectId projectId, string? projectFilePath, string filePath, CancellationToken cancellationToken);

/// <summary>
/// indicate content of a file has updated. the event argument "string" should be same as "filepath" given to <see cref="GetDynamicFileInfoAsync(ProjectId, string, string, CancellationToken)"/>
Expand Down
4 changes: 2 additions & 2 deletions src/Tools/ExternalAccess/Razor/InternalAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ Microsoft.CodeAnalysis.ExternalAccess.Razor.IRazorDocumentPropertiesService.Diag
Microsoft.CodeAnalysis.ExternalAccess.Razor.IRazorDocumentServiceProvider
Microsoft.CodeAnalysis.ExternalAccess.Razor.IRazorDocumentServiceProvider.GetService<TService>() -> TService?
Microsoft.CodeAnalysis.ExternalAccess.Razor.IRazorDynamicFileInfoProvider
Microsoft.CodeAnalysis.ExternalAccess.Razor.IRazorDynamicFileInfoProvider.GetDynamicFileInfoAsync(Microsoft.CodeAnalysis.ProjectId! projectId, string! projectFilePath, string! filePath, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<Microsoft.CodeAnalysis.ExternalAccess.Razor.RazorDynamicFileInfo!>!
Microsoft.CodeAnalysis.ExternalAccess.Razor.IRazorDynamicFileInfoProvider.RemoveDynamicFileInfoAsync(Microsoft.CodeAnalysis.ProjectId! projectId, string! projectFilePath, string! filePath, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task!
Microsoft.CodeAnalysis.ExternalAccess.Razor.IRazorDynamicFileInfoProvider.GetDynamicFileInfoAsync(Microsoft.CodeAnalysis.ProjectId! projectId, string? projectFilePath, string! filePath, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<Microsoft.CodeAnalysis.ExternalAccess.Razor.RazorDynamicFileInfo?>!
Microsoft.CodeAnalysis.ExternalAccess.Razor.IRazorDynamicFileInfoProvider.RemoveDynamicFileInfoAsync(Microsoft.CodeAnalysis.ProjectId! projectId, string? projectFilePath, string! filePath, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task!
Microsoft.CodeAnalysis.ExternalAccess.Razor.IRazorDynamicFileInfoProvider.Updated -> System.EventHandler<string!>!
Microsoft.CodeAnalysis.ExternalAccess.Razor.IRazorLanguageServerFactoryWrapper
Microsoft.CodeAnalysis.ExternalAccess.Razor.IRazorLanguageServerFactoryWrapper.CreateDocumentInfo(Microsoft.CodeAnalysis.DocumentId! id, string! name, System.Collections.Generic.IReadOnlyList<string!>? folders = null, Microsoft.CodeAnalysis.SourceCodeKind sourceCodeKind = Microsoft.CodeAnalysis.SourceCodeKind.Regular, Microsoft.CodeAnalysis.TextLoader? loader = null, string? filePath = null, bool isGenerated = false, bool designTimeOnly = false, Microsoft.CodeAnalysis.ExternalAccess.Razor.IRazorDocumentServiceProvider? razorDocumentServiceProvider = null) -> Microsoft.CodeAnalysis.DocumentInfo!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public RazorDynamicFileInfoProviderWrapper(
_innerDynamicFileInfoProvider = innerDynamicFileInfoProvider ?? throw new ArgumentNullException(nameof(innerDynamicFileInfoProvider));
}

public async Task<DynamicFileInfo?> GetDynamicFileInfoAsync(ProjectId projectId, string projectFilePath, string filePath, CancellationToken cancellationToken)
public async Task<DynamicFileInfo?> GetDynamicFileInfoAsync(ProjectId projectId, string? projectFilePath, string filePath, CancellationToken cancellationToken)
{
// We lazily attach to the dynamic file info provider in order to ensure that Razor assemblies are not loaded in non-Razor contexts.
if (!EnsureAttached())
Expand All @@ -48,7 +48,7 @@ public RazorDynamicFileInfoProviderWrapper(
return dynamicFileInfo;
}

public Task RemoveDynamicFileInfoAsync(ProjectId projectId, string projectFilePath, string filePath, CancellationToken cancellationToken)
public Task RemoveDynamicFileInfoAsync(ProjectId projectId, string? projectFilePath, string filePath, CancellationToken cancellationToken)
{
if (_innerDynamicFileInfoProvider == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ public DynamicFileInfo(string filePath, SourceCodeKind sourceCodeKind, TextLoade
/// <summary>
/// return <see cref="IDocumentServiceProvider"/> for the content it provided
/// </summary>
public IDocumentServiceProvider DocumentServiceProvider { get; }
public IDocumentServiceProvider? DocumentServiceProvider { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -25,15 +23,15 @@ internal interface IDynamicFileInfoProvider
/// <param name="projectFilePath">full path to project file (ex, csproj)</param>
/// <param name="filePath">full path to non source file (ex, cshtml)</param>
/// <returns>null if this provider can't handle the given file</returns>
Task<DynamicFileInfo> GetDynamicFileInfoAsync(ProjectId projectId, string projectFilePath, string filePath, CancellationToken cancellationToken);
Task<DynamicFileInfo?> GetDynamicFileInfoAsync(ProjectId projectId, string? projectFilePath, string filePath, CancellationToken cancellationToken);

/// <summary>
/// let provider know certain file has been removed
/// </summary>
/// <param name="projectId"><see cref="ProjectId"/> this file belongs to</param>
/// <param name="projectFilePath">full path to project file (ex, csproj)</param>
/// <param name="filePath">full path to non source file (ex, cshtml)</param>
Task RemoveDynamicFileInfoAsync(ProjectId projectId, string projectFilePath, string filePath, CancellationToken cancellationToken);
Task RemoveDynamicFileInfoAsync(ProjectId projectId, string? projectFilePath, string filePath, CancellationToken cancellationToken);

/// <summary>
/// indicate content of a file has updated. the event argument "string" should be same as "filepath" given to <see cref="GetDynamicFileInfoAsync(ProjectId, string, string, CancellationToken)"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,8 @@ public void ProcessDynamicFileChange(string projectSystemFilePath, string worksp
var fileInfo = fileInfoProvider.GetDynamicFileInfoAsync(
_project.Id, _project._filePath, projectSystemFilePath, CancellationToken.None).WaitAndGetResult_CanCallOnBackground(CancellationToken.None);
Contract.ThrowIfNull(fileInfo, "We previously received a dynamic file for this path, and we're responding to a change, so we expect to get a new one.");
// Right now we're only supporting dynamic files as actual source files, so it's OK to call GetDocument here
var attributes = w.CurrentSolution.GetRequiredDocument(documentId).State.Attributes;
Expand Down

0 comments on commit 2a9f4ed

Please sign in to comment.