Closed jdub55 closed 5 years ago
Do you mean types like file
?
All built in types or resources (file
, package
, etc), plus any from modules in the module path (downloaded from the forge, etc), plus any from a control repo if that's the current workspace will show up in intellisense, hover, autocomplete, etc. The Puppet Extension will then provide a minimal snippet which can be tabbed through. After completing the tab order, you can invoke intellisense/autocomplete and then get a list of parameters and the accompanying documentation in a hover window.
See https://github.com/lingua-pupuli/puppet-vscode#auto-completion, https://github.com/lingua-pupuli/puppet-vscode#hover-support. These types and resources show up as symbols to VSCode, which lights up the ability for quick code navigation like https://github.com/lingua-pupuli/puppet-vscode#go-to-symbol.
Did I misunderstand your suggestion?
TBH though, we should have the snippet thats auto generated from the Language Server be a little bit more filled out than name/ensure pairs.
@jpogran The Language Server only generates snippets for required parameters.
I was thinking more along the lines of a Puppet language reference where it would provide a "complete" snippet of all parameters for a given resource or Puppet code pattern / best practice.
Even better would be a place where people could share snippets but I suspect that's something Microsoft would have to provide within VS Code itself.
Even better would be a place where people could share snippets but I suspect that's something Microsoft would have to provide within VS Code itself.
No, you could dynamically fetch them. Interesting idea though...
"complete" snippet of all parameters for a given resource
This can be dangerous for resources like apache, but I understand the need
or Puppet code pattern / best practice.
This is one is really tricky as there can't really be a best practice for a resource as it's heavily dependent on the environment. Even a basic example like file
differs greatly whether it's on a Windows or Linux or OSX node.
Here's another take on it....
What if users could have their own snippets file and the extension reads that in and offers it in a dynamic manner? So you can have your own set of commonly used snippets?
EDIT - Already supported natively in VSCode https://blog.logrocket.com/custom-polymorphic-code-snippets-in-vs-code-e76d8cad656b/
Was going to point to https://code.visualstudio.com/docs/editor/userdefinedsnippets#_creating-your-own-snippets, but you beat me to it.
The https://code.visualstudio.com/docs/editor/userdefinedsnippets#_snippet-filenames and https://code.visualstudio.com/docs/editor/userdefinedsnippets#_global-snippets links imply we could ship community collaborated snippets in gists or pdk-templates, unsure of place to put it because I haven't tried yet
FWIW, this isn't the first time we've discussed this https://github.com/lingua-pupuli/puppet-vscode/issues/265.
Having your own snippets to create and use is great. That does seem to ship out of the box in VSCode as you both pointed out. Thanks for the links.
I think any form of community collaborated snippets would be something very popular amongst Puppet VSCode users, including myself. :) I can see how the implementation might be tricky. The goal is certainly not to (re)-create the Forge of snippets, so the use case would need to focus on a specific niche. This is where I thought longer form examples of good Puppet code (e.g. style guide) could be useful. My $0.02. And now looking at the other issue, I do see there is a separate plugin for sharing(?) https://marketplace.visualstudio.com/items?itemName=bhurt.puppet-snippets
Yeah @RandomNoun7 created that. Mainly because it spanned languages. This extension is focusing on the Puppet Language (so .pp etc.) not Ruby.
The implementation isn't that bad to be honest, and isn't the problem. It's more the workflow, and trying to not end up with a billion-and-one snippets for the file
resource.
I wonder if you could "subscribe" to blocks of snippets e.g.
I could subscribe to the Windows, IIS and ActiveDirectory snippets or I could subscribe to the CentOS and Apache snippets.
and so on.
Similarly, snippets for functions would be nice. I've started writing my own snippets for some of my more commonly used ones, but it would be really nice if the extension saw my functions and knew what they were.
File > Preferences > User Snippets > New User Snippet for '<name_of_workspace>'
creates a puppet.code-snippets
file inside the .vscode
directory inside a module folder. To create a 'shared' file, this file could then be added to the pdk-template repo, which is then sync'ed out to any module maintained by pdk update
. With some care for both file and snippet naming, you could have a multiple files for each 'subject' that are automatically loaded when a folder is opened.
File > Preferences > User Snippets > New Global Snippets file...
creates $env:APPDATA/Code/User/snippets/puppet.json
, which is more of an organization/user scoped thing and not something controllable by us.
The extension ships some snippets in https://github.com/lingua-pupuli/puppet-vscode/tree/master/snippets, but there would have to be some agreement as to how 'authoritative' they are, to Glenn's point.
This issue has been marked stale because it has been open for more than 30 days with no activity. If this issue is still important to you, please comment to keep this issue open. If not, this will be closed in 5 days
What if the Puppet VS Code plugin were to ship a reference version of the Puppet style guide in the form of code snippets? So, for example, if a user typed in psfile, it would return a well formatted example of a file code block. Rinse and repeat for the rest of the common Puppet language primitives / commonly used commands. Thoughts?