-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
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:
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:
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.

