Kenth John Israel
Kenth John Israel

Reputation: 1333

How to ignore SQL syntax in Visual Studio Code

enter image description here

Hi, as the title implies, how do I ignore SQL syntax highlighting on my .php files?

As you could see on the image above, Visual Studio Code seems to think that the 'DELETE /api/crm/contact_meetings....' starts a SQL query and messes up the highlighting of the whole file.

I have tried checking the Visual Studio Code's settings but to no avail, I can't seem to find a relevant configuration entry for it.

Upvotes: 3

Views: 2308

Answers (3)

goodevans
goodevans

Reputation: 136

I know this is old, but I found an easy answer.

Open ~\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\php\syntaxes\php.tmLanguage.json

search and replace the line (there's multiple instances)

SELECT|INSERT|UPDATE|DELETE|CREATE|REPLACE|ALTER|AND

with

SELECT|INSERT|UPDATE|DELETE FROM|CREATE|REPLACE|ALTER|AND

That will make sure that the SQL formatting only kicks in when "delete from" is used, while leaving the normal syntax highlighting intact.

Upvotes: 0

Hideki Nakajima
Hideki Nakajima

Reputation: 31

I had the same problem, and I fix it with the help of Crayons' post.

Just delete these lines!

~\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\php\syntaxes\php.tmLanguage.json

2531:       "sql-string-double-quoted": {
2532:           "begin": "\"\\s*(?=(SELECT|INSERT|UPDATE|DELETE|CREATE|REPLACE|ALTER|AND)\\b)",
2533:           "beginCaptures": {
2534:               "0": {
2535:                   "name": "punctuation.definition.string.begin.php"
2536:               }
2537:           },
2538:           "contentName": "source.sql.embedded.php",
2539:           "end": "\"",
2540:           "endCaptures": {
2541:               "0": {
2542:                   "name": "punctuation.definition.string.end.php"
2543:               }
2544:           },
2545:           "name": "string.quoted.double.sql.php",
2546:           "patterns": [
2547:               {
2548:                   "include": "source.sql"
2549:               }
2550:           ]
2551:       },
2552:       "sql-string-single-quoted": {
2553:           "begin": "'\\s*(?=(SELECT|INSERT|UPDATE|DELETE|CREATE|REPLACE|ALTER|AND)\\b)",
2554:           "beginCaptures": {
2555:               "0": {
2556:                   "name": "punctuation.definition.string.begin.php"
2557:               }
2558:           },
2559:           "contentName": "source.sql.embedded.php",
2560:           "end": "'",
2561:           "endCaptures": {
2562:               "0": {
2563:                   "name": "punctuation.definition.string.end.php"
2564:               }
2565:           },
2566:           "name": "string.quoted.single.sql.php",
2567:           "patterns": [
2568:               {
2569:                   "include": "source.sql"
2570:               }
2571:           ]
2572:       },

I'd have to add it as a comment to Crayons' post, but I can't because I'm completely new to here. Sorry. Hope it helps you.

Upvotes: 3

Crayons
Crayons

Reputation: 2066

Just wanted to note, that I also experience this with the keyword DELETE. There is definitely something buggy with this keyword.

My investigations thus far, have led me to believe its either a language specific issue, or a theme specific issue.

PHP's language syntax highlight rules were taken from Atom's definitions -- see here: https://github.com/atom/language-php/blob/master/grammars/php.cson and here https://github.com/atom/language-php/issues/321

Visual Studio Code implemented this through php.tmLanguage.json which you'll find in ~\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\php\syntaxes.

Or, its a theme specific thing which may be somewhere here ~\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\theme-defaults\themes.

The VS Code team says any contributions or issues should be addressed with against the original repository (linked above). I've decided that its just not worth my time to investigate further, but you're welcome to try raising an issue over there :)

If you happen to find a fix, please let me know!

enter image description here

Upvotes: 2

Related Questions