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

SQL syntax highlighting inside sqlx macros #10448

Closed
Milo123459 opened this issue Oct 4, 2021 · 13 comments
Closed

SQL syntax highlighting inside sqlx macros #10448

Milo123459 opened this issue Oct 4, 2021 · 13 comments
Labels
C-feature Category: feature request S-unactionable Issue requires feedback, design decisions or is blocked on other work

Comments

@Milo123459
Copy link
Contributor

Something like SQL syntax-highlighting inside usage of SQLx macros. This could also provide autocomplete for columns in tables, along with SQL keywords like UPDATE, INSERT, etc.

@lnicola lnicola added C-feature Category: feature request S-unactionable Issue requires feedback, design decisions or is blocked on other work labels Oct 4, 2021
@lnicola
Copy link
Member

lnicola commented Oct 4, 2021

How do you see that working?

@Milo123459
Copy link
Contributor Author

How do you see that working?

There is autocomplete for SQL files, and countless extensions to do that if not provided on install of VSCode; literally that, but inside the SQLx query macro. And for the autocomplete, SQLx actually provides this. The offline feature can do this, but, if it needs to be on the fly a modification would be made to SQLx, or we write something that fetches the data in RA

@lnicola
Copy link
Member

lnicola commented Oct 4, 2021

Unfortunately, we can't do that, for various technical reasons. And I don't think we should special-case sqlx, nor implement parsing for the three popular SQL dialects it supports.

@flodiebold
Copy link
Member

Yeah. We already have #10281 and #7402 for the general solution.

@Milo123459
Copy link
Contributor Author

Ah, I've done this wrong. I meant overall SQL syntax highlighting, but they look good.

@flodiebold
Copy link
Member

So since we're not going to provide any specific SQL support, let's close this in favor of those issues.

@lnicola
Copy link
Member

lnicola commented Oct 4, 2021

@Milo123459 it's a duplicate of #10281, filed also by you.

@Milo123459
Copy link
Contributor Author

I am aware. I wanted this one to be more specific

@peri4n
Copy link

peri4n commented Sep 18, 2024

If you ran into this and use NeoVim. You can use Treesitter to highlight the SQL inside string literals by putting

(macro_invocation
  macro: (scoped_identifier
    path: (identifier) @_path (#eq? @_path "sqlx")
    name: (identifier) @_name (#any-of? @_name "query" "query_as")
  )
  (token_tree 
    (_ (string_content) @injection.content)
    (#set! injection.language "sql")
  )
)

(call_expression
  (scoped_identifier
    path: (identifier) @path (#eq? @path "sqlx")
    name: (identifier) @name (#any-of? @name "query" "query_as"))
  (arguments
    (_ (string_content) @injection.content)
    (#set! injection.language "sql")))

into $USER/.config/neovim/queries/rust/injections.scm

@Milo123459
Copy link
Contributor Author

Is there an equivalent for vscode?

@peri4n
Copy link

peri4n commented Sep 19, 2024

I am not a VS Code expert but I don't believe there is. Treesitter support is an open issue: microsoft/vscode#50140

@paulwongx
Copy link

To clarify, based on this issue is it normal to see SQL queries inside a sqlx::query_as! macro all in one color like below?

Image

@LeonSnajdr
Copy link

Is there an equivalent for vscode?

You can use https://marketplace.visualstudio.com/items?itemName=qufiwefefwoyn.inline-sql-syntax

Then it looks like this:
Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature Category: feature request S-unactionable Issue requires feedback, design decisions or is blocked on other work
Projects
None yet
Development

No branches or pull requests

6 participants