Skip to content

remove TokenCompletionContext, make CompletionContext non-abstract #2126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/System.CommandLine.Tests/CompletionContextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void CommandLineText_is_unavailable_when_string_array_is_parsed()

parseResult.GetCompletionContext()
.Should()
.BeOfType<TokenCompletionContext>();
.BeOfType<CompletionContext>();
}

[Fact]
Expand Down
8 changes: 6 additions & 2 deletions src/System.CommandLine/Completions/CompletionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ namespace System.CommandLine.Completions
/// <summary>
/// Supports command line completion operations.
/// </summary>
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;
Expand All @@ -29,7 +33,7 @@ internal CompletionContext(ParseResult parseResult, string wordToComplete)
/// Gets an empty CompletionContext.
/// </summary>
/// <remarks>Can be used for testing purposes.</remarks>
public static CompletionContext Empty => _empty ??= new TokenCompletionContext(ParseResult.Empty());
public static CompletionContext Empty => _empty ??= new CompletionContext(ParseResult.Empty());

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

Expand Down
14 changes: 0 additions & 14 deletions src/System.CommandLine/Completions/TokenCompletionContext.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/System.CommandLine/ParseResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public string[] UnmatchedTokens
public CompletionContext GetCompletionContext() =>
_completionContext ??=
CommandLineText is null
? new TokenCompletionContext(this)
? new CompletionContext(this)
: new TextCompletionContext(this, CommandLineText);

/// <summary>
Expand Down