Skip to content

Commit bf523f8

Browse files
authored
Types cleanup (#2076)
* remove ServiceProviderExtensions (an empty class) * remove CompletionItemKind, merge it's two fields into CompletionItem TYPE * remove unused types * merge Platform class into ConsoleExtensions, as it's the only user of that API
1 parent febc391 commit bf523f8

File tree

8 files changed

+35
-123
lines changed

8 files changed

+35
-123
lines changed

src/System.CommandLine/Binding/ServiceProviderExtensions.cs

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/System.CommandLine/Command.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ void AddCompletionsFor(Symbol identifier, AliasSet? aliases)
234234
{
235235
if (identifier.Name.ContainsCaseInsensitive(textToMatch))
236236
{
237-
completions.Add(new CompletionItem(identifier.Name, CompletionItemKind.Keyword, detail: identifier.Description));
237+
completions.Add(new CompletionItem(identifier.Name, CompletionItem.KindKeyword, detail: identifier.Description));
238238
}
239239

240240
if (aliases is not null)
@@ -243,7 +243,7 @@ void AddCompletionsFor(Symbol identifier, AliasSet? aliases)
243243
{
244244
if (alias.ContainsCaseInsensitive(textToMatch))
245245
{
246-
completions.Add(new CompletionItem(alias, CompletionItemKind.Keyword, detail: identifier.Description));
246+
completions.Add(new CompletionItem(alias, CompletionItem.KindKeyword, detail: identifier.Description));
247247
}
248248
}
249249
}

src/System.CommandLine/Completions/CompletionItem.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ namespace System.CommandLine.Completions
88
/// </summary>
99
public class CompletionItem : IEquatable<CompletionItem>
1010
{
11+
// reference: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_completion
12+
internal const string KindKeyword = "Keyword";
13+
internal const string KindValue = "Value";
14+
1115
/// <param name="label">The label value, which is the text displayed to users and, unless <paramref name="insertText"/> is set, is also used to populate the <see cref="InsertText"/> property.</param>
1216
/// <param name="kind">The kind of completion item.</param>
1317
/// <param name="sortText">The value used to sort the completion item in a list. If this is not provided, then <paramref name="label"/> is used.</param>
@@ -16,7 +20,7 @@ public class CompletionItem : IEquatable<CompletionItem>
1620
/// <param name="detail">Additional details regarding the completion item.</param>
1721
public CompletionItem(
1822
string label,
19-
string kind = CompletionItemKind.Value,
23+
string kind = CompletionItem.KindValue,
2024
string? sortText = null,
2125
string? insertText = null,
2226
string? documentation = null,

src/System.CommandLine/Completions/CompletionItemKind.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/System.CommandLine/DebugAssert.cs

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/System.CommandLine/DictionaryExtensions.cs

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/System.CommandLine/IO/ConsoleExtensions.cs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,51 @@ namespace System.CommandLine.IO
55
{
66
internal static class ConsoleExtensions
77
{
8+
private static bool? _isConsoleRedirectionCheckSupported;
9+
10+
private static bool IsConsoleRedirectionCheckSupported
11+
{
12+
get
13+
{
14+
if (_isConsoleRedirectionCheckSupported is null)
15+
{
16+
try
17+
{
18+
var check = Console.IsOutputRedirected;
19+
_isConsoleRedirectionCheckSupported = true;
20+
}
21+
22+
catch (PlatformNotSupportedException)
23+
{
24+
_isConsoleRedirectionCheckSupported = false;
25+
}
26+
}
27+
28+
return _isConsoleRedirectionCheckSupported.Value;
29+
}
30+
}
31+
832
internal static void SetTerminalForegroundRed(this IConsole console)
933
{
10-
if (Platform.IsConsoleRedirectionCheckSupported &&
34+
if (IsConsoleRedirectionCheckSupported &&
1135
!Console.IsOutputRedirected)
1236
{
1337
Console.ForegroundColor = ConsoleColor.Red;
1438
}
15-
else if (Platform.IsConsoleRedirectionCheckSupported)
39+
else if (IsConsoleRedirectionCheckSupported)
1640
{
1741
Console.ForegroundColor = ConsoleColor.Red;
1842
}
1943
}
2044

2145
internal static void ResetTerminalForegroundColor(this IConsole console)
2246
{
23-
if (Platform.IsConsoleRedirectionCheckSupported &&
47+
if (IsConsoleRedirectionCheckSupported &&
2448
!Console.IsOutputRedirected)
2549
{
2650
Console.ResetColor();
2751
}
28-
else if (Platform.IsConsoleRedirectionCheckSupported)
52+
else if (IsConsoleRedirectionCheckSupported)
2953
{
3054
Console.ResetColor();
3155
}

src/System.CommandLine/Platform.cs

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)