dotnet/roslyn

Workspace update disregards indentation settings in VB

Open

#77.366 aperta il 27 feb 2025

Vedi su GitHub
 (0 commenti) (1 reazione) (0 assegnatari)C# (4257 fork)batch import
Area-IDEhelp wanted

Metriche repository

Star
 (20.414 star)
Metriche merge PR
 (Merge medio 6g 17h) (256 PR mergiate in 30 g)

Descrizione

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.

Guida contributor