microsoft / microsoft/vscode-textmate

How to make the embedded language have corresponding language id

Open
#216 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
678
Forks
135
Avg merge
1d 14h
Merged PRs (30d)
2

Description

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!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how tokenizeLine and tokenizeLine2 derive scopes and language masks for embedded grammars. Compare the MagicPython.tmLanguage grammar with Sql.tmLanguage.json, focusing on the sql(...) example. Done means the embedded SELECT span receives the sql language id in tokenizeLine2 instead of python.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.