0

Since VSCode doesn't seem to feature autocompletion for if, elseif, etc for javascript, php and maybe even more, I wanted to create myself snippets to get around that.
The snippet:

{
    "If": {
        "scope": "javascript,typescript,php",
        "prefix": "if",
        "body": [
            "if ( ${1:true} ) {",
            "\t${2:/// code}",
            "}"
        ],
        "description": "generic if statement"
    }
}

Tab completion in php works as expected in javascript however it doesn't work at all.
Why is that?

UPDATE:
I have already figured out that there are default snippets for "if" and "ifelse".
vscode build in if snippets

The very top one is my snippet.
The build-in ones I have hidden from IntelliSense, so that they are not in the way. But as I said, this is just working for php, not javascript.
Removing my snippet and unhiding the build-in ones just causes that no if-snippet works anymore, not even php. That is the reason why I assumed that vscode has no if-completion support in the first place.
No matter how I put it, it never works :shrug:

2
  • Are you putting that snippet into a global snippets file - so it works in those 3 languages? Commented Aug 8, 2022 at 16:32
  • I go ctrl+shift+p > Snippets: Configure User Snippets > New Global Snippets file... > I enter a name > enter > fill in the automatically opened snippets template. The content is as I have posted above. The scope is set for javascript and php but only php works. Commented Aug 9, 2022 at 19:38

1 Answer 1

1

VSCode has default snippets for many languages. See the default ones by pressing:

Shift + Cmnd + P or Shift + Ctrl + P on PC and typing Insert Snippet

Seems like if is already reserved for one of those in JavaScript.

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

1 Comment

please see update for further information

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.