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

Prettier PR for VSCoder users? #58

Open
cameronelliott opened this issue Sep 3, 2021 · 15 comments
Open

Prettier PR for VSCoder users? #58

cameronelliott opened this issue Sep 3, 2021 · 15 comments
Labels
enhancement New feature or request

Comments

@cameronelliott
Copy link

This seems like a fantastic project, thanks for implementing it.

I am more of a backend Go developer, and try to stay away from NPM/Yarn, Rollup, etc, etc

It would be really wonderful if this was part of Prettier, and
so every VSCode user could this plugin without having to touch NPM.
Just by using a standard VScode extension:
https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
(NPM is great, until you do something wrong, and you don't know how to fix it)

Maybe it is not meant to be due to do logistical reasons, but I wanted to throw it out there,
in case.

@cameronelliott
Copy link
Author

cameronelliott commented Sep 3, 2021

One more thought, an example of a test-case in the README that shows a before & after example,
so users unfamiliar with prettier-plugin-go-template can see if they have installed it correctly would be super helpful.

For example, in my case, I did:

And if I now run:

npx prettier sample.html

with the input: sample.html

<html>
<script>
{{if }}
Whatever.
{{else }}
Psych.
{{end }}
</script>
</html>

I get the following on Stdout:

<html>
<script>
{{if }}
Whatever.
{{else }}
Psych.
{{end }}
</script>
</html>

Which seems wrong, (it is unindented to start) but I am so unfamiliar with npm/npx, I don't know the issue.

@cameronelliott
Copy link
Author

I just found this: prettier/prettier#6034
😢

@cameronelliott
Copy link
Author

Okay, I guess my test cases are failing because the {{foo}} inside the <script> block causes the formatter to abort formatting.

@NiklasPor
Copy link
Owner

<script> & <style> support is currently not there. Regarding VSCode, I could consider publishing the plugin as an additional VSCode extension.

@cameronelliott
Copy link
Author

@NiklasPor I don't think I'm using this enough to justify me asking you to do that, but maybe if other people come along and want it to it makes sense.
I'm just kind of thrilled this exists for go templates in the first place.

@whatsupbros
Copy link

Regarding VSCode, I could consider publishing the plugin as an additional VSCode extension.

Please, do!

I.e. Grafana Unified Alerting Templates are currently using Golang Template language, and it would be really useful.

Currently, no golang-template formatter available for VS Code in Marketplace.

@NiklasPor NiklasPor added the enhancement New feature or request label Mar 28, 2022
@NiklasPor
Copy link
Owner

If anyone is still interested in using it globally (without installing it to each repository), you'll need to:

  1. Have node & npm installed
  2. Run npm i -g prettier prettier-plugin-go-template
  3. Find where your node modules are by running npm root -g ➡️ /Users/niklaspor/.nvm/versions/node/v16.13.2/lib/node_modules
  4. Configure your VSCode settings to use your global prettier: "prettier.prettierPath": "/Users/niklaspor/.nvm/versions/node/v16.13.2/lib/node_modules/prettier"
  5. Setup your .prettierrc as it's described inside the README.md

I'm still considering publishing a VSCode extension for the users who're not interested in the node cosmos at all. Especially as the setup above is more than just a click 😁

@NiklasPor
Copy link
Owner

NiklasPor commented Apr 1, 2022

@cameronelliott there are now examples in the README.md and you can play with the plugin on the playground 🚀

image

@exofoliohq
Copy link

I'm still considering publishing a VSCode extension for the users who're not interested in the node cosmos at all. Especially as the setup above is more than just a click 😁

Never used node.js before, and had it all installed just for this pretty software piece of yours. It was interesting, but having the prettier plugin go template live next to the other vscode extensions would be smoother for sure

Cheers !

@robbycuenot
Copy link

I'm still considering publishing a VSCode extension for the users who're not interested in the node cosmos at all. Especially as the setup above is more than just a click 😁

Never used node.js before, and had it all installed just for this pretty software piece of yours. It was interesting, but having the prettier plugin go template live next to the other vscode extensions would be smoother for sure

Cheers !

Agree with this 100% -- Love the plugin, but would love it even more without having to install node. Great work regardless!

@pinkpigeonltd
Copy link

pinkpigeonltd commented Nov 1, 2023

When I attempt this, I get:

["INFO" - 12:20:11] Extension Name: esbenp.prettier-vscode.
["INFO" - 12:20:11] Extension Version: 10.1.0.
["INFO" - 12:20:20] Attempted to load Prettier module from /usr/lib/node_modules/prettier/
["ERROR" - 12:20:20] Failed to load module. If you have prettier or plugins referenced in package.json, ensure you have run `npm install`
["ERROR" - 12:20:20] Cannot find Prettier package.json

I have tried this with /usr/lib/node_modules/prettier (no trailing slash) which made no difference. Going to that directory, I can see prettier is right there, along with a package.json. Not sure how to address this. Any ideas? This is on Manjaro, if that helps.

Quick edit:

It would appear that the first part of this issue can be addressed by doing this:

"prettier.prettierPath": "/usr/lib/node_modules/prettier/index.cjs"

However, the following issue now occurs:

["ERROR" - 12:36:50] Error resolve node module 'prettier-plugin-go-template'
Error: Error resolve node module 'prettier-plugin-go-template'

Despite this also having been installed via npm i -g and sitting right next to prettier in /usr/lib/node_modules

One last edit:

I have now installed both prettier and the go template plugin directly in my project folder, to see if I could get it working like that. Now, however, I am getting this error:

["ERROR" - 12:41:44] Error formatting document.
["ERROR" - 12:41:44] An error occured during printing. Found invalid node root.
Error: An error occured during printing. Found invalid node root.
    at Object.print (/fast_ssd/Projects/pink_pigeon/defaultsitestructure/node_modules/prettier-plugin-go-template/lib/index.js:65:19)
    at callPluginPrintFunction (file:///fast_ssd/Projects/pink_pigeon/defaultsitestructure/node_modules/prettier/index.mjs:17846:20)
    at printAstToDoc (file:///fast_ssd/Projects/pink_pigeon/defaultsitestructure/node_modules/prettier/index.mjs:17801:22)
    at async coreFormat (file:///fast_ssd/Projects/pink_pigeon/defaultsitestructure/node_modules/prettier/index.mjs:18111:14)
    at async formatWithCursor (file:///fast_ssd/Projects/pink_pigeon/defaultsitestructure/node_modules/prettier/index.mjs:18309:14)
    at async Module.format2 (file:///fast_ssd/Projects/pink_pigeon/defaultsitestructure/node_modules/prettier/index.mjs:21504:25)

I am not entirely sure what that means unfortunately.

@technodrome
Copy link

Same error as user above.

@D-4-N
Copy link

D-4-N commented Apr 28, 2024

One last edit:

I have now installed both prettier and the go template plugin directly in my project folder, to see if I could get it working like that. Now, however, I am getting this error:

["ERROR" - 12:41:44] Error formatting document.
["ERROR" - 12:41:44] An error occured during printing. Found invalid node root.
Error: An error occured during printing. Found invalid node root.
    at Object.print (/fast_ssd/Projects/pink_pigeon/defaultsitestructure/node_modules/prettier-plugin-go-template/lib/index.js:65:19)
    at callPluginPrintFunction (file:///fast_ssd/Projects/pink_pigeon/defaultsitestructure/node_modules/prettier/index.mjs:17846:20)
    at printAstToDoc (file:///fast_ssd/Projects/pink_pigeon/defaultsitestructure/node_modules/prettier/index.mjs:17801:22)
    at async coreFormat (file:///fast_ssd/Projects/pink_pigeon/defaultsitestructure/node_modules/prettier/index.mjs:18111:14)
    at async formatWithCursor (file:///fast_ssd/Projects/pink_pigeon/defaultsitestructure/node_modules/prettier/index.mjs:18309:14)
    at async Module.format2 (file:///fast_ssd/Projects/pink_pigeon/defaultsitestructure/node_modules/prettier/index.mjs:21504:25)

I am not entirely sure what that means unfortunately.

I can confirm the above mentioned error is still present on the following:

Environment:

  • VSCode: 1.88.1
  • Prettier: 3.2.5
  • Plugin: 0.0.15

It seems to be something related to the way the GoTemplate AST is being generated or interpreted by Prettier. Maybe an API change?

@NiklasPor any hopes on feedback on this, or is the project no longer maintained?

Thanks

@kristofk01
Copy link

I'm also having this problem

@emilchr
Copy link

emilchr commented Jun 24, 2024

Same issue here.

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

No branches or pull requests

10 participants