jcberquist / sublimetext-cfml

CFML (ColdFusion and Lucee) package for Sublime Text
MIT License
115 stars 24 forks source link

SQL Syntax Highlighting does not Recognize SQL Server TOP Keyword #133

Closed michaelalandawson closed 4 years ago

michaelalandawson commented 4 years ago

There are a few instances where the TOP keyword is not recognized correctly and this causes the SQL syntax highlighting to revert to default text. I hope these examples can help improve the syntax highlighting.

Here is a basic query that is displayed correctly.

sql1

If I add the "top" keyword, the syntax doesn't change, but this is not a valid SQL statement.

sql2a

If I bring up a column to the same line as the "top" keyword, the syntax highlighting fails. This is still invalid SQL, but is basically the same logic as the previous invalid example that uses syntax highlighting.

sql2b

Here is an example of valid SQL using "select top n". (This is no longer recommended by Microsoft, but is still supported.)

sql3

This is valid SQL using Microsoft's recommendation of "top(n)". Syntax highlighting doesn't recognize this.

sql4

This is an example of using a SQL variable in the "top()" keyword.

sql5a

Finally, an example of using a parameter in the "top()" keyword.

sql5b

jcberquist commented 4 years ago

Thanks for reporting, I have tried to improve the top matching in st3-v0.29.1.

michaelalandawson commented 4 years ago

Thank you very much. It looks great. I did find another instance to tweak the highlighting regarding a query param and the SQL "limit" keyword.

This example highlights ":limit" as an SQL keyword when, in this case, is only a query parameter. My use of ":limit" as a query parameter is valid. Perhaps the matching could look for a leading colon, and if found, consider it a parameter.

sql1

If I rename the query parameter, highlighting works, as expected.

sql2

If you will allow me to go one step further, the following can be added to the "top" keyword: "percent" and "percent with ties"

sql3

Again, thank you for making this package.

jcberquist commented 4 years ago

I am glad that the original issue has been resolved.

In the first screenshots, the issue was that the SQL syntax was not being used at all, whereas in these latest ones the issue has to do with the SQL syntax itself. The SQL syntax comes from Sublime Text, it is not part of this package. It is a generic syntax, so SQL Server specific syntax is unlikely to be supported well.

As far as recognizing CFML parameters (e.g. :param), that might be possible down the road, but it would probably involve creating a custom syntax. So I don't think I can address it right now.

michaelalandawson commented 4 years ago

Understood. Thank you for looking at this.