nova-prettier
nova-prettier copied to clipboard
Suggestion: check language that the user selected for a file and use prettier --parse <language>
Hi,
I've noticed that when the user overrides the programming style on a file, via Editor > Style, Prettier usually skips checking what the user thinks that the syntax is for that file, and if the file ending is nothing that is recognised as being one of the supported ones (by Prettier), then the extension will complain saying that the language is not found — even if the file is supported, it's just the filename extension that doesn't get recognised by Prettier (which seems to only check for file extensions...).
Here is a typical example: I've installed the XML plugin for Prettier. This works fine... so long the file I open terminates with .xml
. But now imagine I wish to open, say, a .csproj
, which is used by Microsoft to 'configure' a C#/.NET project. I can manually change it to XML, and Nova will accept that, and even list that the .csproj
is valid XML (according to Nova's XML parser/validator), but Prettier will not know that. But Nova does! So, if it's possible to retrieve from Nova what it thinks that the syntax is supposed to be (I haven't found a function for that, but it's probably somewhere...), then you can run prettier --parse xml ...
on that file, instead of giving the error that Prettier could not determine the language of the file.
Also, Prettier, as far as I know, will only detect the language syntax from the file extension and nothing else; Nova's a bit cleverer, allowing the extensions to figure out the syntax based on more criteria.
Unfortunately, I lack the JS programming skills to write a PR with that proposed change, so I'm leaving this suggestion here — who knows, perhaps someone will get inspired by it some day!
Sounds like a nice improvement!
Do you actually have the prettier XML plugin installed in your project? Because by default Prettier doesn't include support for XML.
Version 2.6.0 (just released) will now try to use a parser based on the syntax selected in Nova if Prettier can't find a parser.