4

I've got two debug snippets, one for PHP, one for Javascript. I use the same keyboard binding:

{
  "key": "ctrl+D",
  "command": "editor.action.insertSnippet",
  "when": "editorTextFocus && editorLangId == 'php'",
  "args": {
    "langId": "php",
    "name": "Debug output for PHP"
  }
}, {
  "key": "ctrl+D",
  "command": "editor.action.insertSnippet",
  "when": "editorTextFocus && editorLangId == 'javascript'",
  "args": {
    "langId": "javascript",
    "name": "Debug output for Javascript"
  }
},

Everything is fine, when I work with a .php file with PHP code or a .js file with JS code. But if I work with the JavaScript code inside PHP, it uses PHP variant, because the file language is PHP. PHP files can include PHP, JS or HTML blocks, but, as I see, the editorLangId parameter of when don't recognize it. Is there any way to refine a condition for language, to detect a "context" language?

Mosh Feu
  • 28,354
  • 16
  • 88
  • 135
Sergey Beloglazov
  • 342
  • 1
  • 3
  • 14
  • Out of the box? I believe not. If you want to write a code which will identify that, you can try to use [`php-parser`](https://github.com/glayzzle/php-parser.glayzzle.com/) to identify if the cursor is now inside a script tag. You can get an idea by playing with it - https://astexplorer.net/#/gist/0a6cbfb5d8b2bba34450928fff21c32d/66cd4c98359a61a4d42a68b0692f66f81b33b710 – Mosh Feu Oct 19 '20 at 14:34

0 Answers0