Skip to content

Improve authoring experience for Format.ps1xml and Types.ps1xml files #7749

@felixfbecker

Description

@felixfbecker

The Format.ps1xml and Types.ps1xml system in PowerShell is incredibly powerful. It's awesome how we can output objects, then totally separate from that define how these should be displayed in similar ways to how UIs are declared in XAML or JSX. Some really cool things are possible with it:

search results with highlighted matches

git log output with colored patches

However, authoring these files is incredibly frustrating. There is no autocompletion, hovers or validation for these files in your editor. The reference documentation is incredibly hard to find, browse and search (a bunch of duplicate element Foo for Bar for Baz for Quz (Format). Error messages are often very confusing.

The way this could be improved a lot would be with an XSD for these files, which would allow validation, hovers and autocompletion. I started working on this:

image

This is with the vscode-xml extension.
Schemas are here: https://github.com/felixfbecker/PowerShellXSD

I currently just autogenerated this schema from the Format file in that repo.

I will investigate writing a script that parses the official schema markdown reference here and converts it into an XSD (probably with manual edits afterwards).

I couldn't find reference docs for Types.ps1xml files unfortunately, but they also seem simpler.

What's in the way of using this is that any attribute declaration on the root Configuration element will cause an error:

Update-FormatData : Errors occurred while loading the format data file:
Format.ps1xml, Error at XPath  in file Format.ps1xml: The XML element Configuration does not allow attributes.

Which means the schema instance attributes need to be removed again before loading the Format file. It would be great if PowerShell could instead just ignore attributes on the root element:

<?xml version="1.0" encoding="utf-8"?>
<Configuration xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/felixfbecker/PowerShellXSD/master/Format.xsd"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

Another unfortunate thing to mention is that schema validation won't work if you want to use ANSI color codes in Format files because of #7526

I am posting this here in case someone wants to help out and because it would be great if eventually these schemas would be versioned in the PowerShell repo and hosted by Microsoft.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Committee-ReviewedPS-Committee has reviewed this and made a decisionIssue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-No ActivityIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions