Snippets not working in C9

workspace
autocomplete

#1

Hi,

Snippets are not working in C9. The steps followed were from the below documented site.

If this issue is resolved, it would help on various categories on auto completion.

When type the snippet keywords, Its listing the title in the coding pane, however not showing the content nor expanding the desired result.

Can any C9 employee get this fixed and help everyone to be more productive in C9?

Thanks in Advance!


#2

Hmm yeah, I have tried everything I can think of but anything other than the built-in snippets won’t expand in the editor.

I have tried the following:

  • Create a snippets folder called “snippets” in the main workspace

  • In the snippets folder create a file called test.snippets with the following example in it:

      snippet test
      if (${1:true}) {
          ${2}
      } else {
          ${0}
      }
    
  • Tried to expand test in a plain text, javascript and markdown file

  • Tried the above with a # scope: _, # scope: javascript and # scope: markdown

  • Tried moving the test.snippets file out of the snippets folder and into the workspace root

Any guidance would be appreciated.

Martien


#3

Unfortunately for now this is not as straightforward as it should be.

You need to create a new plugin

mkdir -p ~/.c9/plugins/myPlugin/snippets;
cd ~/.c9/plugins/myPlugin/snippets;
printf '# scope: javascript\nsnippet test\n\tif (${1:true}) {\n\t\t${2}\n\t}\n\t$0' > javascript.snippets;
echo '{"name":"myPlugin", "plugins": {}}' >  ../package.json

then open your init script from cloud9 menu and add code for loading the plugin

services.pluginManager.loadPackage([
    "~/.c9/plugins/myPlugin/package.json"
])

If you want to use this on several workspaces, then

update c9 cli tool to the latest version npm i c9 -g; hash -r
go to ~/.c9/plugins/myPlugin directory and run c9 build
and put files it creates in c9build folder somewhere public
(For instance create github repository and push to gh-pages branch)

then update the init script to load from that public url

services.pluginManager.loadPackage([
    "https://myname.github.io/myPlugin/c9build/package.myPlugin.js"
])

to add more snippets edit ~/.c9/plugins/myPlugin/snippets/javascript.snippets


Custom snippets
#4

Thanks for the reply, that sounds easy enough. I tried to replicate your example using the local plugin approach but no snippet completion yet. Can you tell me what I might still be doing wrong?


#5

snippets file needs to be indented with tabs, in the screenshot you have spaces instead.


#6

Success! Thanks for your help!

Martien