diff --git a/src/System.CommandLine/Binding/ServiceProviderExtensions.cs b/src/System.CommandLine/Binding/ServiceProviderExtensions.cs deleted file mode 100644 index a5b054e5c9..0000000000 --- a/src/System.CommandLine/Binding/ServiceProviderExtensions.cs +++ /dev/null @@ -1,8 +0,0 @@ -// 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. - -namespace System.CommandLine.Binding; - -internal static class ServiceProviderExtensions -{ -} \ No newline at end of file diff --git a/src/System.CommandLine/Command.cs b/src/System.CommandLine/Command.cs index 94a6427b7d..753d5938c1 100644 --- a/src/System.CommandLine/Command.cs +++ b/src/System.CommandLine/Command.cs @@ -234,7 +234,7 @@ void AddCompletionsFor(Symbol identifier, AliasSet? aliases) { if (identifier.Name.ContainsCaseInsensitive(textToMatch)) { - completions.Add(new CompletionItem(identifier.Name, CompletionItemKind.Keyword, detail: identifier.Description)); + completions.Add(new CompletionItem(identifier.Name, CompletionItem.KindKeyword, detail: identifier.Description)); } if (aliases is not null) @@ -243,7 +243,7 @@ void AddCompletionsFor(Symbol identifier, AliasSet? aliases) { if (alias.ContainsCaseInsensitive(textToMatch)) { - completions.Add(new CompletionItem(alias, CompletionItemKind.Keyword, detail: identifier.Description)); + completions.Add(new CompletionItem(alias, CompletionItem.KindKeyword, detail: identifier.Description)); } } } diff --git a/src/System.CommandLine/Completions/CompletionItem.cs b/src/System.CommandLine/Completions/CompletionItem.cs index 87fe3e4443..bbc3d987f2 100644 --- a/src/System.CommandLine/Completions/CompletionItem.cs +++ b/src/System.CommandLine/Completions/CompletionItem.cs @@ -8,6 +8,10 @@ namespace System.CommandLine.Completions /// public class CompletionItem : IEquatable { + // reference: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_completion + internal const string KindKeyword = "Keyword"; + internal const string KindValue = "Value"; + /// The label value, which is the text displayed to users and, unless is set, is also used to populate the property. /// The kind of completion item. /// The value used to sort the completion item in a list. If this is not provided, then is used. @@ -16,7 +20,7 @@ public class CompletionItem : IEquatable /// Additional details regarding the completion item. public CompletionItem( string label, - string kind = CompletionItemKind.Value, + string kind = CompletionItem.KindValue, string? sortText = null, string? insertText = null, string? documentation = null, diff --git a/src/System.CommandLine/Completions/CompletionItemKind.cs b/src/System.CommandLine/Completions/CompletionItemKind.cs deleted file mode 100644 index 6eb973d821..0000000000 --- a/src/System.CommandLine/Completions/CompletionItemKind.cs +++ /dev/null @@ -1,12 +0,0 @@ -// 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. - -namespace System.CommandLine.Completions -{ - internal static class CompletionItemKind - { - // reference: https://microsoft.github.io/language-server-protocol/specifications/specification-3-17/#textDocument_completion - public const string Keyword = nameof(Keyword); - public const string Value = nameof(Value); - } -} \ No newline at end of file diff --git a/src/System.CommandLine/DebugAssert.cs b/src/System.CommandLine/DebugAssert.cs deleted file mode 100644 index 0ba2feffc7..0000000000 --- a/src/System.CommandLine/DebugAssert.cs +++ /dev/null @@ -1,25 +0,0 @@ -// 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.Diagnostics; - -namespace System.CommandLine -{ - internal static class DebugAssert - { - [Conditional("DEBUG")] - public static void ThrowIf(bool condition, string message) - { - if (condition) - { - Throw(message); - } - } - - [Conditional("DEBUG")] - public static void Throw(string message) - { - throw new Exception(message); - } - } -} \ No newline at end of file diff --git a/src/System.CommandLine/DictionaryExtensions.cs b/src/System.CommandLine/DictionaryExtensions.cs deleted file mode 100644 index ba4e4d7ac3..0000000000 --- a/src/System.CommandLine/DictionaryExtensions.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System.Collections.Generic; - -namespace System.CommandLine -{ - internal static class DictionaryExtensions - { - public static TValue GetOrAdd( - this IDictionary source, - TKey key, - Func create) - { - if (source.TryGetValue(key, out TValue? value)) - { - return value; - } - else - { - value = create(key); - - source.Add(key, value); - - return value; - } - } - - public static bool TryAdd( - this IDictionary source, - TKey key, - TValue value) - { - if (source.ContainsKey(key)) - { - return false; - } - else - { - source.Add(key, value); - return true; - } - } - } -} \ No newline at end of file diff --git a/src/System.CommandLine/IO/ConsoleExtensions.cs b/src/System.CommandLine/IO/ConsoleExtensions.cs index 10c91c00db..7ec5ab26b4 100644 --- a/src/System.CommandLine/IO/ConsoleExtensions.cs +++ b/src/System.CommandLine/IO/ConsoleExtensions.cs @@ -5,14 +5,38 @@ namespace System.CommandLine.IO { internal static class ConsoleExtensions { + private static bool? _isConsoleRedirectionCheckSupported; + + private static bool IsConsoleRedirectionCheckSupported + { + get + { + if (_isConsoleRedirectionCheckSupported is null) + { + try + { + var check = Console.IsOutputRedirected; + _isConsoleRedirectionCheckSupported = true; + } + + catch (PlatformNotSupportedException) + { + _isConsoleRedirectionCheckSupported = false; + } + } + + return _isConsoleRedirectionCheckSupported.Value; + } + } + internal static void SetTerminalForegroundRed(this IConsole console) { - if (Platform.IsConsoleRedirectionCheckSupported && + if (IsConsoleRedirectionCheckSupported && !Console.IsOutputRedirected) { Console.ForegroundColor = ConsoleColor.Red; } - else if (Platform.IsConsoleRedirectionCheckSupported) + else if (IsConsoleRedirectionCheckSupported) { Console.ForegroundColor = ConsoleColor.Red; } @@ -20,12 +44,12 @@ internal static void SetTerminalForegroundRed(this IConsole console) internal static void ResetTerminalForegroundColor(this IConsole console) { - if (Platform.IsConsoleRedirectionCheckSupported && + if (IsConsoleRedirectionCheckSupported && !Console.IsOutputRedirected) { Console.ResetColor(); } - else if (Platform.IsConsoleRedirectionCheckSupported) + else if (IsConsoleRedirectionCheckSupported) { Console.ResetColor(); } diff --git a/src/System.CommandLine/Platform.cs b/src/System.CommandLine/Platform.cs deleted file mode 100644 index 742895eb70..0000000000 --- a/src/System.CommandLine/Platform.cs +++ /dev/null @@ -1,29 +0,0 @@ -namespace System.CommandLine -{ - internal static class Platform - { - private static bool? _isConsoleRedirectionCheckSupported; - - public static bool IsConsoleRedirectionCheckSupported - { - get - { - if (_isConsoleRedirectionCheckSupported is null) - { - try - { - var check = Console.IsOutputRedirected; - _isConsoleRedirectionCheckSupported = true; - } - - catch (PlatformNotSupportedException) - { - _isConsoleRedirectionCheckSupported = false; - } - } - - return _isConsoleRedirectionCheckSupported.Value; - } - } - } -}