Languages and tree-sitter
Add syntax colours and structural language data with tree-sitter. You need a bundler that emits module workers and WebAssembly assets.
Use Chromium 144, Firefox 145, Safari 26.2, or newer for Tree-sitter and native Markdown parsing. Parser calls in Node require Node.js 26.0.0 or newer; Bun requires 1.2.22 or newer. The parser uses WebAssembly.Memory.prototype.toResizableBuffer().
1. Install the syntax packages
npm install
@singapore-editor/core
@singapore-editor/tree
-sitter
@singapore-editor/tree
-sitter-languages
npm install
@singapore-editor/core
@singapore-editor/tree
-sitter
@singapore-editor/tree
-sitter-languages
npm install
@singapore-editor/core
@singapore-editor/tree-sitte
r
@singapore-editor/tree-sitte
r-languages
npm install
@singapore-editor/core
@singapore-editor/tree-sitte
r
@singapore-editor/tree-sitte
r-languages
npm install @singapore-editor/core
@singapore-editor/tree-sitter
@singapore-editor/tree-sitter-langua
ges
npm install @singapore-editor/core
@singapore-editor/tree-sitter
@singapore-editor/tree-sitter-langua
ges
npm install @singapore-editor/core
@singapore-editor/tree-sitter
@singapore-editor/tree-sitter-languages
npm install @singapore-editor/core
@singapore-editor/tree-sitter
@singapore-editor/tree-sitter-languages
npm install @singapore-editor/core @singapore-editor/tree-sitter
@singapore-editor/tree-sitter-languages
npm install @singapore-editor/core @singapore-editor/tree-sitter
@singapore-editor/tree-sitter-languages
npm install @singapore-editor/core @singapore-editor/tree-sitter
@singapore-editor/tree-sitter-languages
npm install @singapore-editor/core @singapore-editor/tree-sitter
@singapore-editor/tree-sitter-languages
npm install @singapore-editor/core @singapore-editor/tree-sitter
@singapore-editor/tree-sitter-languages
npm install @singapore-editor/core @singapore-editor/tree-sitter
@singapore-editor/tree-sitter-languages
sh example Make live
2. Register the bundled languages
import { Editor } from
'@singapore-editor/cor
e/editor'
import {
createTreeSitterLangua
gePlugin } from
'@singapore-editor/tre
e-sitter'
import {
TREE_SITTER_LANGUAGE_C
ONTRIBUTIONS } from
'@singapore-editor/tre
e-sitter-languages/cat
alog'
const editor = new
Editor ( document . queryS
elector < HTMLElement >( '
#editor' )!, {
plugins :
[ createTreeSitterLangu
agePlugin ( TREE_SITTER_
LANGUAGE_CONTRIBUTIONS
)],
})
editor . openDocument ({
documentId :
'/src/main.ts' ,
text : 'const value =
1\n' ,
languageId :
'typescript' ,
})
import { Editor } from
'@singapore-editor/cor
e/editor'
import {
createTreeSitterLangua
gePlugin } from
'@singapore-editor/tre
e-sitter'
import {
TREE_SITTER_LANGUAGE_C
ONTRIBUTIONS } from
'@singapore-editor/tre
e-sitter-languages/cat
alog'
const editor = new
Editor ( document . queryS
elector < HTMLElement >( '
#editor' )!, {
plugins :
[ createTreeSitterLangu
agePlugin ( TREE_SITTER_
LANGUAGE_CONTRIBUTIONS
)],
})
editor . openDocument ({
documentId :
'/src/main.ts' ,
text : 'const value =
1\n' ,
languageId :
'typescript' ,
})
import { Editor } from
'@singapore-editor/core/edit
or'
import {
createTreeSitterLanguagePlug
in } from
'@singapore-editor/tree-sitt
er'
import {
TREE_SITTER_LANGUAGE_CONTRIB
UTIONS } from
'@singapore-editor/tree-sitt
er-languages/catalog'
const editor = new
Editor ( document . querySelecto
r < HTMLElement >( '#editor' )!,
{
plugins :
[ createTreeSitterLanguagePlu
gin ( TREE_SITTER_LANGUAGE_CON
TRIBUTIONS )],
})
editor . openDocument ({
documentId :
'/src/main.ts' ,
text : 'const value = 1\n' ,
languageId : 'typescript' ,
})
import { Editor } from
'@singapore-editor/core/edit
or'
import {
createTreeSitterLanguagePlug
in } from
'@singapore-editor/tree-sitt
er'
import {
TREE_SITTER_LANGUAGE_CONTRIB
UTIONS } from
'@singapore-editor/tree-sitt
er-languages/catalog'
const editor = new
Editor ( document . querySelecto
r < HTMLElement >( '#editor' )!,
{
plugins :
[ createTreeSitterLanguagePlu
gin ( TREE_SITTER_LANGUAGE_CON
TRIBUTIONS )],
})
editor . openDocument ({
documentId :
'/src/main.ts' ,
text : 'const value = 1\n' ,
languageId : 'typescript' ,
})
import { Editor } from
'@singapore-editor/core/editor'
import {
createTreeSitterLanguagePlugin }
from '@singapore-editor/tree-sitter'
import {
TREE_SITTER_LANGUAGE_CONTRIBUTIONS }
from
'@singapore-editor/tree-sitter-langu
ages/catalog'
const editor = new
Editor ( document . querySelector < HTMLEl
ement >( '#editor' )!, {
plugins :
[ createTreeSitterLanguagePlugin ( TREE
_SITTER_LANGUAGE_CONTRIBUTIONS )],
})
editor . openDocument ({
documentId : '/src/main.ts' ,
text : 'const value = 1\n' ,
languageId : 'typescript' ,
})
import { Editor } from
'@singapore-editor/core/editor'
import {
createTreeSitterLanguagePlugin }
from '@singapore-editor/tree-sitter'
import {
TREE_SITTER_LANGUAGE_CONTRIBUTIONS }
from
'@singapore-editor/tree-sitter-langu
ages/catalog'
const editor = new
Editor ( document . querySelector < HTMLEl
ement >( '#editor' )!, {
plugins :
[ createTreeSitterLanguagePlugin ( TREE
_SITTER_LANGUAGE_CONTRIBUTIONS )],
})
editor . openDocument ({
documentId : '/src/main.ts' ,
text : 'const value = 1\n' ,
languageId : 'typescript' ,
})
import { Editor } from
'@singapore-editor/core/editor'
import { createTreeSitterLanguagePlugin } from
'@singapore-editor/tree-sitter'
import { TREE_SITTER_LANGUAGE_CONTRIBUTIONS } from
'@singapore-editor/tree-sitter-languages/catalog'
const editor = new
Editor ( document . querySelector < HTMLElement >( '#editor
' )!, {
plugins :
[ createTreeSitterLanguagePlugin ( TREE_SITTER_LANGUAG
E_CONTRIBUTIONS )],
})
editor . openDocument ({
documentId : '/src/main.ts' ,
text : 'const value = 1\n' ,
languageId : 'typescript' ,
})
import { Editor } from
'@singapore-editor/core/editor'
import { createTreeSitterLanguagePlugin } from
'@singapore-editor/tree-sitter'
import { TREE_SITTER_LANGUAGE_CONTRIBUTIONS } from
'@singapore-editor/tree-sitter-languages/catalog'
const editor = new
Editor ( document . querySelector < HTMLElement >( '#editor
' )!, {
plugins :
[ createTreeSitterLanguagePlugin ( TREE_SITTER_LANGUAG
E_CONTRIBUTIONS )],
})
editor . openDocument ({
documentId : '/src/main.ts' ,
text : 'const value = 1\n' ,
languageId : 'typescript' ,
})
import { Editor } from '@singapore-editor/core/editor'
import { createTreeSitterLanguagePlugin } from
'@singapore-editor/tree-sitter'
import { TREE_SITTER_LANGUAGE_CONTRIBUTIONS } from
'@singapore-editor/tree-sitter-languages/catalog'
const editor = new
Editor ( document . querySelector < HTMLElement >( '#editor' )!, {
plugins :
[ createTreeSitterLanguagePlugin ( TREE_SITTER_LANGUAGE_CONTRIBUTION
S )],
})
editor . openDocument ({
documentId : '/src/main.ts' ,
text : 'const value = 1\n' ,
languageId : 'typescript' ,
})
import { Editor } from '@singapore-editor/core/editor'
import { createTreeSitterLanguagePlugin } from
'@singapore-editor/tree-sitter'
import { TREE_SITTER_LANGUAGE_CONTRIBUTIONS } from
'@singapore-editor/tree-sitter-languages/catalog'
const editor = new
Editor ( document . querySelector < HTMLElement >( '#editor' )!, {
plugins :
[ createTreeSitterLanguagePlugin ( TREE_SITTER_LANGUAGE_CONTRIBUTION
S )],
})
editor . openDocument ({
documentId : '/src/main.ts' ,
text : 'const value = 1\n' ,
languageId : 'typescript' ,
})
import { Editor } from '@singapore-editor/core/editor'
import { createTreeSitterLanguagePlugin } from
'@singapore-editor/tree-sitter'
import { TREE_SITTER_LANGUAGE_CONTRIBUTIONS } from
'@singapore-editor/tree-sitter-languages/catalog'
const editor = new Editor ( document . querySelector < HTMLElement >( '#editor' )!, {
plugins :
[ createTreeSitterLanguagePlugin ( TREE_SITTER_LANGUAGE_CONTRIBUTIONS )],
})
editor . openDocument ({
documentId : '/src/main.ts' ,
text : 'const value = 1\n' ,
languageId : 'typescript' ,
})
import { Editor } from '@singapore-editor/core/editor'
import { createTreeSitterLanguagePlugin } from
'@singapore-editor/tree-sitter'
import { TREE_SITTER_LANGUAGE_CONTRIBUTIONS } from
'@singapore-editor/tree-sitter-languages/catalog'
const editor = new Editor ( document . querySelector < HTMLElement >( '#editor' )!, {
plugins :
[ createTreeSitterLanguagePlugin ( TREE_SITTER_LANGUAGE_CONTRIBUTIONS )],
})
editor . openDocument ({
documentId : '/src/main.ts' ,
text : 'const value = 1\n' ,
languageId : 'typescript' ,
})
import { Editor } from '@singapore-editor/core/editor'
import { createTreeSitterLanguagePlugin } from '@singapore-editor/tree-sitter'
import { TREE_SITTER_LANGUAGE_CONTRIBUTIONS } from
'@singapore-editor/tree-sitter-languages/catalog'
const editor = new Editor ( document . querySelector < HTMLElement >( '#editor' )!, {
plugins : [ createTreeSitterLanguagePlugin ( TREE_SITTER_LANGUAGE_CONTRIBUTIONS )],
})
editor . openDocument ({
documentId : '/src/main.ts' ,
text : 'const value = 1\n' ,
languageId : 'typescript' ,
})
import { Editor } from '@singapore-editor/core/editor'
import { createTreeSitterLanguagePlugin } from '@singapore-editor/tree-sitter'
import { TREE_SITTER_LANGUAGE_CONTRIBUTIONS } from
'@singapore-editor/tree-sitter-languages/catalog'
const editor = new Editor ( document . querySelector < HTMLElement >( '#editor' )!, {
plugins : [ createTreeSitterLanguagePlugin ( TREE_SITTER_LANGUAGE_CONTRIBUTIONS )],
})
editor . openDocument ({
documentId : '/src/main.ts' ,
text : 'const value = 1\n' ,
languageId : 'typescript' ,
})
ts example Make live
The grammar loads when the document needs it. Tree-sitter parses in a worker and supplies highlights, folds, bracket information, structural selection and injected languages.
3. Bring a grammar
Register a language on createTreeSitterSyntaxProvider, then install createTreeSitterSyntaxPlugin(provider). The contribution supplies a WebAssembly URL and highlight queries. Fold and injection queries are optional additions.
import {
createTreeSitterSyntax
Provider } from
'@singapore-editor/tre
e-sitter'
const provider =
createTreeSitterSyntax
Provider ()
provider . registerLangu
age ({
id : 'lua' ,
extensions :
[ '.lua' ],
load : async () => ({
wasmUrl :
'/grammars/tree-sitter
-lua.wasm' ,
highlightQuerySource :
await
fetch ( '/grammars/lua-h
ighlights.scm' ). then ((
response ) =>
response . text (),
),
}),
})
import {
createTreeSitterSyntax
Provider } from
'@singapore-editor/tre
e-sitter'
const provider =
createTreeSitterSyntax
Provider ()
provider . registerLangu
age ({
id : 'lua' ,
extensions :
[ '.lua' ],
load : async () => ({
wasmUrl :
'/grammars/tree-sitter
-lua.wasm' ,
highlightQuerySource :
await
fetch ( '/grammars/lua-h
ighlights.scm' ). then ((
response ) =>
response . text (),
),
}),
})
import {
createTreeSitterSyntaxProvid
er } from
'@singapore-editor/tree-sitt
er'
const provider =
createTreeSitterSyntaxProvid
er ()
provider . registerLanguage ({
id : 'lua' ,
extensions : [ '.lua' ],
load : async () => ({
wasmUrl :
'/grammars/tree-sitter-lua.w
asm' ,
highlightQuerySource :
await
fetch ( '/grammars/lua-highlig
hts.scm' ). then (( response ) =>
response . text (),
),
}),
})
import {
createTreeSitterSyntaxProvid
er } from
'@singapore-editor/tree-sitt
er'
const provider =
createTreeSitterSyntaxProvid
er ()
provider . registerLanguage ({
id : 'lua' ,
extensions : [ '.lua' ],
load : async () => ({
wasmUrl :
'/grammars/tree-sitter-lua.w
asm' ,
highlightQuerySource :
await
fetch ( '/grammars/lua-highlig
hts.scm' ). then (( response ) =>
response . text (),
),
}),
})
import {
createTreeSitterSyntaxProvider }
from '@singapore-editor/tree-sitter'
const provider =
createTreeSitterSyntaxProvider ()
provider . registerLanguage ({
id : 'lua' ,
extensions : [ '.lua' ],
load : async () => ({
wasmUrl :
'/grammars/tree-sitter-lua.wasm' ,
highlightQuerySource : await
fetch ( '/grammars/lua-highlights.scm'
). then (( response ) =>
response . text (),
),
}),
})
import {
createTreeSitterSyntaxProvider }
from '@singapore-editor/tree-sitter'
const provider =
createTreeSitterSyntaxProvider ()
provider . registerLanguage ({
id : 'lua' ,
extensions : [ '.lua' ],
load : async () => ({
wasmUrl :
'/grammars/tree-sitter-lua.wasm' ,
highlightQuerySource : await
fetch ( '/grammars/lua-highlights.scm'
). then (( response ) =>
response . text (),
),
}),
})
import { createTreeSitterSyntaxProvider } from
'@singapore-editor/tree-sitter'
const provider = createTreeSitterSyntaxProvider ()
provider . registerLanguage ({
id : 'lua' ,
extensions : [ '.lua' ],
load : async () => ({
wasmUrl : '/grammars/tree-sitter-lua.wasm' ,
highlightQuerySource : await
fetch ( '/grammars/lua-highlights.scm' ). then (( respons
e ) =>
response . text (),
),
}),
})
import { createTreeSitterSyntaxProvider } from
'@singapore-editor/tree-sitter'
const provider = createTreeSitterSyntaxProvider ()
provider . registerLanguage ({
id : 'lua' ,
extensions : [ '.lua' ],
load : async () => ({
wasmUrl : '/grammars/tree-sitter-lua.wasm' ,
highlightQuerySource : await
fetch ( '/grammars/lua-highlights.scm' ). then (( respons
e ) =>
response . text (),
),
}),
})
import { createTreeSitterSyntaxProvider } from
'@singapore-editor/tree-sitter'
const provider = createTreeSitterSyntaxProvider ()
provider . registerLanguage ({
id : 'lua' ,
extensions : [ '.lua' ],
load : async () => ({
wasmUrl : '/grammars/tree-sitter-lua.wasm' ,
highlightQuerySource : await
fetch ( '/grammars/lua-highlights.scm' ). then (( response ) =>
response . text (),
),
}),
})
import { createTreeSitterSyntaxProvider } from
'@singapore-editor/tree-sitter'
const provider = createTreeSitterSyntaxProvider ()
provider . registerLanguage ({
id : 'lua' ,
extensions : [ '.lua' ],
load : async () => ({
wasmUrl : '/grammars/tree-sitter-lua.wasm' ,
highlightQuerySource : await
fetch ( '/grammars/lua-highlights.scm' ). then (( response ) =>
response . text (),
),
}),
})
import { createTreeSitterSyntaxProvider } from
'@singapore-editor/tree-sitter'
const provider = createTreeSitterSyntaxProvider ()
provider . registerLanguage ({
id : 'lua' ,
extensions : [ '.lua' ],
load : async () => ({
wasmUrl : '/grammars/tree-sitter-lua.wasm' ,
highlightQuerySource : await
fetch ( '/grammars/lua-highlights.scm' ). then (( response ) =>
response . text (),
),
}),
})
import { createTreeSitterSyntaxProvider } from
'@singapore-editor/tree-sitter'
const provider = createTreeSitterSyntaxProvider ()
provider . registerLanguage ({
id : 'lua' ,
extensions : [ '.lua' ],
load : async () => ({
wasmUrl : '/grammars/tree-sitter-lua.wasm' ,
highlightQuerySource : await
fetch ( '/grammars/lua-highlights.scm' ). then (( response ) =>
response . text (),
),
}),
})
import { createTreeSitterSyntaxProvider } from '@singapore-editor/tree-sitter'
const provider = createTreeSitterSyntaxProvider ()
provider . registerLanguage ({
id : 'lua' ,
extensions : [ '.lua' ],
load : async () => ({
wasmUrl : '/grammars/tree-sitter-lua.wasm' ,
highlightQuerySource : await
fetch ( '/grammars/lua-highlights.scm' ). then (( response ) =>
response . text (),
),
}),
})
import { createTreeSitterSyntaxProvider } from '@singapore-editor/tree-sitter'
const provider = createTreeSitterSyntaxProvider ()
provider . registerLanguage ({
id : 'lua' ,
extensions : [ '.lua' ],
load : async () => ({
wasmUrl : '/grammars/tree-sitter-lua.wasm' ,
highlightQuerySource : await
fetch ( '/grammars/lua-highlights.scm' ). then (( response ) =>
response . text (),
),
}),
})
ts example Make live
Build the grammar against Singapore’s tree-sitter runtime. A grammar from a different runtime build needs compatibility verification.
Shiki as a separate path
The core’s /shiki entry point exposes Shiki highlighting and VS Code theme conversion. Use it when your integration needs its supported grammars or theme conversion. Tree-sitter supplies structural syntax information in addition to colours. Each path has its own worker and asset setup.
If it doesn’t work
Plain text appears with no colours
Check languageId, the grammar request and the worker console. A document language id does not load a plugin by itself.
A custom language fails to parse
Check the WebAssembly response and runtime compatibility, then validate the highlight query against that grammar’s node names.
Continue with bundling and workers , workers and highlighting .