roslyn
roslyn copied to clipboard
VS 16.1.6 - Collection Initializer Comment Bug
This issue has been moved from a ticket on Developer Community.
Autocomplete interferes when I try to type a space then a comment on a collection initializer line.
e.g. I'm expecting to get [new Version(1, 1)] = new Version(2, 3, 4, 0), /
but instead I get [new Version(1, 1)] = new Version(2, 3, 4, 0), Version/
Here is a code sample:
using System;
using System.Collections.Generic;
namespace Collection_Initializer_Comment_Bug
{
public static class C
{
public static readonly Dictionary<Version, Version> TestDictionary = new Dictionary<Version, Version>
{
[new Version(1, 0)] = new Version(1, 2, 3, 0), // Test comment
[new Version(1, 1)] = new Version(2, 3, 4, 0),
};
}
}
See attached screenshot.
Original Comments
Visual Studio Feedback System on 8/15/2019, 07:50 PM:
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.
Original Solutions
(no solutions)
/cc @ivanbasov
Reproduced. Interesting issue:
/is a commit character.- When typing space in the collection initializer, there is a completion session to add a new element (
Versionin the example) - When we press
/with the active completion session, we commit the active completion item.
Yes, the question is is there a valid scenario where typing Version was desired here rather than [ ... which I assume is a commit character too.
Thank you, @miloush !
I think we should implement something like this:
- if the completion trigger is space (user may or may not want to trigger completion with it) and
- if the commit character is not Enter, Tab or space and
- if the committing item does not start with the commit character then cancel the commit.
@sharwell and @CyrusNajmabadi , what do you think?
That doesn't seem to be a very consistent experience to me. I was trying to suggest that perhaps there shouldn't be anything at all in the autocompletion list when typing the key part of a dictionary initializer?
Unless the idea here is to correct this for all collection initializers, not just dictionary, in which case I don't think the existing behaviour should be changed because the autocompletion is a valid entry:
const int Value = 4;
List<int> list = new List<int>
{
Value,|
}
You should be able to type a space and slash and get Value/ if you wanted to write e.g.
Value, Value / 2, Value / 4
EDIT: Okay that actually doesn't work with ints, but you get the idea of my concern.
Doesn't repro. After the space i get:

Then after teh / i get:

Which all seems to be working as expected.