diff --git a/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt b/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt index 7ad424075e..51160a2a33 100644 --- a/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt +++ b/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt @@ -158,7 +158,7 @@ System.CommandLine public System.Boolean Equals(System.Object obj) public System.Int32 GetHashCode() System.CommandLine.Completions - public abstract class CompletionContext + public class CompletionContext public static CompletionContext Empty { get; } public System.CommandLine.ParseResult ParseResult { get; } public System.String WordToComplete { get; } @@ -178,7 +178,6 @@ System.CommandLine.Completions public System.String CommandLineText { get; } public System.Int32 CursorPosition { get; } public TextCompletionContext AtCursorPosition(System.Int32 position) - public class TokenCompletionContext : CompletionContext System.CommandLine.Help public class HelpAction : System.CommandLine.CliAction .ctor() diff --git a/src/System.CommandLine.Tests/CompletionContextTests.cs b/src/System.CommandLine.Tests/CompletionContextTests.cs index e843bcd677..09d805d6e1 100644 --- a/src/System.CommandLine.Tests/CompletionContextTests.cs +++ b/src/System.CommandLine.Tests/CompletionContextTests.cs @@ -68,7 +68,7 @@ public void CommandLineText_is_unavailable_when_string_array_is_parsed() parseResult.GetCompletionContext() .Should() - .BeOfType(); + .BeOfType(); } [Fact] diff --git a/src/System.CommandLine/Completions/CompletionContext.cs b/src/System.CommandLine/Completions/CompletionContext.cs index fb7d25a63a..6fb201a0ef 100644 --- a/src/System.CommandLine/Completions/CompletionContext.cs +++ b/src/System.CommandLine/Completions/CompletionContext.cs @@ -9,10 +9,14 @@ namespace System.CommandLine.Completions /// /// Supports command line completion operations. /// - public abstract class CompletionContext + public class CompletionContext { private static CompletionContext? _empty; + internal CompletionContext(ParseResult parseResult) : this(parseResult, GetWordToComplete(parseResult)) + { + } + internal CompletionContext(ParseResult parseResult, string wordToComplete) { ParseResult = parseResult; @@ -29,7 +33,7 @@ internal CompletionContext(ParseResult parseResult, string wordToComplete) /// Gets an empty CompletionContext. /// /// Can be used for testing purposes. - public static CompletionContext Empty => _empty ??= new TokenCompletionContext(ParseResult.Empty()); + public static CompletionContext Empty => _empty ??= new CompletionContext(ParseResult.Empty()); internal bool IsEmpty => ReferenceEquals(this, _empty); diff --git a/src/System.CommandLine/Completions/TokenCompletionContext.cs b/src/System.CommandLine/Completions/TokenCompletionContext.cs deleted file mode 100644 index 17e07fccd6..0000000000 --- a/src/System.CommandLine/Completions/TokenCompletionContext.cs +++ /dev/null @@ -1,14 +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; - -/// -/// Provides details for getting completions when the complete text of the original command line is not available. -/// -public class TokenCompletionContext : CompletionContext -{ - internal TokenCompletionContext(ParseResult parseResult) : base(parseResult, GetWordToComplete(parseResult)) - { - } -} \ No newline at end of file diff --git a/src/System.CommandLine/ParseResult.cs b/src/System.CommandLine/ParseResult.cs index 8dff241ee8..5d3fdd27ad 100644 --- a/src/System.CommandLine/ParseResult.cs +++ b/src/System.CommandLine/ParseResult.cs @@ -103,7 +103,7 @@ public string[] UnmatchedTokens public CompletionContext GetCompletionContext() => _completionContext ??= CommandLineText is null - ? new TokenCompletionContext(this) + ? new CompletionContext(this) : new TextCompletionContext(this, CommandLineText); ///