microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.77k stars 28.73k forks source link

SQL syntax highlighting breaks with string inside f-string #227469

Open gunther-knotts opened 3 weeks ago

gunther-knotts commented 3 weeks ago

Does this issue occur when all extensions are disabled?: Yes

Steps to Reproduce:

  1. When inside a cell of a jupyter notebook, create an f-string to store SQL query text.
  2. As soon as a string is used inside of the f-string, the syntax highlighting breaks

Attached image:

  1. Examples of broken syntax, non broken syntax without a string, and .sql file with correct syntax of this example syntax_highlighting_bug.pdf
RedCMD commented 2 weeks ago

are you able to paste the code-snippets here please

image

gunther-knotts commented 2 weeks ago

Query with string criteria in the WHERE statement:

SELECT
  col_a,
  col_b,
  col_c
FROM
  table_a
WHERE
  col_a = 'example'
GROUP BY 
  ALL
ORDER BY
  col_a, col_b;

Query with string criteria in the SELECT statement:

SELECT
  col_a AS "a",
  col_b,
  col_c
FROM
  table_a
GROUP BY 
  ALL
ORDER BY
  col_a, col_b;

Query with string criteria in the SELECT & WHERE statement inside of an f-string:

query = f"""
SELECT
  col_a AS "a",
  col_b,
  col_c
FROM
  table_a
WHERE
  col_a = "a"
GROUP BY 
  ALL
ORDER BY
  col_a, col_b;
"""