Skip to content

XML Formatter makes unreadable documents #33367

@adamsoutar

Description

@adamsoutar

Summary

The 'Format Document' option in XML files produces very unusual, near-unreadable XML documents.

Description

Given this XML document:

<WatchFace width="450" height="450" shape="CIRCLE" schemeVersion="1.0.0"><Metadata key="CLOCK_TYPE" value="ANALOG"/><Metadata key="TICK_PER_SECOND" value="15"/><Scene backgroundColor="#ff000000"><ComplicationSlot slotId="0" displayName="Small Box Complication" screenReaderText="" isCustomizable="TRUE" supportedTypes="SMALL_IMAGE " x="180" y="179" width="92" height="92" pivotX="0.5" pivotY="0.5" name="Small Box Complication_0" alpha="255"><DefaultProviderPolicy defaultSystemProvider="EMPTY" defaultSystemProviderType="SMALL_IMAGE"/><BoundingBox x="0" y="0" width="92" height="92" pivotX="0" pivotY="0"/><Complication type="SMALL_IMAGE"><PartImage x="14" y="13" width="69" height="69" pivotX="0.5" pivotY="0.5" name="Image_fd89" alpha="255"><Image resource="[COMPLICATION.SMALL_IMAGE]"/></PartImage></Complication></ComplicationSlot></Scene></WatchFace>

VS Code does this:

Image

Zed does this:

Image

Steps to reproduce:

  1. Paste XML into Zed or open an XML document
  2. Open the Command Palette and type 'Format Document'
  3. Press Enter

Expected Behavior:

<Outer><Inner prop="value"><Innermost /></Inner></Outer>

Is formatted like this:

<Outer>
  <Inner prop="value">
    <Innermost />
  </Inner>
</Outer>

Actual Behavior:

Zed seems to place opening tags in line with the closing brackets of the previous element, and likes to close as many tags on one line as it can. Additionally, the indentation algorithm appears to be unbalanced as the longer the document is, the more everything drifts to the right without going back left.

Zed Settings JSON
{
  "project_panel": {
    "auto_fold_dirs": false
  },
  "ssh_connections": [
    // Redacted.
  ],
  "use_autoclose": false,
  "use_auto_surround": false,
  "indent_guides": {
    "enabled": false
  },
  "features": {
    "edit_prediction_provider": "none",
    "copilot": false
  },
  "vim_mode": false,
  "theme": "Catppuccin Frappé - No Italics",
  "base_keymap": "Atom",
  "telemetry": {
    "diagnostics": false,
    "metrics": false
  },
  "ui_font_size": 15,
  "buffer_font_size": 15,
  "buffer_font_family": "Menlo",
  "tabs": {
    "close_position": "left"
  },
  "git": {
    "inline_blame": {
      "enabled": false
    }
  },
  "tab_bar": {
    "show": true,
    "show_nav_history_buttons": false
  },
  "unstable.ui_density": "compact",
  "toolbar": {
    "breadcrumbs": false,
    "quick_actions": false
  },
  "lsp": {
    "rust-analyzer": {
      "cargo": {
        "buildScripts": {
          "enable": true
        }
      },
      "initialization_options": {
        "check": {
          "command": "clippy"
        },
        "rustfmt": {
          "extraArgs": ["+nightly"]
        }
      }
    }
  },
  "diagnostics": {
    "include_warnings": true,
    "inline": {
      "enabled": true,
      "update_debounce_ms": 150,
      "padding": 4,
      "min_column": 0,
      "max_severity": null
    }
  }
}

Zed Version and System Specs

Zed: v0.192.1 (Zed Preview)
OS: macOS 15.6.0
Memory: 16 GiB
Architecture: aarch64

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:toolingAn umbrella label for language tools, linters, formatters, etc

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions