@@ -1488,7 +1488,7 @@ public static ImmutableArray<CSharpDirective> FindDirectives(SourceFile sourceFi
1488
1488
if ( deduplicated . TryGetValue ( directive , out var existingDirective ) )
1489
1489
{
1490
1490
var typeAndName = $ "#:{ existingDirective . GetType ( ) . Name . ToLowerInvariant ( ) } { existingDirective . Name } ";
1491
- diagnostics . AddError ( sourceFile , directive . Info . Span , location => string . Format ( CliCommandStrings . DuplicateDirective , typeAndName , location ) ) ;
1491
+ diagnostics . AddError ( sourceFile , directive . Info . Span , string . Format ( CliCommandStrings . DuplicateDirective , typeAndName ) ) ;
1492
1492
}
1493
1493
else
1494
1494
{
@@ -1538,7 +1538,7 @@ void ReportErrorFor(SyntaxTrivia trivia)
1538
1538
{
1539
1539
if ( trivia . ContainsDiagnostics && trivia . IsKind ( SyntaxKind . IgnoredDirectiveTrivia ) )
1540
1540
{
1541
- diagnostics . AddError ( sourceFile , trivia . Span , location => string . Format ( CliCommandStrings . CannotConvertDirective , location ) ) ;
1541
+ diagnostics . AddError ( sourceFile , trivia . Span , CliCommandStrings . CannotConvertDirective ) ;
1542
1542
}
1543
1543
}
1544
1544
@@ -1660,7 +1660,7 @@ public FileLinePositionSpan GetFileLinePositionSpan(TextSpan span)
1660
1660
public string GetLocationString ( TextSpan span )
1661
1661
{
1662
1662
var positionSpan = GetFileLinePositionSpan ( span ) ;
1663
- return $ "{ positionSpan . Path } : { positionSpan . StartLinePosition . Line + 1 } ";
1663
+ return $ "{ positionSpan . Path } ( { positionSpan . StartLinePosition . Line + 1 } ) ";
1664
1664
}
1665
1665
}
1666
1666
@@ -1717,7 +1717,7 @@ public readonly struct ParseContext
1717
1717
"property" => Property . Parse ( context ) ,
1718
1718
"package" => Package . Parse ( context ) ,
1719
1719
"project" => Project . Parse ( context ) ,
1720
- var other => context . Diagnostics . AddError < Named > ( context . SourceFile , context . Info . Span , location => string . Format ( CliCommandStrings . UnrecognizedDirective , other , location ) ) ,
1720
+ var other => context . Diagnostics . AddError < Named > ( context . SourceFile , context . Info . Span , string . Format ( CliCommandStrings . UnrecognizedDirective , other ) ) ,
1721
1721
} ;
1722
1722
}
1723
1723
@@ -1729,13 +1729,13 @@ private static (string, string?)? ParseOptionalTwoParts(in ParseContext context,
1729
1729
string directiveKind = context . DirectiveKind ;
1730
1730
if ( firstPart . IsWhiteSpace ( ) )
1731
1731
{
1732
- return context . Diagnostics . AddError < ( string , string ? ) ? > ( context . SourceFile , context . Info . Span , location => string . Format ( CliCommandStrings . MissingDirectiveName , directiveKind , location ) ) ;
1732
+ return context . Diagnostics . AddError < ( string , string ? ) ? > ( context . SourceFile , context . Info . Span , string . Format ( CliCommandStrings . MissingDirectiveName , directiveKind ) ) ;
1733
1733
}
1734
1734
1735
1735
// If the name contains characters that resemble separators, report an error to avoid any confusion.
1736
1736
if ( Patterns . DisallowedNameCharacters . IsMatch ( firstPart ) )
1737
1737
{
1738
- return context . Diagnostics . AddError < ( string , string ? ) ? > ( context . SourceFile , context . Info . Span , location => string . Format ( CliCommandStrings . InvalidDirectiveName , directiveKind , separator , location ) ) ;
1738
+ return context . Diagnostics . AddError < ( string , string ? ) ? > ( context . SourceFile , context . Info . Span , string . Format ( CliCommandStrings . InvalidDirectiveName , directiveKind , separator ) ) ;
1739
1739
}
1740
1740
1741
1741
var secondPart = i < 0 ? [ ] : context . DirectiveText . AsSpan ( ( i + 1 ) ..) . TrimStart ( ) ;
@@ -1802,7 +1802,7 @@ public sealed class Property(in ParseInfo info) : Named(info)
1802
1802
1803
1803
if ( propertyValue is null )
1804
1804
{
1805
- return context . Diagnostics . AddError < Property ? > ( context . SourceFile , context . Info . Span , static location => string . Format ( CliCommandStrings . PropertyDirectiveMissingParts , location ) ) ;
1805
+ return context . Diagnostics . AddError < Property ? > ( context . SourceFile , context . Info . Span , CliCommandStrings . PropertyDirectiveMissingParts ) ;
1806
1806
}
1807
1807
1808
1808
try
@@ -1811,13 +1811,13 @@ public sealed class Property(in ParseInfo info) : Named(info)
1811
1811
}
1812
1812
catch ( XmlException ex )
1813
1813
{
1814
- return context . Diagnostics . AddError < Property ? > ( context . SourceFile , context . Info . Span , location => string . Format ( CliCommandStrings . PropertyDirectiveInvalidName , location , ex . Message ) , ex ) ;
1814
+ return context . Diagnostics . AddError < Property ? > ( context . SourceFile , context . Info . Span , string . Format ( CliCommandStrings . PropertyDirectiveInvalidName , ex . Message ) , ex ) ;
1815
1815
}
1816
1816
1817
1817
if ( propertyName . Equals ( "RestoreUseStaticGraphEvaluation" , StringComparison . OrdinalIgnoreCase ) &&
1818
1818
MSBuildUtilities . ConvertStringToBool ( propertyValue ) )
1819
1819
{
1820
- context . Diagnostics . AddError ( context . SourceFile , context . Info . Span , static location => string . Format ( CliCommandStrings . StaticGraphRestoreNotSupported , location ) ) ;
1820
+ context . Diagnostics . AddError ( context . SourceFile , context . Info . Span , CliCommandStrings . StaticGraphRestoreNotSupported ) ;
1821
1821
}
1822
1822
1823
1823
return new Property ( context . Info )
@@ -1865,7 +1865,7 @@ public sealed class Project(in ParseInfo info) : Named(info)
1865
1865
if ( directiveText . IsWhiteSpace ( ) )
1866
1866
{
1867
1867
string directiveKind = context . DirectiveKind ;
1868
- return context . Diagnostics . AddError < Project ? > ( context . SourceFile , context . Info . Span , location => string . Format ( CliCommandStrings . MissingDirectiveName , directiveKind , location ) ) ;
1868
+ return context . Diagnostics . AddError < Project ? > ( context . SourceFile , context . Info . Span , string . Format ( CliCommandStrings . MissingDirectiveName , directiveKind ) ) ;
1869
1869
}
1870
1870
1871
1871
try
@@ -1886,7 +1886,7 @@ public sealed class Project(in ParseInfo info) : Named(info)
1886
1886
}
1887
1887
catch ( GracefulException e )
1888
1888
{
1889
- context . Diagnostics . AddError ( context . SourceFile , context . Info . Span , location => string . Format ( CliCommandStrings . InvalidProjectDirective , location , e . Message ) , e ) ;
1889
+ context . Diagnostics . AddError ( context . SourceFile , context . Info . Span , string . Format ( CliCommandStrings . InvalidProjectDirective , e . Message ) , e ) ;
1890
1890
}
1891
1891
1892
1892
return new Project ( context . Info )
@@ -1960,22 +1960,22 @@ internal readonly struct DiagnosticBag
1960
1960
public static DiagnosticBag Collect ( out ImmutableArray < SimpleDiagnostic > . Builder builder ) => new ( ) { Builder = builder = ImmutableArray . CreateBuilder < SimpleDiagnostic > ( ) } ;
1961
1961
public static DiagnosticBag Ignore ( ) => new ( ) { IgnoreDiagnostics = true , Builder = null } ;
1962
1962
1963
- public void AddError ( SourceFile sourceFile , TextSpan span , Func < string , string > messageFactory , Exception ? inner = null )
1963
+ public void AddError ( SourceFile sourceFile , TextSpan span , string message , Exception ? inner = null )
1964
1964
{
1965
1965
if ( Builder != null )
1966
1966
{
1967
1967
Debug . Assert ( ! IgnoreDiagnostics ) ;
1968
- Builder . Add ( new SimpleDiagnostic { Location = sourceFile . GetFileLinePositionSpan ( span ) , Message = messageFactory ( sourceFile . GetLocationString ( span ) ) } ) ;
1968
+ Builder . Add ( new SimpleDiagnostic { Location = sourceFile . GetFileLinePositionSpan ( span ) , Message = message } ) ;
1969
1969
}
1970
1970
else if ( ! IgnoreDiagnostics )
1971
1971
{
1972
- throw new GracefulException ( messageFactory ( sourceFile . GetLocationString ( span ) ) , inner ) ;
1972
+ throw new GracefulException ( $ " { sourceFile . GetLocationString ( span ) } : { CliCommandStrings . DirectiveError } : { message } " , inner ) ;
1973
1973
}
1974
1974
}
1975
1975
1976
- public T ? AddError < T > ( SourceFile sourceFile , TextSpan span , Func < string , string > messageFactory , Exception ? inner = null )
1976
+ public T ? AddError < T > ( SourceFile sourceFile , TextSpan span , string message , Exception ? inner = null )
1977
1977
{
1978
- AddError ( sourceFile , span , messageFactory , inner ) ;
1978
+ AddError ( sourceFile , span , message , inner ) ;
1979
1979
return default ;
1980
1980
}
1981
1981
}
0 commit comments