dotnet/roslyn

Workspace update disregards indentation settings in VB

Open

#77,366 opened on 2025年2月27日

GitHub で見る
 (0 comments) (1 reaction) (0 assignees)C# (4,257 forks)batch import
Area-IDEhelp wanted

Repository metrics

Stars
 (20,414 stars)
PR merge metrics
 (平均マージ 6d 17h) (30d で 256 merged PRs)

説明

Version Used:

Latest internal preview.

Steps to Reproduce:

This happens inside of the OOP-WinForms Designer, when we're writing the Designer code for InitializeComponent. It should repo though in other scenarios, which take the current VS settings for indentation (Tab/Spaces, etc.) into account.

  1. Set the indentation setting for Visual Basic projects to any other value than 4 (best for both spaces and tabs differently, for easier verification.)
  2. Generate some code VB code with structures, so indentation would come into play. Make sure, you generate nested structures with more than 2 lines code for each nested indention level!
  3. Make sure, the formatting based on the options has been applied correctly, like this:
          DocumentOptionSet docOptions = await document.GetOptionsAsync();
   .
   .
   .
          newRoot = noFormatterRoot.ReplaceNodes(
                nodes: noFormatterRoot.DescendantNodes(),
                computeReplacementNode: (original, rewritten) => rewritten.WithAdditionalAnnotations(formatAnnotation));

            newDocument = newDocument.WithSyntaxRoot(newRoot);
            Document formattedDocument = await Formatter.FormatAsync(newDocument, formatAnnotation, docOptions);
  1. In the debugger, check that the formatted document indeed as the indention settings as per the VS Option definition (<>4).
  2. Update the workspace:
                           if (!document.Project.Solution.Workspace.TryApplyChanges(formattedDocument.Project.Solution))
                            {
                                DebugUtilities.FailIfAttached("Failed to apply changes to the document.");

Expected Behavior:

The document in question after updating the workspace should contain the document as it was formatted.

Actual Behavior:

The indention in nested structures is all over the place.

Note: This is VB only. Same code for C# works as intended. Note also that this happens both in Framework AND in .NET 6+.

@DustinCampbell Just FYI: The above code was just to track down the issue, customers have started to report lately in the NETFX (inproc) Designer and the OOP Designer. It was the result of my fix attempts, until I found out that updating the workspace screwed the indention up.

コントリビューターガイド