-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
feat(languages): sql #1464
feat(languages): sql #1464
Conversation
file-types = ["sql"] | ||
injection-regex = "sql" | ||
comment-token = "--" | ||
indent = { tab-width = 2, unit = " " } |
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.
Hmm, SQL 2 spaces? I never used SQL in two spaces, I thought it's rare.
runtime/queries/sql/highlights.scm
Outdated
[ | ||
"AS" | ||
"CREATE" | ||
"CREATE_DOMAIN" | ||
"CREATE_OR_REPLACE_FUNCTION" | ||
"CREATE_SCHEMA" | ||
"CREATE_TABLE" | ||
"CREATE_TYPE" | ||
"DATABASE" | ||
"FROM" | ||
"GRANT" | ||
"GROUP_BY" | ||
"IF_NOT_EXISTS" | ||
"INDEX" | ||
"INNER" | ||
"INSERT" | ||
"INTO" | ||
"JOIN" | ||
"LANGUAGE" | ||
"LEFT" | ||
"ON" | ||
"ORDER_BY" | ||
"OUTER" | ||
"PRIMARY_KEY" | ||
"PUBLIC" | ||
"RETURNS" | ||
"SCHEMA" | ||
"SELECT" | ||
"SET" | ||
"LOCAL" | ||
"SESSION" | ||
"TABLE" | ||
"TO" | ||
"UNIQUE" | ||
"UPDATE" | ||
"USAGE" | ||
"VALUES" | ||
"WHERE" | ||
] @keyword |
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.
Would it be better to separate CREATE
, UPDATE
, DELETE
as keyword.operator
? Also, I don't see DELETE
.
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.
I am not sure about having them as keyword.operator
. Looking at other implementations (Intellihj, VScode) it doesn't seem that anyone is doing this. On the other hand, some implementations have for example different highlighting for logic operators (OR
, AND
).
Hmm, there also seems to be https://github.com/DerekStride/tree-sitter-sql that has more recent changes, same amount of stars as the repo used currently in this PR (https://github.com/m-novikov/tree-sitter-sql). |
runtime/queries/sql/highlights.scm
Outdated
(TRUE) | ||
(FALSE) |
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.
probably want to split these out as boolean
\cc @the-mikedavis maybe there's a better grammar available? It seems it highlights |
I've set up sql support in a fork and started with https://github.com/m-novikov/tree-sitter-sql. After using it for a little while, I switched to https://github.com/DerekStride/tree-sitter-sql. IMO it's a nice grammar and you can write nicer queries/highlights. |
I did some looking around and I don't see any SQL grammars that look very close to complete1 I think the highlighting will be fairly buggy-looking for even DerekStride/tree-sitter-sql, but I also think that grammar is the pick of the litter with what's available currently. From what I understand, SQL is quite a large and nuanced language, so it's hard to pull off a grammar that handles everything that's possible with it. The good news is injections should be easier than I was thinking with the rust-regex-style injection. Based on this discussion, you could write an injections.scm query like so: ((string) @injection.content
(#match? @injection.content "^\s*(SELECT|CREATE|..)") ; .. etc
(#set injection.language "sql")) and that should be flexible enough to inject SQL into string literals where that's common (like go and rust afaik) Footnotes |
Looks like I wasn't the first to think of injecting into SQL-like strings 😄 |
@matoous what's the status on this? I'm pretty excited for this to land as it's one of the last languages not already supported I used regularly and I'd love to switch to Helix as my daily editor. Is there anything I can do to help? |
@jaredramirez Sorry, got a lot of work lately so I didn't have time to take a look yet. Currently, |
superseded by #2097 |
WIP, needs some fixing
.