How do I teach VSC to autocomplete from @ or $?

Hi all,

I’m writing my game in Visual Studio Code, using the excellent ChoiceScript plugin (side note to whoever made the plugin: thank you, you have saved me so many hours!!). Only thing is, the plugin doesn’t doesn’t autocomplete $ to ${}, or @ to @{|}. Is there a way to teach it to do this, like cside does?

I’m writing a game with lots of NPC and player gender options, so it would really speed me up!

Thanks.

Example
*commend
    Indent
2 Likes

I’m not 100% sure if this functionality already exists or not, but if it doesn’t and you’re tech savvy you could look at adding it yourself in the codebase: GitHub - sgranade/choicescript_vscode: VS Code plugin for ChoiceScript development

Or you could ask @Sargent (the creator) very nicely.

5 Likes

Ah, thanks so much. I’ve messaged them.

1 Like

I don’t think the shortcut exists in the extension. An alternative is to create code snippets, it’s relatively simple and you can assign a keyboard shortcut to the snippet, which is functionally what you want.


  1. Open VS Code, then the command pallet (Ctrl + Shift + P)
  2. Search for Configure Snippets
  3. In the language option, type in choicescript
  4. Replace (or merge) the contents with the object below:
{
	"String interpolation": {
		"prefix": "$",
		"body": "${$1}$0",
		"description": "Add a string interpolation"
	},
	"String interpolation - Capital": {
		"prefix": "$",
		"body": "$!{$1}$0",
		"description": "Add a string interpolation with capitalization"
	},
	"String interpolation - UpperCase": {
		"prefix": "$",
		"body": "$!!{$1}$0",
		"description": "Add a string interpolation with upper case"
	},
	"String interpolation - Generic": {
		"prefix": "$",
		"body": "$$1{$2}$0",
		"description": "Add a string interpolation"
	},
	"Multireplace": {
		"prefix": "@",
		"body": "@{($1) $2|$3}$0",
		"description": "Add multireplace"
	},
	"For-loop": {
		"prefix": "*for",
		"body": [
			"*comment for_loop_start",
			"*temp ${1:i_} 0",
			"*temp ${2:max_loop} ${3:10}",
			"*label ${4:for_loop_start}",
			"$0",
			"*set $1 +1",
			"*if ($1 < $2)",
			"\t*goto $4",
			"*comment for_loop_end",
			""
		],
		"description": "Add for loop boilerplate"
	}
}
  1. In the command pallet again, search for Open Keyboard Shortcuts JSON
  2. Merge the array with the one below (also define more shortcuts)
[
    {
        "key": "ctrl+shift+s",
        "command": "editor.action.insertSnippet",
        "when": "editorTextFocus && editorLangId == 'choicescript'",
        "args": {
            "langId": "choicescript",
            "name": "String interpolation - Generic"
        }
    }
]
2 Likes