-
Notifications
You must be signed in to change notification settings - Fork 591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SQL] use inheritance to support different dialects #3046
Conversation
Thanks for working on this. I noticed a few things:
|
Big +1. |
INSERT INTO my_table (foo, bar)
VALUES (1, 'two') The table is scoped as a function. I'm finding that the biggest thing I miss from my janky T-SQL definition is the scoping for identifiers within (eg) |
Indeed, I am aware of this (though thanks for pointing it out) and am trying to decide what approach is best to use - I'm thinking of specific, small contexts which will allow me to match column names where column names are expected, table names where table names are expected etc, while allowing fully/partially qualified names. I think the alternative is to just match anything left which is not a keyword as an identifier - it could still support qualified names, but without being context aware, it won't know if it is a table or column name when unqualified (especially if the schema is not |
can you clarify what you mean here with an example please @jrappen ? I believe I addressed your other comments :) |
Will do when I'm back home. |
Regression: Having a function in the SELECT foo, COUNT(*) AS tally
FROM bar
WHERE 1 = 1
GROUP BY foo |
Sorry about that, it seems every change I make breaks something 😅 but at least each time we get some more syntax test assertions to prevent it in future :D so thanks for the testing and reporting of issues! It is fixed now :) |
1809d84
to
2541790
Compare
I did some "comment"s research. The built-in converter had originally brought over the comment tags from tmLanguage, when I did a PR to convert all files to sublime-syntax. I haven't tested it, but I assume the built-in converter works unchanged. The docs do not specify a comment key, though. Whether by ommission or design, only Jon or one of the others could say. With regards to word borders, I meant something like this random example from your code: expressions:
- meta_append: true
- match: (?i)\b(CONCATENATE|CONVERT|LOWER|SUBSTRING|TRANSLATE|TRIM|UPPER)\b
scope: support.function.string.sql should've probably been this, yes? : expressions:
- meta_append: true
- match: (?i)\b(CONCATENATE|CONVERT|LOWER|SUBSTRING|TRANSLATE|TRIM|UPPER)\b
captures:
1: support.function.string.sql There still some |
Note: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The scope-everything-as-a-constant for now is a little wild, but I can edit-color-scheme my way out of it.
Two notes on T-SQL types:
- You're missing
text
(intentional?) - You can wrap them in
[]
in some places, including the somewhat odd[VARCHAR](1)
style.
Looking very good. I will probably now run this at work, rather than my own def. The current weird stuff:
|
Hmm, I thought I had covered named CTE columns with syntax tests and scoped them as Packages/SQL/syntax_test_tsql.sql Line 634 in be7d7fc
The I am thinking that because semi-colons to end statements are mostly optional, it is going to be too brittle to try to accurately detect if it is the beginning of a (top level?) statement or not. But I may be able to improve it some more. Do you have any concrete examples you can share where it doesn't work please? I will work on the other items, thanks for notifying about them. I may just add them into the bottom of the syntax test file without assertions to start with (like I've done for |
I found a case where a CTE wasn't scoped/identified correctly and fixed it. And I found another overload of |
SELECT *
FROM table_name AS t1
INNER JOIN (SELECT foo FROM bar) AS t2(id)
-- ^^ constant.language.with
ON t2.ID = t1.ID which I think is equivalent to SELECT *
FROM table_name AS t1
INNER JOIN (SELECT foo AS id FROM bar) AS t2
ON t2.ID = t1.ID |
Thanks, I hadn't heard of that before. I will try to implement everything from https://docs.microsoft.com/en-us/sql/t-sql/queries/from-transact-sql?view=sql-server-ver15, which indeed includes this syntax. |
I've never used it, either. 😅 I'm just clicking around in our SQL files looking for stuff that seems odd.
You're doing great. If you need to take a break, or if you want me to stop finding bugs just tell me to stop for a bit. 😁 |
Thanks! Pray, please continue - though I probably should also try to concentrate on other dialects (like MySql) to be sure the base syntax is as useful/correct as it should be, rather than just concentrating on T-SQL 😅 |
ADD SEQUENCE isn't valid inside an ALTER TABLE context, so `sequence` here needs to be treated as a column name
This commit 1. renames CSS.sublime-syntax to CSS (Plain).sublime-syntax 2. creates an inherit CSS from CSS (Plain) Goal ---- Support different CSS dialects (Basic, PostCSS, Tailwind CSS, ...) in embedded code scenarios including templating support. Motivation ---------- More and more syntax packages inherit CSS.sublime-syntax to add support for interpolation or embed template tags (e.g.: ASP, JSP, PHP, Liquid, Vue, ...). Other packages might provide certain dialects of CSS, such as PostCSS or Tailwind CSS. It is currently not easily possible to embed Tailwind CSS in PHP or Liquid without rewriting each of those syntaxes, because all of them rely on default CSS.sublime-syntax due to inheritance depending on file names rather than scopes. The motivation is to enable exactly this (again), to benefit from both inheritance and flexibility from 3rd-party packages. Strategy -------- The idea is to turn CSS.sublime-syntax into an interface, which is inherit from CSS (Plain) and can be extended by and embedded into syntax definitions such as PHP, while being able to easily create an override with `extends` value replaced by desired syntax dialect (e.g.: Tailwind CSS). CSS (PHP) | CSS | \ | Tailwind CSS | | | PostCSS | / CSS (Plain) Note: It follows the idea being discussed in SQL (sublimehq#3046).
This may not be the place for it, but I think it's worth considering a new second-level scope on Also, I've been using this branch for years. It'd be nice to have its improvements available for everyone without hunting for it. |
Besides finalizing support for various statements and dialects (e.g. Postgre) scope naming in general is still one of the major todos. I agree with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SQL specs are too heavy to get everything done perfectly well.
This branch/PR may not be perfect, but is still lightyears ahead of master.
I'd say: Just go with it and improve based on user feedback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not my first time approving this. 😜
SummaryAll supported SQL syntax dialects share a common SQL (basic).sublime-syntax which provides common patterns/contexts and acts as a library. Supported dialects are: MySQL, PostgreSQL, T-SQL, Cassandra Basically all syntaxes are completely rewritten, following SQL specs. Primarily most important DML/DDL parts of each language are covered. As SQL requires dedicated syntax rules for each statement/feature, it is however hard to cover everything. So there are still unsupported statements in each dialect. All sorts of identifiers, such as tables, index, columns, users, constraints, ... are scoped to enable goto definition or goto reference as well as symbol lists. Not all of those have been added to the ladder though. Note: Postgre is still in an early WIP state and has not seen much work. As the primarily supported syntax of the old SQL package however was MySQL, this PR doesn't step backwards. |
Just to make sure, is overriding supposed to be done by copying https://github.com/sublimehq/Packages/blob/master/SQL/SQL.sublime-syntax to |
Yes. Or install DefaultSyntaxChooser from this DeathAxe comment. |
Initial work on supporting different SQL dialects using inheritance. Defaults to MySQL like before, but users can easily override the
SQL.sublime-syntax
to point to their preferred dialect. Idea originally proposed by SublimeHQ on the forum.Fixes #1742, #1764, #2899, #3072, #3072, closes #2631
Note: breaking change:
keyword.other.DML
has been lowercased tokeyword.other.dml
, so color schemes may need a small change if they target this scope specifically