Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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 @@ -36,15 +36,15 @@
/// The latter is useful for <c>dotnet run file.cs</c> where if there are app directives after the first token,
/// compiler reports <see cref="ErrorCode.ERR_PPIgnoredFollowsToken"/> anyway, so we speed up success scenarios by not parsing the whole file up front in the SDK CLI.
/// </param>
public static ImmutableArray<CSharpDirective> FindDirectives(SourceFile sourceFile, bool reportAllErrors, ErrorReporter reportError)
public static ImmutableArray<CSharpDirective> FindDirectives(SourceFile sourceFile, bool reportAllErrors, ErrorReporter errorReporter)

Check failure on line 39 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TestBuild: linux (x64))

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L39

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(39,51): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'static Microsoft.DotNet.FileBasedPrograms.FileLevelDirectiveHelpers.FindDirectives(Microsoft.DotNet.FileBasedPrograms.SourceFile sourceFile, bool reportAllErrors, Microsoft.DotNet.FileBasedPrograms.ErrorReporter! errorReporter) -> System.Collections.Immutable.ImmutableArray<Microsoft.DotNet.FileBasedPrograms.CSharpDirective!>' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 39 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build AoT: macOS (x64))

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L39

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(39,51): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'static Microsoft.DotNet.FileBasedPrograms.FileLevelDirectiveHelpers.FindDirectives(Microsoft.DotNet.FileBasedPrograms.SourceFile sourceFile, bool reportAllErrors, Microsoft.DotNet.FileBasedPrograms.ErrorReporter! errorReporter) -> System.Collections.Immutable.ImmutableArray<Microsoft.DotNet.FileBasedPrograms.CSharpDirective!>' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)
{
var builder = ImmutableArray.CreateBuilder<CSharpDirective>();
var tokenizer = CreateTokenizer(sourceFile.Text);

var result = tokenizer.ParseLeadingTrivia();
var triviaList = result.Token.LeadingTrivia;

FindLeadingDirectives(sourceFile, triviaList, reportError, builder);
FindLeadingDirectives(sourceFile, triviaList, errorReporter, builder);

// In conversion mode, we want to report errors for any invalid directives in the rest of the file
// so users don't end up with invalid directives in the converted project.
Expand Down Expand Up @@ -73,7 +73,7 @@
{
if (trivia.ContainsDiagnostics && trivia.IsKind(SyntaxKind.IgnoredDirectiveTrivia))
{
reportError(sourceFile, trivia.Span, FileBasedProgramsResources.CannotConvertDirective);
errorReporter(sourceFile.Text, sourceFile.Path, trivia.Span, FileBasedProgramsResources.CannotConvertDirective);
}
}

Expand All @@ -83,10 +83,10 @@

/// <summary>Finds file-level directives in the leading trivia list of a compilation unit and reports diagnostics on them.</summary>
/// <param name="builder">The builder to store the parsed directives in, or null if the parsed directives are not needed.</param>
public static void FindLeadingDirectives(

Check failure on line 86 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build AoT: macOS (x64))

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L86

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(86,24): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'static Microsoft.DotNet.FileBasedPrograms.FileLevelDirectiveHelpers.FindLeadingDirectives(Microsoft.DotNet.FileBasedPrograms.SourceFile sourceFile, Microsoft.CodeAnalysis.SyntaxTriviaList triviaList, Microsoft.DotNet.FileBasedPrograms.ErrorReporter! errorReporter, System.Collections.Immutable.ImmutableArray<Microsoft.DotNet.FileBasedPrograms.CSharpDirective!>.Builder? builder) -> void' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)
SourceFile sourceFile,
SyntaxTriviaList triviaList,
ErrorReporter reportError,
ErrorReporter errorReporter,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably decide on naming and consolidate it everywhere. I think I've been renaming some parameters in the other direction (to reportError) as part of #52347.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed to avoid collision between helpers Context.ReportError and ErrorReporter ReportError field.

ImmutableArray<CSharpDirective>.Builder? builder)
{
Debug.Assert(triviaList.Span.Start == 0);
Expand Down Expand Up @@ -144,7 +144,7 @@
LeadingWhiteSpace = whiteSpace.Leading,
TrailingWhiteSpace = whiteSpace.Trailing,
},
ReportError = reportError,
ErrorReporter = errorReporter,
SourceFile = sourceFile,
DirectiveKind = name,
DirectiveText = value,
Expand All @@ -153,7 +153,7 @@
// Block quotes now so we can later support quoted values without a breaking change. https://github.com/dotnet/sdk/issues/49367
if (value.Contains('"'))
{
reportError(sourceFile, context.Info.Span, FileBasedProgramsResources.QuoteInDirective);
context.ReportError(FileBasedProgramsResources.QuoteInDirective);
}

if (CSharpDirective.Parse(context) is { } directive)
Expand All @@ -162,7 +162,7 @@
if (deduplicated.TryGetValue(directive, out var existingDirective))
{
var typeAndName = $"#:{existingDirective.GetType().Name.ToLowerInvariant()} {existingDirective.Name}";
reportError(sourceFile, directive.Info.Span, string.Format(FileBasedProgramsResources.DuplicateDirective, typeAndName));
context.ReportError(directive.Info.Span, string.Format(FileBasedProgramsResources.DuplicateDirective, typeAndName));
}
else
{
Expand Down Expand Up @@ -231,11 +231,6 @@
return new SourceFile(filePath, SourceText.From(stream, encoding: null));
}

public SourceFile WithText(SourceText newText)
{
return new SourceFile(Path, newText);
}

public void Save()
{
using var stream = File.Open(Path, FileMode.Create, FileAccess.Write);
Expand All @@ -244,17 +239,6 @@
using var writer = new StreamWriter(stream, encoding);
Text.Write(writer);
}

public FileLinePositionSpan GetFileLinePositionSpan(TextSpan span)
{
return new FileLinePositionSpan(Path, Text.Lines.GetLinePositionSpan(span));
}

public string GetLocationString(TextSpan span)
{
var positionSpan = GetFileLinePositionSpan(span);
return $"{positionSpan.Path}({positionSpan.StartLinePosition.Line + 1})";
}
}

internal static partial class Patterns
Expand Down Expand Up @@ -293,10 +277,16 @@
public readonly struct ParseContext
{
public required ParseInfo Info { get; init; }
public required ErrorReporter ReportError { get; init; }
public required ErrorReporter ErrorReporter { get; init; }

Check failure on line 280 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TestBuild: linux (x64))

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L280

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(280,60): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.DotNet.FileBasedPrograms.CSharpDirective.ParseContext.ErrorReporter.init -> void' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 280 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TestBuild: linux (x64))

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L280

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(280,55): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.DotNet.FileBasedPrograms.CSharpDirective.ParseContext.ErrorReporter.get -> Microsoft.DotNet.FileBasedPrograms.ErrorReporter!' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 280 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TestBuild: linux (arm64))

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L280

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(280,60): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.DotNet.FileBasedPrograms.CSharpDirective.ParseContext.ErrorReporter.init -> void' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 280 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TestBuild: linux (arm64))

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L280

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(280,55): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.DotNet.FileBasedPrograms.CSharpDirective.ParseContext.ErrorReporter.get -> Microsoft.DotNet.FileBasedPrograms.ErrorReporter!' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 280 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TemplateEngine: linux (x64))

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L280

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(280,55): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.DotNet.FileBasedPrograms.CSharpDirective.ParseContext.ErrorReporter.get -> Microsoft.DotNet.FileBasedPrograms.ErrorReporter!' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 280 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TemplateEngine: linux (x64))

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L280

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(280,60): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.DotNet.FileBasedPrograms.CSharpDirective.ParseContext.ErrorReporter.init -> void' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 280 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TestBuild: macOS (x64))

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L280

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(280,55): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.DotNet.FileBasedPrograms.CSharpDirective.ParseContext.ErrorReporter.get -> Microsoft.DotNet.FileBasedPrograms.ErrorReporter!' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 280 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TestBuild: macOS (x64))

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L280

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(280,60): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.DotNet.FileBasedPrograms.CSharpDirective.ParseContext.ErrorReporter.init -> void' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 280 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TemplateEngine: macOS (x64))

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L280

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(280,55): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.DotNet.FileBasedPrograms.CSharpDirective.ParseContext.ErrorReporter.get -> Microsoft.DotNet.FileBasedPrograms.ErrorReporter!' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 280 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TemplateEngine: macOS (x64))

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L280

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(280,60): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.DotNet.FileBasedPrograms.CSharpDirective.ParseContext.ErrorReporter.init -> void' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 280 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TestBuild: macOS (arm64))

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L280

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(280,55): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.DotNet.FileBasedPrograms.CSharpDirective.ParseContext.ErrorReporter.get -> Microsoft.DotNet.FileBasedPrograms.ErrorReporter!' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 280 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TestBuild: macOS (arm64))

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L280

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(280,60): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.DotNet.FileBasedPrograms.CSharpDirective.ParseContext.ErrorReporter.init -> void' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 280 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build AoT: macOS (x64))

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L280

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(280,60): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.DotNet.FileBasedPrograms.CSharpDirective.ParseContext.ErrorReporter.init -> void' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 280 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L280

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(280,60): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.DotNet.FileBasedPrograms.CSharpDirective.ParseContext.ErrorReporter.init -> void' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 280 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L280

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(280,55): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.DotNet.FileBasedPrograms.CSharpDirective.ParseContext.ErrorReporter.get -> Microsoft.DotNet.FileBasedPrograms.ErrorReporter!' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)
public required SourceFile SourceFile { get; init; }
public required string DirectiveKind { get; init; }
public required string DirectiveText { get; init; }

public void ReportError(string message)

Check failure on line 285 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TestBuild: linux (x64))

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L285

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(285,21): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.DotNet.FileBasedPrograms.CSharpDirective.ParseContext.ReportError(string! message) -> void' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 285 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TestBuild: linux (arm64))

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L285

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(285,21): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.DotNet.FileBasedPrograms.CSharpDirective.ParseContext.ReportError(string! message) -> void' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 285 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TemplateEngine: linux (x64))

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L285

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(285,21): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.DotNet.FileBasedPrograms.CSharpDirective.ParseContext.ReportError(string! message) -> void' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 285 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TestBuild: macOS (x64))

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L285

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(285,21): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.DotNet.FileBasedPrograms.CSharpDirective.ParseContext.ReportError(string! message) -> void' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 285 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TemplateEngine: macOS (x64))

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L285

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(285,21): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.DotNet.FileBasedPrograms.CSharpDirective.ParseContext.ReportError(string! message) -> void' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 285 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TestBuild: macOS (arm64))

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L285

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(285,21): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.DotNet.FileBasedPrograms.CSharpDirective.ParseContext.ReportError(string! message) -> void' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 285 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L285

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(285,21): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.DotNet.FileBasedPrograms.CSharpDirective.ParseContext.ReportError(string! message) -> void' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)
=> ErrorReporter(SourceFile.Text, SourceFile.Path, Info.Span, message);

public void ReportError(TextSpan span, string message)

Check failure on line 288 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TemplateEngine: linux (x64))

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L288

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(288,21): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.DotNet.FileBasedPrograms.CSharpDirective.ParseContext.ReportError(Microsoft.CodeAnalysis.Text.TextSpan span, string! message) -> void' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 288 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TestBuild: macOS (x64))

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L288

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(288,21): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.DotNet.FileBasedPrograms.CSharpDirective.ParseContext.ReportError(Microsoft.CodeAnalysis.Text.TextSpan span, string! message) -> void' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 288 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TemplateEngine: macOS (x64))

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L288

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(288,21): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.DotNet.FileBasedPrograms.CSharpDirective.ParseContext.ReportError(Microsoft.CodeAnalysis.Text.TextSpan span, string! message) -> void' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)
=> ErrorReporter(SourceFile.Text, SourceFile.Path, span, message);
}

public static Named? Parse(in ParseContext context)
Expand All @@ -308,7 +298,7 @@
case "package": return Package.Parse(context);
case "project": return Project.Parse(context);
default:
context.ReportError(context.SourceFile, context.Info.Span, string.Format(FileBasedProgramsResources.UnrecognizedDirective, context.DirectiveKind));
context.ReportError(string.Format(FileBasedProgramsResources.UnrecognizedDirective, context.DirectiveKind));
return null;
};
}
Expand All @@ -321,14 +311,14 @@
string directiveKind = context.DirectiveKind;
if (firstPart.IsWhiteSpace())
{
context.ReportError(context.SourceFile, context.Info.Span, string.Format(FileBasedProgramsResources.MissingDirectiveName, directiveKind));
context.ReportError(string.Format(FileBasedProgramsResources.MissingDirectiveName, directiveKind));
return null;
}

// If the name contains characters that resemble separators, report an error to avoid any confusion.
if (Patterns.DisallowedNameCharacters.Match(context.DirectiveText, beginning: 0, length: firstPart.Length).Success)
{
context.ReportError(context.SourceFile, context.Info.Span, string.Format(FileBasedProgramsResources.InvalidDirectiveName, directiveKind, separator));
context.ReportError(string.Format(FileBasedProgramsResources.InvalidDirectiveName, directiveKind, separator));
return null;
}

Expand Down Expand Up @@ -404,7 +394,7 @@

if (propertyValue is null)
{
context.ReportError(context.SourceFile, context.Info.Span, FileBasedProgramsResources.PropertyDirectiveMissingParts);
context.ReportError(FileBasedProgramsResources.PropertyDirectiveMissingParts);
return null;
}

Expand All @@ -414,14 +404,14 @@
}
catch (XmlException ex)
{
context.ReportError(context.SourceFile, context.Info.Span, string.Format(FileBasedProgramsResources.PropertyDirectiveInvalidName, ex.Message));
context.ReportError(string.Format(FileBasedProgramsResources.PropertyDirectiveInvalidName, ex.Message));
return null;
}

if (propertyName.Equals("RestoreUseStaticGraphEvaluation", StringComparison.OrdinalIgnoreCase) &&
MSBuildUtilities.ConvertStringToBool(propertyValue))
{
context.ReportError(context.SourceFile, context.Info.Span, FileBasedProgramsResources.StaticGraphRestoreNotSupported);
context.ReportError(FileBasedProgramsResources.StaticGraphRestoreNotSupported);
}

return new Property(context.Info)
Expand Down Expand Up @@ -493,8 +483,7 @@
var directiveText = context.DirectiveText;
if (directiveText.IsWhiteSpace())
{
string directiveKind = context.DirectiveKind;
context.ReportError(context.SourceFile, context.Info.Span, string.Format(FileBasedProgramsResources.MissingDirectiveName, directiveKind));
context.ReportError(string.Format(FileBasedProgramsResources.MissingDirectiveName, context.DirectiveKind));
return null;
}

Expand Down Expand Up @@ -532,14 +521,15 @@
/// <summary>
/// If the directive points to a directory, returns a new directive pointing to the corresponding project file.
/// </summary>
public Project EnsureProjectFilePath(SourceFile sourceFile, ErrorReporter reportError)
public Project EnsureProjectFilePath(SourceFile sourceFile, ErrorReporter errorReporter)

Check failure on line 524 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TestBuild: linux (arm64))

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L524

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(524,24): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.DotNet.FileBasedPrograms.CSharpDirective.Project.EnsureProjectFilePath(Microsoft.DotNet.FileBasedPrograms.SourceFile sourceFile, Microsoft.DotNet.FileBasedPrograms.ErrorReporter! errorReporter) -> Microsoft.DotNet.FileBasedPrograms.CSharpDirective.Project!' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 524 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TestBuild: macOS (arm64))

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L524

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(524,24): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.DotNet.FileBasedPrograms.CSharpDirective.Project.EnsureProjectFilePath(Microsoft.DotNet.FileBasedPrograms.SourceFile sourceFile, Microsoft.DotNet.FileBasedPrograms.ErrorReporter! errorReporter) -> Microsoft.DotNet.FileBasedPrograms.CSharpDirective.Project!' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 524 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build AoT: macOS (x64))

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L524

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(524,24): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.DotNet.FileBasedPrograms.CSharpDirective.Project.EnsureProjectFilePath(Microsoft.DotNet.FileBasedPrograms.SourceFile sourceFile, Microsoft.DotNet.FileBasedPrograms.ErrorReporter! errorReporter) -> Microsoft.DotNet.FileBasedPrograms.CSharpDirective.Project!' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)
{
var resolvedName = Name;
var sourcePath = sourceFile.Path;

// If the path is a directory like '../lib', transform it to a project file path like '../lib/lib.csproj'.
// Also normalize backslashes to forward slashes to ensure the directive works on all platforms.
var sourceDirectory = Path.GetDirectoryName(sourceFile.Path)
?? throw new InvalidOperationException($"Source file path '{sourceFile.Path}' does not have a containing directory.");
var sourceDirectory = Path.GetDirectoryName(sourcePath)
?? throw new InvalidOperationException($"Source file path '{sourcePath}' does not have a containing directory.");

var resolvedProjectPath = Path.Combine(sourceDirectory, resolvedName.Replace('\\', '/'));
if (Directory.Exists(resolvedProjectPath))
Expand All @@ -553,16 +543,18 @@
}
else
{
reportError(sourceFile, Info.Span, string.Format(FileBasedProgramsResources.InvalidProjectDirective, error));
ReportError(string.Format(FileBasedProgramsResources.InvalidProjectDirective, error));
}
}
else if (!File.Exists(resolvedProjectPath))
{
reportError(sourceFile, Info.Span,
string.Format(FileBasedProgramsResources.InvalidProjectDirective, string.Format(FileBasedProgramsResources.CouldNotFindProjectOrDirectory, resolvedProjectPath)));
ReportError(string.Format(FileBasedProgramsResources.InvalidProjectDirective, string.Format(FileBasedProgramsResources.CouldNotFindProjectOrDirectory, resolvedProjectPath)));
}

return WithName(resolvedName, NameKind.ProjectFilePath);

void ReportError(string message)
=> errorReporter(sourceFile.Text, sourcePath, Info.Span, message);
}

public override string ToString() => $"#:project {Name}";
Expand Down Expand Up @@ -617,25 +609,25 @@
}
}

internal delegate void ErrorReporter(SourceFile sourceFile, TextSpan textSpan, string message);
internal delegate void ErrorReporter(SourceText text, string path, TextSpan textSpan, string message);

Check failure on line 612 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TestBuild: linux (x64))

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L612

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(612,24): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'virtual Microsoft.DotNet.FileBasedPrograms.ErrorReporter.Invoke(Microsoft.CodeAnalysis.Text.SourceText! text, string! path, Microsoft.CodeAnalysis.Text.TextSpan textSpan, string! message) -> void' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 612 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TestBuild: linux (arm64))

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L612

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(612,24): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'virtual Microsoft.DotNet.FileBasedPrograms.ErrorReporter.Invoke(Microsoft.CodeAnalysis.Text.SourceText! text, string! path, Microsoft.CodeAnalysis.Text.TextSpan textSpan, string! message) -> void' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 612 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TemplateEngine: linux (x64))

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L612

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(612,24): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'virtual Microsoft.DotNet.FileBasedPrograms.ErrorReporter.Invoke(Microsoft.CodeAnalysis.Text.SourceText! text, string! path, Microsoft.CodeAnalysis.Text.TextSpan textSpan, string! message) -> void' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 612 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TestBuild: macOS (x64))

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L612

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(612,24): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'virtual Microsoft.DotNet.FileBasedPrograms.ErrorReporter.Invoke(Microsoft.CodeAnalysis.Text.SourceText! text, string! path, Microsoft.CodeAnalysis.Text.TextSpan textSpan, string! message) -> void' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 612 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TemplateEngine: macOS (x64))

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L612

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(612,24): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'virtual Microsoft.DotNet.FileBasedPrograms.ErrorReporter.Invoke(Microsoft.CodeAnalysis.Text.SourceText! text, string! path, Microsoft.CodeAnalysis.Text.TextSpan textSpan, string! message) -> void' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 612 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TestBuild: macOS (arm64))

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L612

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(612,24): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'virtual Microsoft.DotNet.FileBasedPrograms.ErrorReporter.Invoke(Microsoft.CodeAnalysis.Text.SourceText! text, string! path, Microsoft.CodeAnalysis.Text.TextSpan textSpan, string! message) -> void' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 612 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build AoT: macOS (x64))

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L612

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(612,24): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'virtual Microsoft.DotNet.FileBasedPrograms.ErrorReporter.Invoke(Microsoft.CodeAnalysis.Text.SourceText! text, string! path, Microsoft.CodeAnalysis.Text.TextSpan textSpan, string! message) -> void' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 612 in src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs#L612

src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs(612,24): error RS0051: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'virtual Microsoft.DotNet.FileBasedPrograms.ErrorReporter.Invoke(Microsoft.CodeAnalysis.Text.SourceText! text, string! path, Microsoft.CodeAnalysis.Text.TextSpan textSpan, string! message) -> void' is not part of the declared API (https://github.com/dotnet/roslyn/blob/main/src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

internal static partial class ErrorReporters
{
public static readonly ErrorReporter IgnoringReporter =
static (_, _, _) => { };
static (_, _, _, _) => { };

public static ErrorReporter CreateCollectingReporter(out ImmutableArray<SimpleDiagnostic>.Builder builder)
{
var capturedBuilder = builder = ImmutableArray.CreateBuilder<SimpleDiagnostic>();

return (sourceFile, textSpan, message) =>
return (text, path, textSpan, message) =>
capturedBuilder.Add(new SimpleDiagnostic
{
Location = new SimpleDiagnostic.Position()
{
Path = sourceFile.Path,
Path = path,
TextSpan = textSpan,
Span = sourceFile.GetFileLinePositionSpan(textSpan).Span
Span = text.Lines.GetLinePositionSpan(textSpan)
},
Message = message
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public override int Execute()
// Create a project instance for evaluation.
var projectCollection = new ProjectCollection();

var builder = new VirtualProjectBuilder(file, VirtualProjectBuildingCommand.TargetFrameworkVersion);
var builder = new VirtualProjectBuilder(file, VirtualProjectBuildingCommand.TargetFramework);

builder.CreateProjectInstance(
projectCollection,
Expand Down
4 changes: 2 additions & 2 deletions src/Cli/dotnet/Commands/Run/FileBasedAppSourceEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static string GetNewLine(SourceText text)
public void Add(CSharpDirective directive)
{
var change = DetermineAddChange(directive);
SourceFile = SourceFile.WithText(SourceFile.Text.WithChanges([change]));
SourceFile = SourceFile with { Text = SourceFile.Text.WithChanges([change]) };
}

private TextChange DetermineAddChange(CSharpDirective directive)
Expand Down Expand Up @@ -231,7 +231,7 @@ public void Remove(CSharpDirective directive)
var span = directive.Info.Span;
var start = span.Start;
var length = span.Length + DetermineTrailingLengthToRemove(directive);
SourceFile = SourceFile.WithText(SourceFile.Text.Replace(start: start, length: length, newText: string.Empty));
SourceFile = SourceFile with { Text = SourceFile.Text.Replace(start: start, length: length, newText: string.Empty) };
}

private static int DetermineTrailingLengthToRemove(CSharpDirective directive)
Expand Down
7 changes: 5 additions & 2 deletions src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Microsoft.Build.Logging;
using Microsoft.Build.Logging.SimpleErrorLogger;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
using Microsoft.DotNet.Cli.Commands.Clean.FileBasedAppArtifacts;
using Microsoft.DotNet.Cli.Commands.Restore;
using Microsoft.DotNet.Cli.Utils;
Expand Down Expand Up @@ -82,6 +83,7 @@ internal sealed class VirtualProjectBuildingCommand : CommandBase
];

public static string TargetFrameworkVersion => Product.TargetFrameworkVersion;
public static string TargetFramework => $"net{Product.TargetFrameworkVersion}";

public bool NoRestore { get; init; }

Expand Down Expand Up @@ -139,7 +141,7 @@ public VirtualProjectBuildingCommand(
}
.AsReadOnly());

Builder = new VirtualProjectBuilder(entryPointFileFullPath, TargetFrameworkVersion, MSBuildArgs.GetResolvedTargets(), artifactsPath);
Builder = new VirtualProjectBuilder(entryPointFileFullPath, TargetFramework, MSBuildArgs.GetResolvedTargets(), artifactsPath);
}

public override int Execute()
Expand Down Expand Up @@ -1076,7 +1078,8 @@ public static void CreateTempSubdirectory(string path)
}

public static readonly ErrorReporter ThrowingReporter =
static (sourceFile, textSpan, message) => throw new GracefulException($"{sourceFile.GetLocationString(textSpan)}: {FileBasedProgramsResources.DirectiveError}: {message}");
static (text, path, textSpan, message) =>
throw new GracefulException($"{path}({text.Lines.GetLinePositionSpan(textSpan).Start.Line + 1}): {FileBasedProgramsResources.DirectiveError}: {message}");
}

internal sealed class RunFileBuildCacheEntry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

<ItemGroup>
<InternalsVisibleTo Include="dotnet" />
<InternalsVisibleTo Include="dotnet-watch.Tests" />
<InternalsVisibleTo Include="dotnet.Tests" />
<InternalsVisibleTo Include="Microsoft.DotNet.HotReload.Watch" />
</ItemGroup>

<Import Project="..\Cli\Microsoft.DotNet.FileBasedPrograms\Microsoft.DotNet.FileBasedPrograms.projitems" Label="Shared" />
Expand Down
Loading
Loading