Skip to content
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

Closed
wants to merge 2 commits into from
Closed

feat(languages): sql #1464

wants to merge 2 commits into from

Conversation

matoous
Copy link
Contributor

@matoous matoous commented Jan 8, 2022

WIP, needs some fixing

Screen Shot 2022-01-08 at 19 44 57

.

.gitmodules Outdated Show resolved Hide resolved
languages.toml Outdated Show resolved Hide resolved
file-types = ["sql"]
injection-regex = "sql"
comment-token = "--"
indent = { tab-width = 2, unit = " " }
Copy link
Contributor

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.

Comment on lines 63 to 101
[
"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
Copy link
Contributor

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.

Copy link
Contributor Author

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).

@matoous
Copy link
Contributor Author

matoous commented Jan 9, 2022

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).

Comment on lines 12 to 13
(TRUE)
(FALSE)
Copy link
Member

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

@archseer
Copy link
Member

\cc @the-mikedavis maybe there's a better grammar available? It seems it highlights create regardless of where it's positioned in the query

.gitmodules Outdated Show resolved Hide resolved
@jaredramirez
Copy link
Contributor

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.

@the-mikedavis
Copy link
Member

the-mikedavis commented Jan 11, 2022

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

  1. I'm particularly fond of this grammar's bluntly honest "status" section 😄.

@archseer
Copy link
Member

archseer commented Jan 11, 2022

  1. I'm particularly fond of this grammar's bluntly honest "status" section smile.

Looks like I wasn't the first to think of injecting into SQL-like strings 😄

@jaredramirez
Copy link
Contributor

@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?

@matoous
Copy link
Contributor Author

matoous commented Jan 20, 2022

@jaredramirez Sorry, got a lot of work lately so I didn't have time to take a look yet. Currently, highlight.scm needs to be written given that there's no predefined one in https://github.com/DerekStride/tree-sitter-sql. You can either pick up where I left or I will take a look hopefully next week.

@the-mikedavis
Copy link
Member

superseded by #2097

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants