prisma / language-tools

🌐 Prisma Language Tools = Language Server and Prisma's VS Code extension.
https://marketplace.visualstudio.com/items?itemName=Prisma.prisma
Apache License 2.0
250 stars 34 forks source link

js tag function syntax highlighting is incorrect #1734

Open Cat7373 opened 1 month ago

Cat7373 commented 1 month ago

Bug description

see: https://github.com/microsoft/vscode/issues/212938

image

How to reproduce

It is difficult to make a minimal reproducible example, but when using the label function ($queryRaw), most of the time it will cause color errors in some of the following code.

Expected behavior

Correct highlighted code.

Prisma information

5.14.0

Environment & setup

janpio commented 1 month ago

Can you paste the code snippet from the screenshot please? Is it possibly missing the closing backtick before the as Array ...?

Cat7373 commented 1 month ago

I made a small reproduction case:

import { PrismaClient } from '@prisma/client'

const prisma = new PrismaClient()

export function usePrisma(): typeof prisma {
  return prisma
}

class Demo {
  async test() {
    // aaa
    const x = '' as unknown as Array<{ a: number, b: number, c: number }>

    // bbb
    const a = await usePrisma().$queryRaw`
      SELECT
        taskId,
        COUNT(*) as \`count\`,
      FROM taskTarget
      WHERE typeId IN ['1', '2', '3']
      GROUP BY taskId
    ` as Array<{ taskId: number, count: number }>

    // ccc
    const y = '' as unknown as Array<{ a: number, b: number, c: number }>

    // ddd
  }
}
image
Cat7373 commented 1 month ago

Well, there is a small error in the sql. () should be used instead of [], but it does not affect the problem itself.

Cat7373 commented 1 month ago

It seems that there is no () after queryRaw. Just adding any function call can solve the problem:

Cat7373 commented 1 month ago

Comments are also ok

image
Cat7373 commented 1 month ago

You can also directly follow sql:

But in the middle, as can't solve the problem before, but it can solve the problem after as:

Cat7373 commented 1 week ago

Another magic fix: add a space:

image
Cat7373 commented 1 week ago

Another syntactically legal situation that will cause SQL highlighting to fail:

image