iuyoy / highlight-string-code

Highlight string as specific language. 在其他代码中高亮 SQL、HTML、CSS或者JS
https://marketplace.visualstudio.com/items?itemName=iuyoy.highlight-string-code
MIT License
17 stars 4 forks source link

SQL strings should not require ; as the end delimeter. #6

Closed denysonique closed 3 years ago

denysonique commented 3 years ago

NodeJS libraries allow executing SQL queries by passing a non-delimeted string such as below:

db.query(`SELECT * FROM sometable`)

However the below pattern used for matching requires a semi-colon:

                    "end": "(;)",

I tried adding a leading backtick:

         "begin": "`(SELECT|INSERT|DELETE|UPDATE|DROP|ALTER|CREATE|SET|TRUNCATE|GRANT|REVOKE)\\s",
          "end": "`"

which seems to work, however by adding the backtick I loose the option to precede the query with a newline for formating of longer queries:

db.query(`
   SELECT .....
   WHERE
   INNER JOIN
   INNER JOIN 
   ....
`)

If I try to solve this by only adding a backtick to the "end" value, syntax highlihgting brakes for anything below.

What is the best solution to be able to have all strings beginning with a ` followed by newline + whitespace and then SELECT or other keywoard to be fully highlighted without having to delimit them with a ;

iuyoy commented 3 years ago

VS Code uses TextMate grammars as the syntax tokenization engine. In 12.2 Language Rules of the TextMate document language_grammars says that: image and in next section, it says image So it is impossible to match the multi-line beginning.

What's more, there may be some mis-highlighting if ` is used in SQL, while ; is easily appended to any SQL. They are the reasons why I choose ; as the end expression.