-
Notifications
You must be signed in to change notification settings - Fork 383
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get rid of compile error and clean up some docs File scoped namespace Reverting whitespace changes Adding link Removing out-dated TODO Additional review feedback Adding additional reference link
- Loading branch information
1 parent
d25d2da
commit 05bd9eb
Showing
10 changed files
with
198 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Collections.Immutable; | ||
|
||
namespace System.CommandLine.Parsing; | ||
|
||
/* | ||
* Pattern based on: | ||
* https://github.com/mhutch/MonoDevelop.MSBuildEditor/blob/main/MonoDevelop.MSBuild/Analysis/MSBuildDiagnostic.cs | ||
* https://github.com/mhutch/MonoDevelop.MSBuildEditor/blob/main/MonoDevelop.MSBuild/Analysis/MSBuildDiagnosticDescriptor.cs | ||
* https://github.com/dotnet/roslyn/blob/main/src/Compilers/Core/Portable/Diagnostic/DiagnosticDescriptor.cs | ||
* https://github.com/dotnet/roslyn/blob/main/src/Compilers/Core/Portable/Diagnostic/Diagnostic.cs | ||
*/ | ||
internal static class ParseDiagnostics | ||
{ | ||
public const string DirectiveIsNotDefinedId = "CMD0001"; | ||
public static readonly CliDiagnosticDescriptor DirectiveIsNotDefined = | ||
new( | ||
DirectiveIsNotDefinedId, | ||
//TODO: use localized strings | ||
"Directive is not defined", | ||
"The directive '{0}' is not defined.", | ||
CliDiagnosticSeverity.Error, | ||
null); | ||
} | ||
|
||
public sealed class CliDiagnosticDescriptor | ||
{ | ||
public CliDiagnosticDescriptor(string id, string title, string messageFormat, CliDiagnosticSeverity severity, string? helpUri) | ||
{ | ||
Id = id; | ||
Title = title; | ||
MessageFormat = messageFormat; | ||
Severity = severity; | ||
HelpUri = helpUri; | ||
} | ||
|
||
public string Id { get; } | ||
public string Title { get; } | ||
public string MessageFormat { get; } | ||
public CliDiagnosticSeverity Severity { get; } | ||
public string? HelpUri { get; } | ||
} | ||
|
||
public enum CliDiagnosticSeverity | ||
{ | ||
Hidden = 0, | ||
Info, | ||
Warning, | ||
Error | ||
} | ||
|
||
/// <summary> | ||
/// Describes an error that occurs while parsing command line input. | ||
/// </summary> | ||
public sealed class CliDiagnostic | ||
{ | ||
// TODO: reevaluate whether we should be exposing a SymbolResult here | ||
// TODO: Rename to CliError | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="CliDiagnostic"/> class. | ||
/// </summary> | ||
/// <param name="descriptor">Contains information about the error.</param> | ||
/// <param name="messageArgs">The arguments to be passed to the <see cref="CliDiagnosticDescriptor.MessageFormat"/> in the <paramref name="descriptor"/>.</param> | ||
/// <param name="properties">Properties to be associated with the diagnostic.</param> | ||
/// <param name="symbolResult">The symbol result detailing the symbol that failed to parse and the tokens involved.</param> | ||
/// <param name="location">The location of the error.</param> | ||
public CliDiagnostic( | ||
CliDiagnosticDescriptor descriptor, | ||
object?[]? messageArgs, | ||
ImmutableDictionary<string, object>? properties = null, | ||
SymbolResult? symbolResult = null, | ||
Location? location = null) | ||
{ | ||
Descriptor = descriptor; | ||
MessageArgs = messageArgs; | ||
Properties = properties; | ||
SymbolResult = symbolResult; | ||
} | ||
|
||
/// <summary> | ||
/// Gets a message to explain the error to a user. | ||
/// </summary> | ||
public string Message | ||
{ | ||
get | ||
{ | ||
if (MessageArgs is not null) | ||
{ | ||
return string.Format(Descriptor.MessageFormat, MessageArgs); | ||
} | ||
return Descriptor.MessageFormat; | ||
} | ||
} | ||
|
||
public ImmutableDictionary<string, object>? Properties { get; } | ||
|
||
public CliDiagnosticDescriptor Descriptor { get; } | ||
|
||
public object?[]? MessageArgs { get; } | ||
|
||
/// <summary> | ||
/// Gets the symbol result detailing the symbol that failed to parse and the tokens involved. | ||
/// </summary> | ||
public SymbolResult? SymbolResult { get; } | ||
|
||
/// <inheritdoc /> | ||
public override string ToString() => Message; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.