2

I'm currently using JetBrains PhpStorm EAP build for PHP programming and I would like to switch to VS Code.

I'm currently working on an open source project that heavily uses printing of JavaScript and HTML code inside strings. PhpStorm has a very useful feature, it has full syntax highlighting and intellisense/code completion for HTML and JavaScript code inside strings in PHP. I have the Intelliphense extension installed on VS Code, but it doesn't seem to support this.

This is how JS inside strings looks on VS Code:

This is how it looks on VS Code

This is how the same code looks in PhpStorm:

This is how it looks on PhpStorm

Does anyone know if this is possible to achieve on VS Code? Or should I stick with PhpStorm?

6
  • You might find the answer to what your looking for in this SO question. Commented Nov 13, 2021 at 12:06
  • @slashroot Not exactly what I'm looking for, that SO question is talking about word autocomplete on Strings. I want full syntax highlighting and intellisense/autocomplete fo JavaScript and HTML code inside Strings, like what PHPStorm does. Commented Nov 13, 2021 at 15:49
  • In JetBrains IDEs it's called Language Injection: can be automatic (as in your example: it detects the HTML tag and injects HTML inside; or via some markers that each language can support: e.g. for PHP it can be the label for HEREDOC/NOWDOC .. or via #[Language] attribute for specific parameter etc; for Twig it's a custom block name. etc) or manual (a comment just before the string e.g. $a = /* @lang SQL */ 'some text that is treated as SQL'; Commented Nov 13, 2021 at 16:08
  • 1
    Try googling for vscode language injection and check the links -- they should give some links/ideas for such plugins or corresponding VSCode functionality. The first/start link: github.com/microsoft/vscode/issues/1751 and code.visualstudio.com/api/language-extensions/… Commented Nov 13, 2021 at 16:10
  • @LazyOne Thanks for the information and the links. I could not find any available extension that does HTML and JS Language Injection automatically in string literals on PHP files, but it seems feasible to do it. I currently don't have enough free time, so I'll continue using PhpStorm, but in the future I'll try and work on it. Commented Nov 16, 2021 at 21:06

1 Answer 1

2

This may help for some situations: Instead of ' or " you can use Heredoc syntax to get HTML highlighted inside PHP like this:

echo <<<HTML
<!-- Insert your HTML code here -->
<h1>Hello World</h1>
<h2>Syntax highlighting using heredoc PHP syntax</h2>
HTML; 

And it looks like this on vscode: vscode syntax highlight using heredoc php syntax

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

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.