roslyn icon indicating copy to clipboard operation
roslyn copied to clipboard

VS 16.1.6 - Collection Initializer Comment Bug

Open vsfeedback opened this issue 6 years ago • 6 comments

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)

vsfeedback avatar Aug 16 '19 23:08 vsfeedback

/cc @ivanbasov

sharwell avatar Aug 17 '19 05:08 sharwell

Reproduced. Interesting issue:

  1. / is a commit character.
  2. When typing space in the collection initializer, there is a completion session to add a new element (Version in the example)
  3. When we press / with the active completion session, we commit the active completion item.

ivanbasov avatar Aug 19 '19 23:08 ivanbasov

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.

miloush avatar Aug 19 '19 23:08 miloush

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?

ivanbasov avatar Aug 22 '19 18:08 ivanbasov

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?

miloush avatar Aug 22 '19 18:08 miloush

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.

miloush avatar Aug 22 '19 19:08 miloush

Doesn't repro. After the space i get:

image

Then after teh / i get:

image

Which all seems to be working as expected.

CyrusNajmabadi avatar Feb 14 '23 01:02 CyrusNajmabadi