language-tools icon indicating copy to clipboard operation
language-tools copied to clipboard

js tag function syntax highlighting is incorrect

Open Cat7373 opened this issue 1 year ago • 8 comments

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

  • OS: macOS
  • Editor: VS Code
  • Editor version: 1.89.1
  • Extension version: 5.14.0

Cat7373 avatar May 17 '24 14:05 Cat7373

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

janpio avatar May 17 '24 15:05 janpio

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 avatar May 17 '24 18:05 Cat7373

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

Cat7373 avatar May 17 '24 18:05 Cat7373

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

Cat7373 avatar May 20 '24 03:05 Cat7373

Comments are also ok

image

Cat7373 avatar May 20 '24 03:05 Cat7373

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 avatar May 20 '24 03:05 Cat7373

Another magic fix: add a space:

image

Cat7373 avatar Jul 01 '24 02:07 Cat7373

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

image

Cat7373 avatar Jul 01 '24 02:07 Cat7373