mtxr / vscode-sqltools

Database management for VSCode
https://vscode-sqltools.mteixeira.dev?utm_source=github&utm_medium=homepage-link
MIT License
1.5k stars 303 forks source link

Intellisense in javascript files via template literals #633

Open jlippold opened 4 years ago

jlippold commented 4 years ago

Is your feature request related to a problem? Please describe.

The problem is that I can't require() a .sql text file in a nodejs project. So, my sql files have to be attached to my db wrapper dynamically at runtime via fs.readFile()

And since the sql text is loaded at runtime, I lose control+click abilities when debugging in vscode. For example, If i inspect the definition of my method called db.getUsers(), it won't go directly to the SQL source.

Describe the solution you'd like

I like to have codelens intellisense working in js files, more specifically working in a template literal.

Maybe if there was some custom identifiers that I could put into my js string to identify a block of text as SQL.

For example maybe something like:

const sql = /* sql */ `
      SELECT *
      FROM users
`;

Then allow codelens autocomplete in the SQL Block

Describe alternatives you've considered

RIght now, I create my sql file wrapped in JS:

module.exports = { sql: /* sql */ `
  SELECT *
  FROM users
`};

Then when i need to retrieve it: const { sql } = require("./users.sql.js");

I use the /* sql */ before the backticks currently because it enables basic syntax highlighting by using this Comment tagged templates extension. Maybe that extension has clues into how to enable it in this project.

My current result gives me syntax highlighting but it does not give me all the other cool features that comes with sqltools

image
RXminuS commented 4 years ago

We use PGTyped with the sql tag and would love to see this kind of feature as well. In IntelliJ it works perfectly so that might be a good inspiration to look at?