It would be great if the extension added snippets or class templates.
It would be great if the extension added snippets or class templates.
You can always create user-defined snippets in VS Code:
https://code.visualstudio.com/docs/editor/userdefinedsnippets
There are also a number of snippet management apps out there that could be used for this purpose, but that may not have the close integration with the VS Code editor that you're probably after.
Thanks for the advice! I will definitely try and create a git repository. If something interesting happens, I'll be sure to send a link.
Hi AgentSIB.
Where did you land on this snippet thing??
As Brandon wrote, we can always create user defined snippets, but is seems like a huge waste of time, if we all have to invent the same wheel....
So why don't we start making a collection here?? And then add them to it's own extension.
I'm sure there are several long term Monkey C hackers that could share someting real useful from their collection.
Intellisense goes a long way, but even the simplest thing like System.println can be cut to less than one third of typing with a snippet.
Sys <enter> . (dot) <enter> pr <down key> <enter> ; (semicolon)
can be made to just p <enter> with the below. Plus you get the default label for free while picking the variable to print via intellisense.... And you don't have to remove the default "output" text first....
And this is just a basic snippet.
So please. Anyone with a good collection, please share...
jim_m_58 flocsy🤠 FlowState comes to mind :-)
Not to mention all the Garmin folks.... Not sure if those active here on the forum, are also the ones doing Garmins own IQ stuff.
"Print to console": { "scope": , "prefix": "p", "body": [ "System.println(\"$1: \" + $1);", ], "description": "Log output to console"
Creating a Visual Studio Code extension to add basic code snippets involves several steps. Below, I'll outline a basic example of how to create a simple extension that adds a custom code snippet to VS Code:
Prerequisites:
Steps:
Set Up a Development Environment:
Open your terminal and navigate to the directory where you want to create the extension.
Initialize a New Extension Project:
Use the Yeoman generator for code extensions to scaffold a new extension project. Run the following command:
npx yo code
Follow the prompts to set up your extension. Make sure to choose "New Code Snippet" when asked about the type of extension you want to create.
Edit the Snippet File:
After scaffolding the project, you'll have a snippets
folder in your extension directory. Inside this folder, you'll find a JSON file (e.g., mysnippet.json
). Open this file and define your custom code snippet. For example:
{
"MySnippet": {
"prefix": "mysnippet",
"body": [
"console.log('Hello, World!');"
],
"description": "My custom code snippet"
}
}
Test the Extension:
To test your extension, open a new instance of Visual Studio Code, press F5
to launch a new instance of VS Code with your extension loaded, and then open a file where you want to use the snippet.
Use the Snippet:
Type the prefix you defined in your snippet JSON file (e.g., "mysnippet"), and you should see IntelliSense suggestions for your snippet. Press Tab
to insert the snippet into your code.
Package and Publish:
If you're satisfied with your extension, you can package and publish it to the Visual Studio Code Marketplace. Follow the official documentation on how to do this: Publishing Extensions.
That's the basic process for creating a Visual Studio Code extension that adds a custom code snippet. You can expand on this by adding more snippets, customizing the snippet behavior, and exploring other features provided by the VS Code extension API.
Thanks. Will give it a try. Hopefully some of the more seasoned/experienced dev's will share their snip-lib.....
Do you also happen to know how to make a documentation link. So if one click .drawline you can open a browser or build in window/popup with .../..-docs/Toybox/Graphics/Dc.html#drawLine-instance_function
I don't have a "snip-lib" and I can't see why I'd create one. And if I had one I'd need to maintain it when the SDK gets updated.
For simple things like drawLine(), just typing in part gives you a list of possible matches, and clicking on one adds the template to your app. Like this:
If you need to access the API doc for things, do it from within VS Code using "View Documentation. You see the doc for the specific version of the SDK you are using, and the doc is local to your machine so faster than hitting the website all the time, you can access it when you are offline, and is more complete when it comes to things like "supported devices".
For more complex examples, check out the templates used for "New Project" and the samples in "Open Sample Folder"
For simple things like drawLine(), just typing in part gives you a list of possible matches, and clicking on one adds the template to your app. Like this:
If you actually read and understood the comment you’re replying to, you’d find:
- they know that already
- they already explained why they think snippets are even better
Intellisense goes a long way, but even the simplest thing like System.println can be cut to less than one third of typing with a snippet.
Sys <enter> . (dot) <enter> pr <down key> <enter> ; (semicolon)
can be made to just p <enter> with the below. Plus you get the default label for free while picking the variable to print via intellisense.... And you don't have to remove the default "output" text first....