Skip to content

Commit 7e84513

Browse files
authored
remove TokenCompletionContext, make CompletionContext non-abstract (#2126)
1 parent 4ba4a28 commit 7e84513

File tree

5 files changed

+9
-20
lines changed

5 files changed

+9
-20
lines changed

src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ System.CommandLine
158158
public System.Boolean Equals(System.Object obj)
159159
public System.Int32 GetHashCode()
160160
System.CommandLine.Completions
161-
public abstract class CompletionContext
161+
public class CompletionContext
162162
public static CompletionContext Empty { get; }
163163
public System.CommandLine.ParseResult ParseResult { get; }
164164
public System.String WordToComplete { get; }
@@ -178,7 +178,6 @@ System.CommandLine.Completions
178178
public System.String CommandLineText { get; }
179179
public System.Int32 CursorPosition { get; }
180180
public TextCompletionContext AtCursorPosition(System.Int32 position)
181-
public class TokenCompletionContext : CompletionContext
182181
System.CommandLine.Help
183182
public class HelpAction : System.CommandLine.CliAction
184183
.ctor()

src/System.CommandLine.Tests/CompletionContextTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void CommandLineText_is_unavailable_when_string_array_is_parsed()
6868

6969
parseResult.GetCompletionContext()
7070
.Should()
71-
.BeOfType<TokenCompletionContext>();
71+
.BeOfType<CompletionContext>();
7272
}
7373

7474
[Fact]

src/System.CommandLine/Completions/CompletionContext.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ namespace System.CommandLine.Completions
99
/// <summary>
1010
/// Supports command line completion operations.
1111
/// </summary>
12-
public abstract class CompletionContext
12+
public class CompletionContext
1313
{
1414
private static CompletionContext? _empty;
1515

16+
internal CompletionContext(ParseResult parseResult) : this(parseResult, GetWordToComplete(parseResult))
17+
{
18+
}
19+
1620
internal CompletionContext(ParseResult parseResult, string wordToComplete)
1721
{
1822
ParseResult = parseResult;
@@ -29,7 +33,7 @@ internal CompletionContext(ParseResult parseResult, string wordToComplete)
2933
/// Gets an empty CompletionContext.
3034
/// </summary>
3135
/// <remarks>Can be used for testing purposes.</remarks>
32-
public static CompletionContext Empty => _empty ??= new TokenCompletionContext(ParseResult.Empty());
36+
public static CompletionContext Empty => _empty ??= new CompletionContext(ParseResult.Empty());
3337

3438
internal bool IsEmpty => ReferenceEquals(this, _empty);
3539

src/System.CommandLine/Completions/TokenCompletionContext.cs

-14
This file was deleted.

src/System.CommandLine/ParseResult.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public string[] UnmatchedTokens
103103
public CompletionContext GetCompletionContext() =>
104104
_completionContext ??=
105105
CommandLineText is null
106-
? new TokenCompletionContext(this)
106+
? new CompletionContext(this)
107107
: new TextCompletionContext(this, CommandLineText);
108108

109109
/// <summary>

0 commit comments

Comments
 (0)