Implement getSupportInfo() and use it for inference#3033
Implement getSupportInfo() and use it for inference#3033azz merged 8 commits intoprettier:masterfrom
Conversation
Yeah, the CLI seems necessary for non-JS editor, e.g. vim-prettier. |
package.json
Outdated
| "postcss-values-parser": "1.3.1", | ||
| "remark-frontmatter": "1.1.0", | ||
| "remark-parse": "4.0.0", | ||
| "semver": "^5.4.1", |
There was a problem hiding this comment.
It seems your yarn is always too lazy to pin them. 😂
There was a problem hiding this comment.
Has save-prefix "" been removed from yarn?
src/support.js
Outdated
|
|
||
| const languages = supportTable | ||
| .filter(language => { | ||
| return language.since && semver.gte(version, language.since); |
There was a problem hiding this comment.
Can be simplified to language => language...
|
|
||
| testVersions.forEach(version => { | ||
| test(`with version ${version}`, () => { | ||
| expect(prettier.getSupportInfo(version)).toMatchSnapshot(); |
There was a problem hiding this comment.
Can we only snapshot the { [language]: parsers } information? It's hard to read its snapshot and other information seems unrelated here.
| // Based on: | ||
| // https://github.com/github/linguist/blob/master/lib/linguist/languages.yml | ||
|
|
||
| const supportTable = [ |
There was a problem hiding this comment.
Maybe we should add a script to generate this table from linguist so that it'd be easy to update in the future.
There was a problem hiding this comment.
Maybe. I ended up changing quite a few things though, added more extensions, filenames, added groups, etc.
| }, | ||
| { | ||
| name: "HTML", | ||
| since: undefined, // unreleased |
There was a problem hiding this comment.
No plans to release this yet (in eg 1.8.0), right?
|
Are there any plans on having this function exposed through the CLI ? I believe the info table supplied by the CLI does not need to be so verbose so would probably be a much simpler output than the one returned by |
|
What kind of output would you expect from the CLI version? |
|
Ping @mitermayer, would JSON output or a parseable table be good for CLI? |
|
Hi @azz, Vim has a function This is the documentation info on json_decode() function for vim 8: |
|
I actually am not sure we can leverage from the |
|
Let's just do console.log(
prettier.format(
JSON.stringify(prettier.getSupportInfo()),
{ parser: "json" }
)
);? |
|
We can always start with that, then i can try to to add that to vim-prettier and see how that goes. Can always submit another PR later to allow the getSupportInfo() cli command to accept other output formats other than JSON if required |
|
@mitermayer do you want to give this a try with json_decode before we merge? |
|
I won't be able to test this today, so feel free to merge it as it is! Can always wait for next release in case this is not sufficient. |
TODO
This PR adds a new function to the prettier API:
getSupportInfo().It returns an object, currently with a
languagesproperty, which is an array of:getSupportInfoaccepts an optional argument,version, e.g.prettier.getSupportInfo("1.4.0"), this will filter the list to only include languages that version 1.4.0 of prettier support. This includes changingless/scss/cssparsers back topostcss.In addition, this table is now used by Prettier internally to perform parser inference based on filename and extension.
Maybe we should also add a CLI version?
Closes #3023
Fixes #3058