Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new languages #40

Merged
merged 12 commits into from
Dec 24, 2023
Merged

Add new languages #40

merged 12 commits into from
Dec 24, 2023

Conversation

Sec-ant
Copy link
Owner

@Sec-ant Sec-ant commented Nov 27, 2023

  • feat: support toml (uses prettier-plugin-toml). Thanks @JounQin @so1ve
  • feat: support ini (uses prettier-plugin-ini). Thanks @kddnewton
  • feat: support latex (uses prettier-plugin-latex). Thanks @siefkenj
  • feat: support properties (uses prettier-plugin-properties). Thanks @eemeli
  • feat: support yaml (no plugins required). Thanks @ikatyang
  • feat: support json (no plugins required).
  • feat: support graphql (no plugins required).
  • feat: support sh (uses prettier-plugin-sh). Thanks @JounQin
  • feat(sql): add prettier-plugin-sql-cst. Thanks @nene

👇 Use the package built by codesandbox-ci below to test the new languages support.

Copy link

codesandbox-ci bot commented Nov 27, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

package.json Outdated Show resolved Hide resolved
@Sec-ant Sec-ant force-pushed the new-languages branch 2 times, most recently from 0a78e34 to 3d37617 Compare November 28, 2023 15:05
@JounQin
Copy link

JounQin commented Dec 3, 2023

https://github.com/un-ts/prettier/tree/master/packages/sh

@Sec-ant Sec-ant force-pushed the new-languages branch 3 times, most recently from b46931f to a5c1b14 Compare December 4, 2023 02:27
package.json Outdated Show resolved Hide resolved
const { hardline, group, line, softline, indent } = builders;
const { mapDoc } = utils;

export const embedder: Embedder<Options> = async (
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with the code base, but can these functions be refactored as a common factory? I saw almost same codes for every plugin.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For most of the plugins, they're basically the same. But there're some plugins that need custom tweaking. I'll see what I can do to avoid most of the redundant code.

src/embedded/sh/options.ts Show resolved Hide resolved
@Sec-ant Sec-ant merged commit cb16266 into main Dec 24, 2023
3 of 4 checks passed
@nene
Copy link

nene commented Jan 6, 2024

Is there a hope of getting a new release soon (like within a week) with all these new languages?

I'd like to try it out, but wondering whether I should just wait a bit or should I pull this repo and fiddle around with it.

@Sec-ant
Copy link
Owner Author

Sec-ant commented Jan 6, 2024

Is there a hope of getting a new release soon (like within a week) with all these new languages?

@nene Sorry for the delay, my mind is currently occupied by another project. I'll make some cleanups and hopefully release a new version in 48 hrs.

@JounQin
Copy link

JounQin commented Jan 6, 2024

@Sec-ant You'd better find some collaborators.


I've just posted this repo into the private prettier Discord channel.

@Sec-ant
Copy link
Owner Author

Sec-ant commented Jan 8, 2024

@nene You should be able to test the prettier-plugin-sql-cst support in v0.4.0 v0.4.3.

Note that the default sql plugin used for embedded SQL language formatting is still prettier-plugin-sql. So an additional option embeddedSqlPlugin is needed to set it to prettier-plugin-sql-cst. An example of the configuration would be:

{
  "plugins": ["prettier-plugin-sql-cst", "prettier-plugin-embed"],
  "embeddedSqlIdentifiers": ["sql"],
  "embeddedSqlPlugin": "prettier-plugin-sql-cst",
  "embeddedSqlParser": "sqlite",
  "sqlKeywordCase": "upper",
}

And then you should be able to format code blocks that look like this:

/* sql */`
ATTACH DATABASE 'my_file.sqlite' AS my_schema
`

or this:

sql`
ATTACH DATABASE 'my_file.sqlite' AS my_schema
`

If you need other strings to be recognized as identifiers, like sqlite or bigquery, add them to the embeddedSqlIdentifiers option.

{
  "embeddedSqlIdentifiers": ["sql", "sqlite", "bigquery"],
}

I know the documentation of this plugin is still very immature and in early stage. If you have any questions regarding how to use this plugin, feel free to ask me. Comments, new issues, everywhere is ok.


I see there're new parsers getting supported in prettier-plugin-sql-cst. Wonder if you can just export a union type of all the supported parsers (just the name strings), then prettier-plugin-embed will pick up that type and automatically support new parsers and then I won't have to hardcode them inside the code and update them each time the sql plugin updates.


v0.4.1 v0.4.3 added types support for parsers "mysql", "mariadb" and "postgresql" in prettier-plugin-sql-cst

@Sec-ant Sec-ant deleted the new-languages branch January 8, 2024 06:00
@JounQin
Copy link

JounQin commented Jan 8, 2024

Or is that possible to generate those information via linguist-languages like https://github.com/un-ts/prettier/blob/master/scripts/languages.ts#L33?

cc @nene

@nene
Copy link

nene commented Jan 8, 2024

Thanks. I'll be playing around with it and will report if I run into issues.

I know the documentation of this plugin is still very immature and in early stage.

I find the documentation to be great. Considering this plugin is just a few months old, I'd say the docs are spectacular.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants