microsoft / vscode-textmate

A library that helps tokenize text using Text Mate grammars.
MIT License
562 stars 108 forks source link

How to make the embedded language have corresponding language id #216

Open BeishaoCao-db opened 8 months ago

BeishaoCao-db commented 8 months ago

Hello everyone, I am struggling to find a correct way to support Textmate grammar with embedded language. For example, I want to embed sql into python and all the code inside sql( and ) should be considered as SQL code.

I add custom grammar rule to MagicPython grammer file and successfully make the token returned by tokenizeLine have SQL grammar scope name (something like *.sql). However, I don't know how to make the token returned by tokenizeLine2 to have language sql rather than python

e.g. For SELECT in sql(SELECT): tokenizeLine will return: keyword.other.DML.sql, which is defined in Sql.tmLanguage.json tokenizeLine2 will return a Uint32Array, but the mask the array will show language is python rather than sql

Any idea about how to fix this? I appreciate any help and understand there are a lot of moving parts here to make this all work!