sqls icon indicating copy to clipboard operation
sqls copied to clipboard

feat(hover): POC for inline hover with rust

Open qvalentin opened this issue 10 months ago • 0 comments

Hello everyone,

This PR provides a POC for supporting inline SQL in other languages (as described in https://github.com/joe-re/sql-language-server/issues/180).

The implementation is inspired by the tree sitter injections in nvim-tree-sitter where you can have syntax highlighting for inline languages.

The idea would be for the community to provide tree-sitter queries that define how certain parts of the code should be interpreted as SQL, as I did for rust in the POC. The LSP can then remove all non-SQL code from a file and process only the SQL text.

The example allows the sqls hover function to be used on the following rust code:

fn main() {
    sqlx::query("select * FROM tags").fetch_all(&mut conn).await;
}

image

With the proposed architecture of using queries, the feature could easily be extended to other languages and their SQL libraries, as tree-sitter already provides parsers for most languages.

Please note that adding tree-sitter as a dependency would require the project to be built using cgo.

Running multiple language servers at the same this is supported (at least for neovim) and it should cause no problem if sqls will just return nothing for all positions that are not inside SQL strings.

What do you think about this idea?

qvalentin avatar Apr 21 '24 12:04 qvalentin