Skip to content

Conversation

@adamsitnik
Copy link
Member

My proposal for fixing #1884: use the default completions only when user has not provided their own.

Cons: we lose the possibility to extend the default completions with custom ones.

fixes #1884

cc @KalleOlaviNiemitalo

{
CompletionSource.ForType(ValueType)
};
public ICollection<ICompletionSource> Completions => _completions ??= new();

Choose a reason for hiding this comment

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

Huh, so if I read this property, then the getter assigns an empty collection to _completions, and after that, GetCompletions will no longer use the default completions. It seems wrong that the getter would have a side effect like that.

@jonsequitur
Copy link
Contributor

The behavior seems unintuitive. If I know for example that Option<DayOfWeek> returns seven well-known values, I would not expect calling Completions.Add to replace them.

@KalleOlaviNiemitalo
Copy link

For the DayOfWeek case, although adding more completions to the seven original seems a bit odd, I can imagine adding "today", "tomorrow", "yesterday" with a custom parser.

@jozkee
Copy link
Member

jozkee commented Nov 17, 2022

If I know for example that Option returns seven well-known values, I would not expect calling Completions.Add to replace them.

That's what @KalleOlaviNiemitalo describes as expected in the linked issue. I was first thinking that a possibility could be to only use defaults as long as users don't Add their own completions.

If that's not good, we could also just expose a method to Clear() the completions, or AddReplace()?

@KalleOlaviNiemitalo
Copy link

If you add public ICollection<Func<CompletionContext, IEnumerable<CompletionItem>>> Completions => Argument.Completions; to Option so that I can call ICollection<T>.Clear(), that will suffice.

@adamsitnik
Copy link
Member Author

I've opened #1972 to discuss better solution. Thank you all for your feedback!

@adamsitnik adamsitnik closed this Nov 17, 2022
@adamsitnik adamsitnik deleted the defaultCompletions branch November 17, 2022 15:32
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.

Cannot replace default completions of Option<T> where T is enum

4 participants