5

How to turn on the autocompletion in custom-made snippets in VSCode? I create my snippets in javascriptreact.json


  "importReact": {
     "prefix": "import-stateless",
     "body": ["import React from 'react';"],
     "description": "import React statement"
  },

  "consolelog": {
     "prefix": "import-stateless",
     "body": ["console.log($1);"]
  }

and use in my_file.js:

import | from '|'
...
const variable = '';
console.log( | );
...

The problem is: when I type rea in import statement or varia in console.log - VSCode doesn't propose finish my word as react or variable It's problem with custom snippets only, because while manual typing import React from 'r it autocompletes the word react;

see hows it work

Thanks

1
  • 3
    See "editor.suggest.snippetsPreventQuickSuggestions": false Commented Jun 14, 2019 at 14:58

2 Answers 2

7

@Mark Thanks for your help! To make work autocomplete in snippets put in settings.json put the suggested line

"editor.suggest.snippetsPreventQuickSuggestions": false

the source

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for this. It's been bugging me ever since I started using vscode. Can't imagine who would ever want to use this default functionality...
I put the suggested line but its not working for me
0

Just figured this out myself and it's really simple.

The issue is just a matter of the cursor status and making sure it's it's set to the final cursor position.

So anywhere you want to be able to use auto-complete for variables, you just add $0 to that spot when you create the snippet, as that denotes the final cursor position: https://code.visualstudio.com/docs/editor/userdefinedsnippets#_tabstops.

"Print to console": {
    "scope": "javascript,typescript",
    "prefix": "clg",
    "body": ["console.log($0);"],
    "description": "Log output to console"
  }

Unlike the prior suggestion, what this does is actually put your cursor there, so you don't need to move your cursor back into the parentheses after the call.

Happy coding!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.