vscode-textmate icon indicating copy to clipboard operation
vscode-textmate copied to clipboard

How to make the embedded language have corresponding language id

Open BeishaoCao-db opened this issue 2 years ago • 1 comments

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!

BeishaoCao-db avatar Oct 27 '23 06:10 BeishaoCao-db

use loadGrammarWithConfiguration() or loadGrammarWithEmbeddedLanguages() with IEmbeddedLanguagesMap instead of loadGrammar()

RedCMD avatar Oct 05 '24 23:10 RedCMD