VSCode: richer snippets

Summary: I want to be able to use or define a constructor snippet in Visual Studio Code for C#. However it achieves it, that means when I press a reserved (by me, if I’m defining it) set of keystrokes, then it has to determine the class name, which at that point is only in memory? And therefore needs to be reflected over? In fact the last question is supposition and pointless.. but it’s staying there. 🙂 Regardless, I feel a bit frustrated that I have burned 3 hours and got nowhere. Diddums.

Like the ones in fullfat Visual Studio, that’s what I need. e.g. ctor. Means nothing in VSCode evidently.
This is the ctor snippet in VS-speak:

 

snippetvs01

I thought I read that VSCode supported a richer syntax, so time to put that to the test.

Firstly there is this link:

snippetvs02

Not a lot right now then. And what is there just uses the lean syntax I have used before. So no use.

Then we have the tutorial here, which contains this promising thang…

So first try

npm install -g yo

Which in my case gives me:

Your npm version is outdated.

Upgrade to the latest version by running:
npm install -g npm

OK…Getting annoyed now:

snippetvs04

Maybe it was my own fault for doing it through PowerShell – now trying cmd/Node:

snippetvs05

snippetvs06

Seems better:

snippetvs07

Now try
npm install -g generator-code

snippetvs08

Now

yo code

snippetvs09

snippetvs10

Do a find for folders with .tmSnippet…

snippetvs11

C:\Users\Dennis\AppData\Roaming\npm\node_modules\generator-code\test\fixtures\tmsnippets

Plug that in:

snippetvs12

snippetvs13

snippetvs14

Really unhelpful. Exactly where have you installed it? Can’t find it using Windows Search, so let’s try PowerShell:

gci -Recurse -Path . -Filter “vsc-extension-quickstart.md” -ErrorAction SilentlyContinue

snippetvs15

snippetvs16

snippetvs17
# Welcome to your VS Code Extension

## What’s in the folder
* This folder contains all of the files necessary for your extension
* `package.json` – this is the manifest file that defines the location of the snippet file
and specifies the language of the snippets
* `snippets/snippets.json` – the file containing all snippets

## Get up and running straight away
* press `F5` to open a new window with your extension loaded
* create a new file with a file name suffix matching your language
* verify that your snippets are proposed on intellisense

## Make changes
* you can relaunch the extension from the debug toolbar after making changes to the files listed above
* you can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes

## Install your extension
* To start using your extension with Visual Studio Code copy it into the /.vscode/extensions folder and restart Code.
* To share your extension with the world, read on https://code.visualstudio.com/docs about publishing an extension.

https://code.visualstudio.com/docs/tools/yocode

https://code.visualstudio.com/docs/tools/samples

 

https://code.visualstudio.com/docs/editor/extension-gallery

Let’s try this route for an example:

snippetvs18

 

snippetvs19

So the C# XML docs extension clearly works… I just have to work out how now, and then I can use that for ctor. Another night:

snippetvs21

In fact as is often the way, now I am out of time, I’ve found possibly the most useful entries:

https://code.visualstudio.com/docs/customization/userdefinedsnippets

https://code.visualstudio.com/docs/editor/editingevolved

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s