bmewburn / vscode-intelephense

PHP intellisense for Visual Studio Code
https://intelephense.com
Other
1.62k stars 94 forks source link

Embedded CSS and Javascript diagnostics custom replacement string #971

Open Ciantic opened 4 years ago

Ciantic commented 4 years ago

Feature description or problem with existing feature

Take for instance this code:

<style>
    .foo {
        <?php echo "..."; ?>
    }
</style>

It gives you error because the replacement text the Intelephense gives is incorrect, but I don't want to disable diagnostics all together.

Instead I'd like a simple way to define a replacement string case by case.

Describe the solution you'd like

One could define in a magic-comment what the replacement is e.g. @replacement ""

<style>
    .foo {
        <?php echo "...";  /* @replacement "" */ ?>
    }
</style>

This would mean that the PHP tag gets replaced in that case with empty string, so the CSS diagnostics works again.

Another example how to use @replacement magic:

<style>
    .foo {
        padding-top: <?php echo "..."; /* @replacement "0" */ ?>%;
    }
</style>

Ideally there are many other ways one could want to replace within script tags and style tags, and this would allow spaghetti PHP/CSS/Script to be valid from diagnostics point of view.

bmewburn commented 4 years ago

Good idea. Probably one of the few ways to make sure the php always gets replaced with something appropriate. At the moment it just replaces with a 1 everywhere. I wonder if this was changed to a 1 only after : and = and whitespace elsewhere that this would work for more cases?

Ciantic commented 4 years ago

It would help too, and it could be default for CSS if no @replacement is given.

However the @replacement comment would allow to make even stronger HTML diagnostics work. Imagine this:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>

<?php 
get_footer();
/* @replacement "</body></html>" */
?>

I'd like my editor to throw errors from missing end of tags or some malformed HTML (currently the HTML parts are not checked for end of tag errors or many other kind of errors, but it would be up to the HTML diagnostics after that because even HTML could be considered valid).