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

Not highlighted with TypeScript Generics #114

Open
ariesclark opened this issue Sep 11, 2023 · 9 comments
Open

Not highlighted with TypeScript Generics #114

ariesclark opened this issue Sep 11, 2023 · 9 comments

Comments

@ariesclark
Copy link

The following code should be properly highlighted, but is not. Removing the generic type will cause the string to be highlighted again.

const { data } = await sql<{
  date: Date;
  foo: number;
  bar: number;
}>`
  select
    toStartOfInterval(timestamp, ${interval(5, "minute")}) AS date,
    sum(_sample_interval * double2) / sum(_sample_interval) as foo,
    sum(_sample_interval * double3) / sum(_sample_interval) as bar

  from analytics

  where timestamp >= now() - ${interval(7, "day")}
    and timestamp <= now()
    and index1 = ${worldId}

  group by date
  order by date
`;
@herenickname
Copy link

+1

@karlhorky
Copy link

karlhorky commented Nov 19, 2023

Generic type arguments can be implemented (⚠️ if they are on a single line - I'll come back to this in a followup comment) - check out working versions of this feature in the following VS Code extensions:

  1. SQL tagged template literals by @frigus02 (repo: https://github.com/frigus02/vscode-sql-tagged-template-literals)
  2. Inline SQL by @notyetspecified (repo: https://github.com/notyetspecified/vscode-sql-template-literal)

In the following PR by @KristjanTammekivi, the generic type parameter feature was added to Inline SQL:

@karlhorky
Copy link

karlhorky commented Nov 19, 2023

The problem with the original example in this current issue by @ariesclark above is that the generic type argument spans multiple lines.

The root cause for this is a bit more of a problem, since TextMate grammars have limitations, as @sheetalkamat is familiar with:

VS Code itself somehow gets around the limitations and can do correct syntax highlighting over multiple lines, maybe with Semantic Highlighting by @aeschli and @alexdima.

I also see some changes with regular expressions, which @sheetalkamat has also been maintaining:

So maybe there is a way for a VS Code extension to also achieve this, by also using this Semantic Highlighting / these regular expressions.

The TextMate grammar limitations have also been explored in the following SQL tagged template literals VS Code extension, but no solution has yet appeared:

@karlhorky
Copy link

karlhorky commented Nov 19, 2023

Workaround (/* sql */ comment)

Add a /* sql */ comment after the multi-line generic

sql<{
  value: number
-}[]>`
+}[]>/* sql */ `
  SELECT 1 value;
`

Credit: @net in thebearingedge/vscode-sql-lit#13 (comment)

@vicary
Copy link

vicary commented Apr 15, 2024

This actually breaks coloring for the rest of the documents with generics.

image

image

@KristjanTammekivi
Copy link

This actually breaks coloring for the rest of the documents with generics.

image

image

I can't seem to replicate
image

Can you give a full example? Here's mine:

const sql = <T>(q): any => {
    return {
        execute: (db) => {}
    }
}

interface F {
    now: string;
}

const db = {};

await sql<F>`SELECT NOW(6) AS 'now'`.execute(db);
const boo = true;

await sql<{ now: string }>`SELECT NOW(6) AS 'now'`.execute(db);
const foo = true;

await sql`SELECT NOW(6) AS 'now'`.execute(db);
const moo = true;


export { };

@vicary
Copy link

vicary commented Apr 18, 2024

@KristjanTammekivi testing with your snippet below:

With the extension enabled

image

With the extension disabled

image

@KristjanTammekivi
Copy link

Ah my bad, I thought this was the same extension as I made a contribution to because I was mentioned here. I'm using this extension:
image

@vicary
Copy link

vicary commented Apr 18, 2024

@KristjanTammekivi nice ad (and i'm sold) =D

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

No branches or pull requests

5 participants