Git Product home page Git Product logo

Comments (14)

NiklasPor avatar NiklasPor commented on July 17, 2024 30

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 😁

from prettier-plugin-go-template.

NiklasPor avatar NiklasPor commented on July 17, 2024 4

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

image

from prettier-plugin-go-template.

NiklasPor avatar NiklasPor commented on July 17, 2024 3
<script> & <style> support is currently not there. Regarding VSCode, I could consider publishing the plugin as an additional VSCode extension.

from prettier-plugin-go-template.

D-4-N avatar D-4-N commented on July 17, 2024 3

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

from prettier-plugin-go-template.

pinkpigeonltd avatar pinkpigeonltd commented on July 17, 2024 2

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.

from prettier-plugin-go-template.

technodrome avatar technodrome commented on July 17, 2024 1

Same error as user above.

from prettier-plugin-go-template.

kristofk01 avatar kristofk01 commented on July 17, 2024 1

I'm also having this problem

from prettier-plugin-go-template.

cameronelliott avatar cameronelliott commented on July 17, 2024

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.

from prettier-plugin-go-template.

cameronelliott avatar cameronelliott commented on July 17, 2024

I just found this: prettier/prettier#6034
😢

from prettier-plugin-go-template.

cameronelliott avatar cameronelliott commented on July 17, 2024

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

from prettier-plugin-go-template.

cameronelliott avatar cameronelliott commented on July 17, 2024

@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.

from prettier-plugin-go-template.

whatsupbros avatar whatsupbros commented on July 17, 2024

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.

from prettier-plugin-go-template.

exofoliohq avatar exofoliohq commented on July 17, 2024

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 !

from prettier-plugin-go-template.

robbycuenot avatar robbycuenot commented on July 17, 2024

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!

from prettier-plugin-go-template.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.