mdaniel 2 days ago

An alternative approach is to use comments, which allow changing arbitrary string literals into injected contexts, as JetBrains does: https://www.jetbrains.com/help/idea/using-language-injection... I have found that to be more helpful in cases where the data flow can't or doesn't prove how a string is being used, as in:

  def doit():
    # language=SQL
    s = "SELECT * FROM FOO"
    run_sql(s)
  def run_sql(s: str):
    cur = conn.cursor()
    cur.execute(s)
Although I am not certain if tree-sitter allows matching on comments, but https://github.com/tree-sitter/tree-sitter/issues/1138 seems to imply that it does