When SQL used within a PHP string, interpolated PHP variables remain unstyled #449
Description
Prerequisites
- Put an X between the brackets on this line if you have done all of the following:
- Reproduced the problem in Safe Mode: https://flight-manual.atom.io/hacking-atom/sections/debugging/#using-safe-mode
- Followed all applicable steps in the debugging guide: https://flight-manual.atom.io/hacking-atom/sections/debugging/
- Checked the FAQs on the message board for common solutions: https://discuss.atom.io/c/faq
- Checked that your issue isn't already filed: https://github.com/issues?utf8=✓&q=is%3Aissue+user%3Aatom
- Checked that there is not already an Atom package that provides the described functionality: https://atom.io/packages
Description
Out of the box, VSCode seems to not encounter this particular issue with SQL highlighting within a PHP string. The highlighting seems to interpret the PHP variable as a string, when it probably should fallback to the language of the file / outer scope and check what sort of class it should have - in this particular case, it should be interpreted as a PHP variable.
Also, I might create another issue for the following, but not sure how easy it is to check for this problem:
- When using SQL inside a PHP string, it isn't styling joined strings (e.g. concat via
.
) and - When starting the string with a lowercase
select
, this does not trigger SQL highlighting. I could override the styles and transform them to lowercase, but this might actually be a project's styling convention, to not have the code be screaming at you.
Steps to Reproduce
- Create new file
- Paste in the following:
<?php
$editors = '"'.implode('","', ['vim', 'atom', 'vscode']).'"';
$results = database::select_one_column(
"SELECT user.id
FROM user
WHERE user.healthy = true
AND user.editor IN ($editors)"
);
Expected behavior:
$editors should be highlighted/styled like a PHP variable
Screenshot from VSCode
Actual behavior:
$editors is styled like any other plain PHP string.
Screenshot from Atom
Reproduces how often:
100% of the time
Versions
Atom : 1.58.0
Electron: 9.4.4
Chrome : 83.0.4103.122
Node : 12.14.1
apm 2.6.2
npm 6.14.13
node 12.14.1 x64
atom 1.58.0
python
git 2.25.1
Ubuntu 20
Additional Information
It applies the styles of syntax--source syntax--sql syntax--embedded syntax--php
and takes the form of a text element.
It is also worth noting that disabling this package, will correctly display PHP string interpolation.