Skip to content

introduce CompletionContext.Empty, remove Symbol.GetCompletions(void) #1954

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 4 commits into from
Dec 14, 2022

Conversation

adamsitnik
Copy link
Member

@adamsitnik adamsitnik commented Nov 8, 2022

introduce static CompletionContext.Empty:

  • cache it so it does not get created more than once
  • make it public so it can be reused by our users who write tests (API review issues #1891 (comment))
  • use it places where it can improve performance (including benchmarks, which should not include this allocation as this is not what they are supposed to benchmark)

remove Symbol.GetCompletions(void): mostly to simplify Symbol

@jonsequitur if we don't want to delete Symbol.GetCompletions(void) we should keep caching the empty completion context (perf gains in HelpBuilder and ParseResultVisitor)

* cache it so it does not get created more than once
* make it public so it can be reused by our users who write tests
* use it places where it can improve performance (including benchmarks, which should not include this allocation)
@adamsitnik adamsitnik mentioned this pull request Nov 8, 2022
56 tasks
Comment on lines 66 to 73
string firstColumn;
var completions = (argument is { } a
? a.GetCompletions()
: Array.Empty<CompletionItem>())
.Select(item => item.Label)
.ToArray();
var completions = argument
.GetCompletions(CompletionContext.Empty)
.Select(item => item.Label)
.ToArray();

var arg = argument;
var helpName = arg?.HelpName ?? string.Empty;
Copy link

@KalleOlaviNiemitalo KalleOlaviNiemitalo Nov 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a performance issue dotnet/sdk#27374 (comment) for this method; not changed in this PR, but maybe you'd like to tackle that too.

Filed as #2038.

Copy link
Member

@jozkee jozkee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we don't want to delete Symbol.GetCompletions(void) we should keep caching the empty completion context (perf gains in HelpBuilder and ParseResultVisitor)

+1 to not deleting Symbol.GetCompletions(). Otherwise; LGTM.

Comment on lines -83 to -84
public IEnumerable<CompletionItem> GetCompletions() =>
GetCompletions(CompletionContext.Empty());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like an unnecessary breaking change to me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like an unnecessary breaking change to me.

The main point of my changes is simplification of the APIs which should help us get them approved and moved into BCL.

One of the users raised a concern about removing this method: #1891 (comment) but by exposing CompletionContext.Empty we are going to make it testable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok that's fair, if is proven later on that this method is valuable, we can bring it back.

@adamsitnik adamsitnik merged commit 4a82c9e into dotnet:main Dec 14, 2022
@adamsitnik adamsitnik deleted the GetCompletionsNoArgs branch December 14, 2022 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants