dotnet/roslyn

Invalid formatting of `#If` directive in VB

Open

#50,117 opened on Dec 23, 2020

View on GitHub
 (3 comments) (0 reactions) (0 assignees)C# (4,257 forks)batch import
Area-IDEConcept-Continuous ImprovementIDE-FormatterLanguage-VBhelp wanted

Repository metrics

Stars
 (20,414 stars)
PR merge metrics
 (Avg merge 6d 17h) (256 merged PRs in 30d)

Description

Paste the following code in VB type.

        /// <summary>
        /// Generate a list containing the given field and all dependencies
        /// of that field that require evaluation. The list is ordered by
        /// dependencies, with fields with no dependencies first. Cycles are
        /// broken at the first field lexically in the cycle. If multiple threads
        /// call this method with the same field, the order of the fields
        /// returned should be the same, although some fields may be missing
        /// from the lists in some threads as other threads evaluate fields.
        /// </summary>
        internal static void OrderAllDependencies(
            this SourceFieldSymbolWithSyntaxReference field,
            ArrayBuilder<FieldInfo> order,
            bool earlyDecodingWellKnownAttributes)
        {
            Debug.Assert(order.Count == 0);

            var graph = PooledDictionary<SourceFieldSymbolWithSyntaxReference, Node<SourceFieldSymbolWithSyntaxReference>>.GetInstance();

            CreateGraph(graph, field, earlyDecodingWellKnownAttributes);

            Debug.Assert(graph.Count >= 1);
            CheckGraph(graph);

#if DEBUG
            var fields = ArrayBuilder<SourceFieldSymbolWithSyntaxReference>.GetInstance();
            fields.AddRange(graph.Keys);
#endif

            OrderGraph(graph, order);

#if DEBUG
            // Verify all entries in the graph are in the ordered list.
            var map = new HashSet<SourceFieldSymbolWithSyntaxReference>(order.Select(o => o.Field).Distinct());
            Debug.Assert(fields.All(f => map.Contains(f)));
            fields.Free();
#endif

            graph.Free();
        }

Observed:

        /// <summary>
        /// Generate a list containing the given field And all dependencies
        /// of that field that require evaluation. The list Is ordered by
        /// dependencies, with fields with no dependencies first. Cycles are
        /// broken at the first field lexically in the cycle. If multiple threads
        /// call this method with the same field, the order of the fields
        /// returned should be the same, although some fields may be missing
        /// from the lists in some threads as other threads evaluate fields.
        /// </summary>
        internal Static void OrderAllDependencies(
            this SourceFieldSymbolWithSyntaxReference field,
            ArrayBuilder<FieldInfo> order,
            bool earlyDecodingWellKnownAttributes)
        {
            Debug.Assert(order.Count == 0);

            var graph = PooledDictionary < SourceFieldSymbolWithSyntaxReference, Node<SourceFieldSymbolWithSyntaxReference>>.GetInstance();

            CreateGraph(graph, field, earlyDecodingWellKnownAttributes);

            Debug.Assert(graph.Count >= 1);
            CheckGraph(graph);

#If DEBUGThen
            var fields = ArrayBuilder < SourceFieldSymbolWithSyntaxReference > .GetInstance();
            fields.AddRange(graph.Keys);
#End If

            OrderGraph(graph, order);

#if DEBUGThen
            // Verify all entries in the graph are in the ordered list.
            var map = New HashSet < SourceFieldSymbolWithSyntaxReference > (order.Select(o >= o.Field).Distinct());
            Debug.Assert(fields.All(f => map.Contains(f)));
            fields.Free();
#End If

            graph.Free();
        }

Note, conditional compilation directive is changed to #if DEBUGThen. Expected #if DEBUG Then.

Also, if I position the cursor at the end of #if DEBUGThen and press enter, the result is the following:

#If DEBUGThenThen

#End If

The space is missing and #End If is added. This is unexpected, #End If is already present and shouldn't be added.

Contributor guide