Skip to content

Build a TypeScript playground

This page builds a TypeScript editor in six steps. It starts as plain text and ends with syntax highlighting, line numbers, search, type errors from a TypeScript language service in a worker, and a minimap. Every step shows the whole file so far, and below it an editor running exactly that file.

You need a Vite project and a container with a height, as in the Quick start. Install the packages this page uses:

npm install
@singapore-editor/core
@singapore-editor/tree
-sitter
@singapore-editor/tree
-sitter-languages
@singapore-editor/gutt
ers
@singapore-editor/find
@singapore-editor/type
script-lsp
@singapore-editor/mini
map
npm install
@singapore-editor/core
@singapore-editor/tree
-sitter
@singapore-editor/tree
-sitter-languages
@singapore-editor/gutt
ers
@singapore-editor/find
@singapore-editor/type
script-lsp
@singapore-editor/mini
map
npm install
@singapore-editor/core
@singapore-editor/tree-sitte
r
@singapore-editor/tree-sitte
r-languages
@singapore-editor/gutters
@singapore-editor/find
@singapore-editor/typescript
-lsp
@singapore-editor/minimap
npm install
@singapore-editor/core
@singapore-editor/tree-sitte
r
@singapore-editor/tree-sitte
r-languages
@singapore-editor/gutters
@singapore-editor/find
@singapore-editor/typescript
-lsp
@singapore-editor/minimap
npm install @singapore-editor/core
@singapore-editor/tree-sitter
@singapore-editor/tree-sitter-langua
ges @singapore-editor/gutters
@singapore-editor/find
@singapore-editor/typescript-lsp
@singapore-editor/minimap
npm install @singapore-editor/core
@singapore-editor/tree-sitter
@singapore-editor/tree-sitter-langua
ges @singapore-editor/gutters
@singapore-editor/find
@singapore-editor/typescript-lsp
@singapore-editor/minimap
npm install @singapore-editor/core
@singapore-editor/tree-sitter
@singapore-editor/tree-sitter-languages
@singapore-editor/gutters @singapore-editor/find
@singapore-editor/typescript-lsp
@singapore-editor/minimap
npm install @singapore-editor/core
@singapore-editor/tree-sitter
@singapore-editor/tree-sitter-languages
@singapore-editor/gutters @singapore-editor/find
@singapore-editor/typescript-lsp
@singapore-editor/minimap
npm install @singapore-editor/core @singapore-editor/tree-sitter
@singapore-editor/tree-sitter-languages @singapore-editor/gutters
@singapore-editor/find @singapore-editor/typescript-lsp
@singapore-editor/minimap
npm install @singapore-editor/core @singapore-editor/tree-sitter
@singapore-editor/tree-sitter-languages @singapore-editor/gutters
@singapore-editor/find @singapore-editor/typescript-lsp
@singapore-editor/minimap
npm install @singapore-editor/core @singapore-editor/tree-sitter
@singapore-editor/tree-sitter-languages @singapore-editor/gutters
@singapore-editor/find @singapore-editor/typescript-lsp
@singapore-editor/minimap
npm install @singapore-editor/core @singapore-editor/tree-sitter
@singapore-editor/tree-sitter-languages @singapore-editor/gutters
@singapore-editor/find @singapore-editor/typescript-lsp
@singapore-editor/minimap
npm install @singapore-editor/core @singapore-editor/tree-sitter
@singapore-editor/tree-sitter-languages @singapore-editor/gutters
@singapore-editor/find @singapore-editor/typescript-lsp @singapore-editor/minimap
npm install @singapore-editor/core @singapore-editor/tree-sitter
@singapore-editor/tree-sitter-languages @singapore-editor/gutters
@singapore-editor/find @singapore-editor/typescript-lsp @singapore-editor/minimap
sh example

The editor opens a small TypeScript file. Save it as sample.ts next to your code. It holds two files: main.ts, which you edit, and math.ts, which main.ts imports.

// The two files the
playground edits. In
your application they
come from wherever you
keep code.
export const MAIN_TS =
`import { twice } from
'./math'
// twice takes a
number, so TypeScript
flags this call.
console.log(twice('two
'))
type Order = { id:
string; quantity:
number; price: number
}
const orders: Order[]
= [
{ id: 'a-1',
quantity: 2, price:
4.5 },
{ id: 'b-7',
quantity: 1, price: 12
},
{ id: 'c-3',
quantity: 5, price:
0.8 },
]
function total(order:
Order): number {
return
order.quantity *
order.price
}
export function
summary(): string {
const sum =
orders.reduce((acc, o)
=> acc + total(o), 0)
return
\`\${orders.length}
orders,
\${sum.toFixed(2)}
total\`
}
`
export const MATH_TS =
`export const twice =
(n: number) => n * 2
`
// The two files the
playground edits. In
your application they
come from wherever you
keep code.
export const MAIN_TS =
`import { twice } from
'./math'
// twice takes a
number, so TypeScript
flags this call.
console.log(twice('two
'))
type Order = { id:
string; quantity:
number; price: number
}
const orders: Order[]
= [
{ id: 'a-1',
quantity: 2, price:
4.5 },
{ id: 'b-7',
quantity: 1, price: 12
},
{ id: 'c-3',
quantity: 5, price:
0.8 },
]
function total(order:
Order): number {
return
order.quantity *
order.price
}
export function
summary(): string {
const sum =
orders.reduce((acc, o)
=> acc + total(o), 0)
return
\`\${orders.length}
orders,
\${sum.toFixed(2)}
total\`
}
`
export const MATH_TS =
`export const twice =
(n: number) => n * 2
`
// The two files the
playground edits. In your
application they come from
wherever you keep code.
export const MAIN_TS =
`import { twice } from
'./math'
// twice takes a number, so
TypeScript flags this call.
console.log(twice('two'))
type Order = { id: string;
quantity: number; price:
number }
const orders: Order[] = [
{ id: 'a-1', quantity: 2,
price: 4.5 },
{ id: 'b-7', quantity: 1,
price: 12 },
{ id: 'c-3', quantity: 5,
price: 0.8 },
]
function total(order:
Order): number {
return order.quantity *
order.price
}
export function summary():
string {
const sum =
orders.reduce((acc, o) =>
acc + total(o), 0)
return \`\${orders.length}
orders, \${sum.toFixed(2)}
total\`
}
`
export const MATH_TS =
`export const twice = (n:
number) => n * 2
`
// The two files the
playground edits. In your
application they come from
wherever you keep code.
export const MAIN_TS =
`import { twice } from
'./math'
// twice takes a number, so
TypeScript flags this call.
console.log(twice('two'))
type Order = { id: string;
quantity: number; price:
number }
const orders: Order[] = [
{ id: 'a-1', quantity: 2,
price: 4.5 },
{ id: 'b-7', quantity: 1,
price: 12 },
{ id: 'c-3', quantity: 5,
price: 0.8 },
]
function total(order:
Order): number {
return order.quantity *
order.price
}
export function summary():
string {
const sum =
orders.reduce((acc, o) =>
acc + total(o), 0)
return \`\${orders.length}
orders, \${sum.toFixed(2)}
total\`
}
`
export const MATH_TS =
`export const twice = (n:
number) => n * 2
`
// The two files the playground
edits. In your application they come
from wherever you keep code.
export const MAIN_TS = `import {
twice } from './math'
// twice takes a number, so
TypeScript flags this call.
console.log(twice('two'))
type Order = { id: string; quantity:
number; price: number }
const orders: Order[] = [
{ id: 'a-1', quantity: 2, price:
4.5 },
{ id: 'b-7', quantity: 1, price:
12 },
{ id: 'c-3', quantity: 5, price:
0.8 },
]
function total(order: Order): number
{
return order.quantity *
order.price
}
export function summary(): string {
const sum = orders.reduce((acc, o)
=> acc + total(o), 0)
return \`\${orders.length} orders,
\${sum.toFixed(2)} total\`
}
`
export const MATH_TS = `export const
twice = (n: number) => n * 2
`
// The two files the playground
edits. In your application they come
from wherever you keep code.
export const MAIN_TS = `import {
twice } from './math'
// twice takes a number, so
TypeScript flags this call.
console.log(twice('two'))
type Order = { id: string; quantity:
number; price: number }
const orders: Order[] = [
{ id: 'a-1', quantity: 2, price:
4.5 },
{ id: 'b-7', quantity: 1, price:
12 },
{ id: 'c-3', quantity: 5, price:
0.8 },
]
function total(order: Order): number
{
return order.quantity *
order.price
}
export function summary(): string {
const sum = orders.reduce((acc, o)
=> acc + total(o), 0)
return \`\${orders.length} orders,
\${sum.toFixed(2)} total\`
}
`
export const MATH_TS = `export const
twice = (n: number) => n * 2
`
// The two files the playground edits. In your
application they come from wherever you keep code.
export const MAIN_TS = `import { twice } from
'./math'
// twice takes a number, so TypeScript flags this
call.
console.log(twice('two'))
type Order = { id: string; quantity: number; price:
number }
const orders: Order[] = [
{ id: 'a-1', quantity: 2, price: 4.5 },
{ id: 'b-7', quantity: 1, price: 12 },
{ id: 'c-3', quantity: 5, price: 0.8 },
]
function total(order: Order): number {
return order.quantity * order.price
}
export function summary(): string {
const sum = orders.reduce((acc, o) => acc +
total(o), 0)
return \`\${orders.length} orders,
\${sum.toFixed(2)} total\`
}
`
export const MATH_TS = `export const twice = (n:
number) => n * 2
`
// The two files the playground edits. In your
application they come from wherever you keep code.
export const MAIN_TS = `import { twice } from
'./math'
// twice takes a number, so TypeScript flags this
call.
console.log(twice('two'))
type Order = { id: string; quantity: number; price:
number }
const orders: Order[] = [
{ id: 'a-1', quantity: 2, price: 4.5 },
{ id: 'b-7', quantity: 1, price: 12 },
{ id: 'c-3', quantity: 5, price: 0.8 },
]
function total(order: Order): number {
return order.quantity * order.price
}
export function summary(): string {
const sum = orders.reduce((acc, o) => acc +
total(o), 0)
return \`\${orders.length} orders,
\${sum.toFixed(2)} total\`
}
`
export const MATH_TS = `export const twice = (n:
number) => n * 2
`
// The two files the playground edits. In your application they
come from wherever you keep code.
export const MAIN_TS = `import { twice } from './math'
// twice takes a number, so TypeScript flags this call.
console.log(twice('two'))
type Order = { id: string; quantity: number; price: number }
const orders: Order[] = [
{ id: 'a-1', quantity: 2, price: 4.5 },
{ id: 'b-7', quantity: 1, price: 12 },
{ id: 'c-3', quantity: 5, price: 0.8 },
]
function total(order: Order): number {
return order.quantity * order.price
}
export function summary(): string {
const sum = orders.reduce((acc, o) => acc + total(o), 0)
return \`\${orders.length} orders, \${sum.toFixed(2)} total\`
}
`
export const MATH_TS = `export const twice = (n: number) => n * 2
`
// The two files the playground edits. In your application they
come from wherever you keep code.
export const MAIN_TS = `import { twice } from './math'
// twice takes a number, so TypeScript flags this call.
console.log(twice('two'))
type Order = { id: string; quantity: number; price: number }
const orders: Order[] = [
{ id: 'a-1', quantity: 2, price: 4.5 },
{ id: 'b-7', quantity: 1, price: 12 },
{ id: 'c-3', quantity: 5, price: 0.8 },
]
function total(order: Order): number {
return order.quantity * order.price
}
export function summary(): string {
const sum = orders.reduce((acc, o) => acc + total(o), 0)
return \`\${orders.length} orders, \${sum.toFixed(2)} total\`
}
`
export const MATH_TS = `export const twice = (n: number) => n * 2
`
// The two files the playground edits. In your application they come from
wherever you keep code.
export const MAIN_TS = `import { twice } from './math'
// twice takes a number, so TypeScript flags this call.
console.log(twice('two'))
type Order = { id: string; quantity: number; price: number }
const orders: Order[] = [
{ id: 'a-1', quantity: 2, price: 4.5 },
{ id: 'b-7', quantity: 1, price: 12 },
{ id: 'c-3', quantity: 5, price: 0.8 },
]
function total(order: Order): number {
return order.quantity * order.price
}
export function summary(): string {
const sum = orders.reduce((acc, o) => acc + total(o), 0)
return \`\${orders.length} orders, \${sum.toFixed(2)} total\`
}
`
export const MATH_TS = `export const twice = (n: number) => n * 2
`
// The two files the playground edits. In your application they come from
wherever you keep code.
export const MAIN_TS = `import { twice } from './math'
// twice takes a number, so TypeScript flags this call.
console.log(twice('two'))
type Order = { id: string; quantity: number; price: number }
const orders: Order[] = [
{ id: 'a-1', quantity: 2, price: 4.5 },
{ id: 'b-7', quantity: 1, price: 12 },
{ id: 'c-3', quantity: 5, price: 0.8 },
]
function total(order: Order): number {
return order.quantity * order.price
}
export function summary(): string {
const sum = orders.reduce((acc, o) => acc + total(o), 0)
return \`\${orders.length} orders, \${sum.toFixed(2)} total\`
}
`
export const MATH_TS = `export const twice = (n: number) => n * 2
`
// The two files the playground edits. In your application they come from wherever
you keep code.
export const MAIN_TS = `import { twice } from './math'
// twice takes a number, so TypeScript flags this call.
console.log(twice('two'))
type Order = { id: string; quantity: number; price: number }
const orders: Order[] = [
{ id: 'a-1', quantity: 2, price: 4.5 },
{ id: 'b-7', quantity: 1, price: 12 },
{ id: 'c-3', quantity: 5, price: 0.8 },
]
function total(order: Order): number {
return order.quantity * order.price
}
export function summary(): string {
const sum = orders.reduce((acc, o) => acc + total(o), 0)
return \`\${orders.length} orders, \${sum.toFixed(2)} total\`
}
`
export const MATH_TS = `export const twice = (n: number) => n * 2
`
// The two files the playground edits. In your application they come from wherever
you keep code.
export const MAIN_TS = `import { twice } from './math'
// twice takes a number, so TypeScript flags this call.
console.log(twice('two'))
type Order = { id: string; quantity: number; price: number }
const orders: Order[] = [
{ id: 'a-1', quantity: 2, price: 4.5 },
{ id: 'b-7', quantity: 1, price: 12 },
{ id: 'c-3', quantity: 5, price: 0.8 },
]
function total(order: Order): number {
return order.quantity * order.price
}
export function summary(): string {
const sum = orders.reduce((acc, o) => acc + total(o), 0)
return \`\${orders.length} orders, \${sum.toFixed(2)} total\`
}
`
export const MATH_TS = `export const twice = (n: number) => n * 2
`
ts example

Create an Editor in the container and open main.ts. The document id is a path because the TypeScript step later resolves imports from it.

import { Editor } from
'@singapore-editor/cor
e/editor'
import { MAIN_TS }
from './sample'
export function
mountPlayground(elemen
t: HTMLElement):
Editor {
const editor = new
Editor(element)
editor.openDocument({
documentId:
'/src/main.ts', text:
MAIN_TS, languageId:
'typescript' })
return editor
}
import { Editor } from
'@singapore-editor/cor
e/editor'
import { MAIN_TS }
from './sample'
export function
mountPlayground(elemen
t: HTMLElement):
Editor {
const editor = new
Editor(element)
editor.openDocument({
documentId:
'/src/main.ts', text:
MAIN_TS, languageId:
'typescript' })
return editor
}
import { Editor } from
'@singapore-editor/core/edit
or'
import { MAIN_TS } from
'./sample'
export function
mountPlayground(element:
HTMLElement): Editor {
const editor = new
Editor(element)
editor.openDocument({
documentId: '/src/main.ts',
text: MAIN_TS, languageId:
'typescript' })
return editor
}
import { Editor } from
'@singapore-editor/core/edit
or'
import { MAIN_TS } from
'./sample'
export function
mountPlayground(element:
HTMLElement): Editor {
const editor = new
Editor(element)
editor.openDocument({
documentId: '/src/main.ts',
text: MAIN_TS, languageId:
'typescript' })
return editor
}
import { Editor } from
'@singapore-editor/core/editor'
import { MAIN_TS } from './sample'
export function
mountPlayground(element:
HTMLElement): Editor {
const editor = new Editor(element)
editor.openDocument({ documentId:
'/src/main.ts', text: MAIN_TS,
languageId: 'typescript' })
return editor
}
import { Editor } from
'@singapore-editor/core/editor'
import { MAIN_TS } from './sample'
export function
mountPlayground(element:
HTMLElement): Editor {
const editor = new Editor(element)
editor.openDocument({ documentId:
'/src/main.ts', text: MAIN_TS,
languageId: 'typescript' })
return editor
}
import { Editor } from
'@singapore-editor/core/editor'
import { MAIN_TS } from './sample'
export function mountPlayground(element:
HTMLElement): Editor {
const editor = new Editor(element)
editor.openDocument({ documentId: '/src/main.ts',
text: MAIN_TS, languageId: 'typescript' })
return editor
}
import { Editor } from
'@singapore-editor/core/editor'
import { MAIN_TS } from './sample'
export function mountPlayground(element:
HTMLElement): Editor {
const editor = new Editor(element)
editor.openDocument({ documentId: '/src/main.ts',
text: MAIN_TS, languageId: 'typescript' })
return editor
}
import { Editor } from '@singapore-editor/core/editor'
import { MAIN_TS } from './sample'
export function mountPlayground(element: HTMLElement): Editor {
const editor = new Editor(element)
editor.openDocument({ documentId: '/src/main.ts', text:
MAIN_TS, languageId: 'typescript' })
return editor
}
import { Editor } from '@singapore-editor/core/editor'
import { MAIN_TS } from './sample'
export function mountPlayground(element: HTMLElement): Editor {
const editor = new Editor(element)
editor.openDocument({ documentId: '/src/main.ts', text:
MAIN_TS, languageId: 'typescript' })
return editor
}
import { Editor } from '@singapore-editor/core/editor'
import { MAIN_TS } from './sample'
export function mountPlayground(element: HTMLElement): Editor {
const editor = new Editor(element)
editor.openDocument({ documentId: '/src/main.ts', text: MAIN_TS,
languageId: 'typescript' })
return editor
}
import { Editor } from '@singapore-editor/core/editor'
import { MAIN_TS } from './sample'
export function mountPlayground(element: HTMLElement): Editor {
const editor = new Editor(element)
editor.openDocument({ documentId: '/src/main.ts', text: MAIN_TS,
languageId: 'typescript' })
return editor
}
import { Editor } from '@singapore-editor/core/editor'
import { MAIN_TS } from './sample'
export function mountPlayground(element: HTMLElement): Editor {
const editor = new Editor(element)
editor.openDocument({ documentId: '/src/main.ts', text: MAIN_TS, languageId:
'typescript' })
return editor
}
import { Editor } from '@singapore-editor/core/editor'
import { MAIN_TS } from './sample'
export function mountPlayground(element: HTMLElement): Editor {
const editor = new Editor(element)
editor.openDocument({ documentId: '/src/main.ts', text: MAIN_TS, languageId:
'typescript' })
return editor
}
ts example
Scroll here to run this step.

With no theme the editor is black text on white with the current line shaded, as Monaco and CodeMirror start. The text is plain: you can select, type and undo, but nothing knows it is TypeScript yet.

A theme is every colour the editor paints: the background and text, the gutter, selections, popups, and the colour of each kind of syntax. Syntax highlighting, which arrives in step 3, only decides what each word is, a keyword or a string or a type. The theme decides what colour that is.

A theme is a plain object, and you only set the colours you want to change. Here the editor takes the warm dark of this site’s code blocks. type: 'dark' picks dark defaults for everything else, including the syntax colours and the hover popup in step 5. To reuse a VS Code theme instead, convert it with editorThemeFromVscodeTheme from @singapore-editor/core/shiki.

import { Editor } from
'@singapore-editor/cor
e/editor'
import { MAIN_TS }
from './sample'
export function
mountPlayground(elemen
t: HTMLElement):
Editor {
const editor = new
Editor(element, {
theme: { type:
'dark',
backgroundColor:
'#23211d',
foregroundColor:
'#d6d1c6' },
})
editor.openDocument({
documentId:
'/src/main.ts', text:
MAIN_TS, languageId:
'typescript' })
return editor
}
import { Editor } from
'@singapore-editor/cor
e/editor'
import { MAIN_TS }
from './sample'
export function
mountPlayground(elemen
t: HTMLElement):
Editor {
const editor = new
Editor(element, {
theme: { type:
'dark',
backgroundColor:
'#23211d',
foregroundColor:
'#d6d1c6' },
})
editor.openDocument({
documentId:
'/src/main.ts', text:
MAIN_TS, languageId:
'typescript' })
return editor
}
import { Editor } from
'@singapore-editor/core/edit
or'
import { MAIN_TS } from
'./sample'
export function
mountPlayground(element:
HTMLElement): Editor {
const editor = new
Editor(element, {
theme: { type: 'dark',
backgroundColor: '#23211d',
foregroundColor: '#d6d1c6'
},
})
editor.openDocument({
documentId: '/src/main.ts',
text: MAIN_TS, languageId:
'typescript' })
return editor
}
import { Editor } from
'@singapore-editor/core/edit
or'
import { MAIN_TS } from
'./sample'
export function
mountPlayground(element:
HTMLElement): Editor {
const editor = new
Editor(element, {
theme: { type: 'dark',
backgroundColor: '#23211d',
foregroundColor: '#d6d1c6'
},
})
editor.openDocument({
documentId: '/src/main.ts',
text: MAIN_TS, languageId:
'typescript' })
return editor
}
import { Editor } from
'@singapore-editor/core/editor'
import { MAIN_TS } from './sample'
export function
mountPlayground(element:
HTMLElement): Editor {
const editor = new Editor(element,
{
theme: { type: 'dark',
backgroundColor: '#23211d',
foregroundColor: '#d6d1c6' },
})
editor.openDocument({ documentId:
'/src/main.ts', text: MAIN_TS,
languageId: 'typescript' })
return editor
}
import { Editor } from
'@singapore-editor/core/editor'
import { MAIN_TS } from './sample'
export function
mountPlayground(element:
HTMLElement): Editor {
const editor = new Editor(element,
{
theme: { type: 'dark',
backgroundColor: '#23211d',
foregroundColor: '#d6d1c6' },
})
editor.openDocument({ documentId:
'/src/main.ts', text: MAIN_TS,
languageId: 'typescript' })
return editor
}
import { Editor } from
'@singapore-editor/core/editor'
import { MAIN_TS } from './sample'
export function mountPlayground(element:
HTMLElement): Editor {
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor:
'#23211d', foregroundColor: '#d6d1c6' },
})
editor.openDocument({ documentId: '/src/main.ts',
text: MAIN_TS, languageId: 'typescript' })
return editor
}
import { Editor } from
'@singapore-editor/core/editor'
import { MAIN_TS } from './sample'
export function mountPlayground(element:
HTMLElement): Editor {
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor:
'#23211d', foregroundColor: '#d6d1c6' },
})
editor.openDocument({ documentId: '/src/main.ts',
text: MAIN_TS, languageId: 'typescript' })
return editor
}
import { Editor } from '@singapore-editor/core/editor'
import { MAIN_TS } from './sample'
export function mountPlayground(element: HTMLElement): Editor {
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor: '#23211d',
foregroundColor: '#d6d1c6' },
})
editor.openDocument({ documentId: '/src/main.ts', text:
MAIN_TS, languageId: 'typescript' })
return editor
}
import { Editor } from '@singapore-editor/core/editor'
import { MAIN_TS } from './sample'
export function mountPlayground(element: HTMLElement): Editor {
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor: '#23211d',
foregroundColor: '#d6d1c6' },
})
editor.openDocument({ documentId: '/src/main.ts', text:
MAIN_TS, languageId: 'typescript' })
return editor
}
import { Editor } from '@singapore-editor/core/editor'
import { MAIN_TS } from './sample'
export function mountPlayground(element: HTMLElement): Editor {
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor: '#23211d', foregroundColor:
'#d6d1c6' },
})
editor.openDocument({ documentId: '/src/main.ts', text: MAIN_TS,
languageId: 'typescript' })
return editor
}
import { Editor } from '@singapore-editor/core/editor'
import { MAIN_TS } from './sample'
export function mountPlayground(element: HTMLElement): Editor {
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor: '#23211d', foregroundColor:
'#d6d1c6' },
})
editor.openDocument({ documentId: '/src/main.ts', text: MAIN_TS,
languageId: 'typescript' })
return editor
}
import { Editor } from '@singapore-editor/core/editor'
import { MAIN_TS } from './sample'
export function mountPlayground(element: HTMLElement): Editor {
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor: '#23211d', foregroundColor: '#d6d1c6'
},
})
editor.openDocument({ documentId: '/src/main.ts', text: MAIN_TS, languageId:
'typescript' })
return editor
}
import { Editor } from '@singapore-editor/core/editor'
import { MAIN_TS } from './sample'
export function mountPlayground(element: HTMLElement): Editor {
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor: '#23211d', foregroundColor: '#d6d1c6'
},
})
editor.openDocument({ documentId: '/src/main.ts', text: MAIN_TS, languageId:
'typescript' })
return editor
}
ts example
Scroll here to run this step.

The tree-sitter plugin parses the document in a worker and marks each word as a keyword, a string, a type and so on. The theme from step 2 colours them. TREE_SITTER_LANGUAGE_CONTRIBUTIONS registers the bundled grammars, and the TypeScript grammar downloads the first time a TypeScript document opens.

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'
import { MAIN_TS }
from './sample'
export function
mountPlayground(elemen
t: HTMLElement):
Editor {
const editor = new
Editor(element, {
theme: { type:
'dark',
backgroundColor:
'#23211d',
foregroundColor:
'#d6d1c6' },
plugins:
[createTreeSitterLangu
agePlugin(TREE_SITTER_
LANGUAGE_CONTRIBUTIONS
)],
})
editor.openDocument({
documentId:
'/src/main.ts', text:
MAIN_TS, languageId:
'typescript' })
return editor
}
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'
import { MAIN_TS }
from './sample'
export function
mountPlayground(elemen
t: HTMLElement):
Editor {
const editor = new
Editor(element, {
theme: { type:
'dark',
backgroundColor:
'#23211d',
foregroundColor:
'#d6d1c6' },
plugins:
[createTreeSitterLangu
agePlugin(TREE_SITTER_
LANGUAGE_CONTRIBUTIONS
)],
})
editor.openDocument({
documentId:
'/src/main.ts', text:
MAIN_TS, languageId:
'typescript' })
return editor
}
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'
import { MAIN_TS } from
'./sample'
export function
mountPlayground(element:
HTMLElement): Editor {
const editor = new
Editor(element, {
theme: { type: 'dark',
backgroundColor: '#23211d',
foregroundColor: '#d6d1c6'
},
plugins:
[createTreeSitterLanguagePlu
gin(TREE_SITTER_LANGUAGE_CON
TRIBUTIONS)],
})
editor.openDocument({
documentId: '/src/main.ts',
text: MAIN_TS, languageId:
'typescript' })
return editor
}
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'
import { MAIN_TS } from
'./sample'
export function
mountPlayground(element:
HTMLElement): Editor {
const editor = new
Editor(element, {
theme: { type: 'dark',
backgroundColor: '#23211d',
foregroundColor: '#d6d1c6'
},
plugins:
[createTreeSitterLanguagePlu
gin(TREE_SITTER_LANGUAGE_CON
TRIBUTIONS)],
})
editor.openDocument({
documentId: '/src/main.ts',
text: MAIN_TS, languageId:
'typescript' })
return editor
}
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'
import { MAIN_TS } from './sample'
export function
mountPlayground(element:
HTMLElement): Editor {
const editor = new Editor(element,
{
theme: { type: 'dark',
backgroundColor: '#23211d',
foregroundColor: '#d6d1c6' },
plugins:
[createTreeSitterLanguagePlugin(TREE
_SITTER_LANGUAGE_CONTRIBUTIONS)],
})
editor.openDocument({ documentId:
'/src/main.ts', text: MAIN_TS,
languageId: 'typescript' })
return editor
}
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'
import { MAIN_TS } from './sample'
export function
mountPlayground(element:
HTMLElement): Editor {
const editor = new Editor(element,
{
theme: { type: 'dark',
backgroundColor: '#23211d',
foregroundColor: '#d6d1c6' },
plugins:
[createTreeSitterLanguagePlugin(TREE
_SITTER_LANGUAGE_CONTRIBUTIONS)],
})
editor.openDocument({ documentId:
'/src/main.ts', text: MAIN_TS,
languageId: 'typescript' })
return editor
}
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'
import { MAIN_TS } from './sample'
export function mountPlayground(element:
HTMLElement): Editor {
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor:
'#23211d', foregroundColor: '#d6d1c6' },
plugins:
[createTreeSitterLanguagePlugin(TREE_SITTER_LANGUAG
E_CONTRIBUTIONS)],
})
editor.openDocument({ documentId: '/src/main.ts',
text: MAIN_TS, languageId: 'typescript' })
return editor
}
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'
import { MAIN_TS } from './sample'
export function mountPlayground(element:
HTMLElement): Editor {
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor:
'#23211d', foregroundColor: '#d6d1c6' },
plugins:
[createTreeSitterLanguagePlugin(TREE_SITTER_LANGUAG
E_CONTRIBUTIONS)],
})
editor.openDocument({ documentId: '/src/main.ts',
text: MAIN_TS, languageId: 'typescript' })
return editor
}
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'
import { MAIN_TS } from './sample'
export function mountPlayground(element: HTMLElement): Editor {
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor: '#23211d',
foregroundColor: '#d6d1c6' },
plugins:
[createTreeSitterLanguagePlugin(TREE_SITTER_LANGUAGE_CONTRIBUTION
S)],
})
editor.openDocument({ documentId: '/src/main.ts', text:
MAIN_TS, languageId: 'typescript' })
return editor
}
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'
import { MAIN_TS } from './sample'
export function mountPlayground(element: HTMLElement): Editor {
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor: '#23211d',
foregroundColor: '#d6d1c6' },
plugins:
[createTreeSitterLanguagePlugin(TREE_SITTER_LANGUAGE_CONTRIBUTION
S)],
})
editor.openDocument({ documentId: '/src/main.ts', text:
MAIN_TS, languageId: 'typescript' })
return editor
}
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'
import { MAIN_TS } from './sample'
export function mountPlayground(element: HTMLElement): Editor {
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor: '#23211d', foregroundColor:
'#d6d1c6' },
plugins:
[createTreeSitterLanguagePlugin(TREE_SITTER_LANGUAGE_CONTRIBUTIONS)],
})
editor.openDocument({ documentId: '/src/main.ts', text: MAIN_TS,
languageId: 'typescript' })
return editor
}
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'
import { MAIN_TS } from './sample'
export function mountPlayground(element: HTMLElement): Editor {
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor: '#23211d', foregroundColor:
'#d6d1c6' },
plugins:
[createTreeSitterLanguagePlugin(TREE_SITTER_LANGUAGE_CONTRIBUTIONS)],
})
editor.openDocument({ documentId: '/src/main.ts', text: MAIN_TS,
languageId: 'typescript' })
return editor
}
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'
import { MAIN_TS } from './sample'
export function mountPlayground(element: HTMLElement): Editor {
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor: '#23211d', foregroundColor: '#d6d1c6'
},
plugins: [createTreeSitterLanguagePlugin(TREE_SITTER_LANGUAGE_CONTRIBUTIONS)],
})
editor.openDocument({ documentId: '/src/main.ts', text: MAIN_TS, languageId:
'typescript' })
return editor
}
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'
import { MAIN_TS } from './sample'
export function mountPlayground(element: HTMLElement): Editor {
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor: '#23211d', foregroundColor: '#d6d1c6'
},
plugins: [createTreeSitterLanguagePlugin(TREE_SITTER_LANGUAGE_CONTRIBUTIONS)],
})
editor.openDocument({ documentId: '/src/main.ts', text: MAIN_TS, languageId:
'typescript' })
return editor
}
ts example
Scroll here to run this step.

The text appears at once and the colours arrive a moment later, after the worker parses the file.

Line numbers and search are two more plugins. Each brings its own styles.

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'
import {
createLineGutterPlugin
} from
'@singapore-editor/gut
ters'
import {
createEditorFindPlugin
} from
'@singapore-editor/fin
d'
import { MAIN_TS }
from './sample'
export function
mountPlayground(elemen
t: HTMLElement):
Editor {
const editor = new
Editor(element, {
theme: { type:
'dark',
backgroundColor:
'#23211d',
foregroundColor:
'#d6d1c6' },
plugins: [
createTreeSitterLangua
gePlugin(TREE_SITTER_L
ANGUAGE_CONTRIBUTIONS)
,
createLineGutterPlugin
(),
createEditorFindPlugin
(),
],
})
editor.openDocument({
documentId:
'/src/main.ts', text:
MAIN_TS, languageId:
'typescript' })
return editor
}
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'
import {
createLineGutterPlugin
} from
'@singapore-editor/gut
ters'
import {
createEditorFindPlugin
} from
'@singapore-editor/fin
d'
import { MAIN_TS }
from './sample'
export function
mountPlayground(elemen
t: HTMLElement):
Editor {
const editor = new
Editor(element, {
theme: { type:
'dark',
backgroundColor:
'#23211d',
foregroundColor:
'#d6d1c6' },
plugins: [
createTreeSitterLangua
gePlugin(TREE_SITTER_L
ANGUAGE_CONTRIBUTIONS)
,
createLineGutterPlugin
(),
createEditorFindPlugin
(),
],
})
editor.openDocument({
documentId:
'/src/main.ts', text:
MAIN_TS, languageId:
'typescript' })
return editor
}
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'
import {
createLineGutterPlugin }
from
'@singapore-editor/gutters'
import {
createEditorFindPlugin }
from
'@singapore-editor/find'
import { MAIN_TS } from
'./sample'
export function
mountPlayground(element:
HTMLElement): Editor {
const editor = new
Editor(element, {
theme: { type: 'dark',
backgroundColor: '#23211d',
foregroundColor: '#d6d1c6'
},
plugins: [
createTreeSitterLanguagePlug
in(TREE_SITTER_LANGUAGE_CONT
RIBUTIONS),
createLineGutterPlugin(),
createEditorFindPlugin(),
],
})
editor.openDocument({
documentId: '/src/main.ts',
text: MAIN_TS, languageId:
'typescript' })
return editor
}
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'
import {
createLineGutterPlugin }
from
'@singapore-editor/gutters'
import {
createEditorFindPlugin }
from
'@singapore-editor/find'
import { MAIN_TS } from
'./sample'
export function
mountPlayground(element:
HTMLElement): Editor {
const editor = new
Editor(element, {
theme: { type: 'dark',
backgroundColor: '#23211d',
foregroundColor: '#d6d1c6'
},
plugins: [
createTreeSitterLanguagePlug
in(TREE_SITTER_LANGUAGE_CONT
RIBUTIONS),
createLineGutterPlugin(),
createEditorFindPlugin(),
],
})
editor.openDocument({
documentId: '/src/main.ts',
text: MAIN_TS, languageId:
'typescript' })
return editor
}
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'
import { createLineGutterPlugin }
from '@singapore-editor/gutters'
import { createEditorFindPlugin }
from '@singapore-editor/find'
import { MAIN_TS } from './sample'
export function
mountPlayground(element:
HTMLElement): Editor {
const editor = new Editor(element,
{
theme: { type: 'dark',
backgroundColor: '#23211d',
foregroundColor: '#d6d1c6' },
plugins: [
createTreeSitterLanguagePlugin(TREE_
SITTER_LANGUAGE_CONTRIBUTIONS),
createLineGutterPlugin(),
createEditorFindPlugin(),
],
})
editor.openDocument({ documentId:
'/src/main.ts', text: MAIN_TS,
languageId: 'typescript' })
return editor
}
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'
import { createLineGutterPlugin }
from '@singapore-editor/gutters'
import { createEditorFindPlugin }
from '@singapore-editor/find'
import { MAIN_TS } from './sample'
export function
mountPlayground(element:
HTMLElement): Editor {
const editor = new Editor(element,
{
theme: { type: 'dark',
backgroundColor: '#23211d',
foregroundColor: '#d6d1c6' },
plugins: [
createTreeSitterLanguagePlugin(TREE_
SITTER_LANGUAGE_CONTRIBUTIONS),
createLineGutterPlugin(),
createEditorFindPlugin(),
],
})
editor.openDocument({ documentId:
'/src/main.ts', text: MAIN_TS,
languageId: 'typescript' })
return editor
}
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'
import { createLineGutterPlugin } from
'@singapore-editor/gutters'
import { createEditorFindPlugin } from
'@singapore-editor/find'
import { MAIN_TS } from './sample'
export function mountPlayground(element:
HTMLElement): Editor {
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor:
'#23211d', foregroundColor: '#d6d1c6' },
plugins: [
createTreeSitterLanguagePlugin(TREE_SITTER_LANGUAGE
_CONTRIBUTIONS),
createLineGutterPlugin(),
createEditorFindPlugin(),
],
})
editor.openDocument({ documentId: '/src/main.ts',
text: MAIN_TS, languageId: 'typescript' })
return editor
}
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'
import { createLineGutterPlugin } from
'@singapore-editor/gutters'
import { createEditorFindPlugin } from
'@singapore-editor/find'
import { MAIN_TS } from './sample'
export function mountPlayground(element:
HTMLElement): Editor {
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor:
'#23211d', foregroundColor: '#d6d1c6' },
plugins: [
createTreeSitterLanguagePlugin(TREE_SITTER_LANGUAGE
_CONTRIBUTIONS),
createLineGutterPlugin(),
createEditorFindPlugin(),
],
})
editor.openDocument({ documentId: '/src/main.ts',
text: MAIN_TS, languageId: 'typescript' })
return editor
}
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'
import { createLineGutterPlugin } from
'@singapore-editor/gutters'
import { createEditorFindPlugin } from '@singapore-editor/find'
import { MAIN_TS } from './sample'
export function mountPlayground(element: HTMLElement): Editor {
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor: '#23211d',
foregroundColor: '#d6d1c6' },
plugins: [
createTreeSitterLanguagePlugin(TREE_SITTER_LANGUAGE_CONTRIBUTIONS
),
createLineGutterPlugin(),
createEditorFindPlugin(),
],
})
editor.openDocument({ documentId: '/src/main.ts', text:
MAIN_TS, languageId: 'typescript' })
return editor
}
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'
import { createLineGutterPlugin } from
'@singapore-editor/gutters'
import { createEditorFindPlugin } from '@singapore-editor/find'
import { MAIN_TS } from './sample'
export function mountPlayground(element: HTMLElement): Editor {
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor: '#23211d',
foregroundColor: '#d6d1c6' },
plugins: [
createTreeSitterLanguagePlugin(TREE_SITTER_LANGUAGE_CONTRIBUTIONS
),
createLineGutterPlugin(),
createEditorFindPlugin(),
],
})
editor.openDocument({ documentId: '/src/main.ts', text:
MAIN_TS, languageId: 'typescript' })
return editor
}
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'
import { createLineGutterPlugin } from '@singapore-editor/gutters'
import { createEditorFindPlugin } from '@singapore-editor/find'
import { MAIN_TS } from './sample'
export function mountPlayground(element: HTMLElement): Editor {
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor: '#23211d', foregroundColor:
'#d6d1c6' },
plugins: [
createTreeSitterLanguagePlugin(TREE_SITTER_LANGUAGE_CONTRIBUTIONS),
createLineGutterPlugin(),
createEditorFindPlugin(),
],
})
editor.openDocument({ documentId: '/src/main.ts', text: MAIN_TS,
languageId: 'typescript' })
return editor
}
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'
import { createLineGutterPlugin } from '@singapore-editor/gutters'
import { createEditorFindPlugin } from '@singapore-editor/find'
import { MAIN_TS } from './sample'
export function mountPlayground(element: HTMLElement): Editor {
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor: '#23211d', foregroundColor:
'#d6d1c6' },
plugins: [
createTreeSitterLanguagePlugin(TREE_SITTER_LANGUAGE_CONTRIBUTIONS),
createLineGutterPlugin(),
createEditorFindPlugin(),
],
})
editor.openDocument({ documentId: '/src/main.ts', text: MAIN_TS,
languageId: 'typescript' })
return editor
}
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'
import { createLineGutterPlugin } from '@singapore-editor/gutters'
import { createEditorFindPlugin } from '@singapore-editor/find'
import { MAIN_TS } from './sample'
export function mountPlayground(element: HTMLElement): Editor {
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor: '#23211d', foregroundColor: '#d6d1c6'
},
plugins: [
createTreeSitterLanguagePlugin(TREE_SITTER_LANGUAGE_CONTRIBUTIONS),
createLineGutterPlugin(),
createEditorFindPlugin(),
],
})
editor.openDocument({ documentId: '/src/main.ts', text: MAIN_TS, languageId:
'typescript' })
return editor
}
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'
import { createLineGutterPlugin } from '@singapore-editor/gutters'
import { createEditorFindPlugin } from '@singapore-editor/find'
import { MAIN_TS } from './sample'
export function mountPlayground(element: HTMLElement): Editor {
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor: '#23211d', foregroundColor: '#d6d1c6'
},
plugins: [
createTreeSitterLanguagePlugin(TREE_SITTER_LANGUAGE_CONTRIBUTIONS),
createLineGutterPlugin(),
createEditorFindPlugin(),
],
})
editor.openDocument({ documentId: '/src/main.ts', text: MAIN_TS, languageId:
'typescript' })
return editor
}
ts example
Scroll here to run this step.

Click into the editor and press Ctrl+F, or Cmd+F on a Mac, to search the file.

createTypeScriptLspPlugin runs TypeScript in a worker inside the page, with no server. setWorkspaceFiles gives it the files the document imports, so ./math resolves.

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'
import {
createLineGutterPlugin
} from
'@singapore-editor/gut
ters'
import {
createEditorFindPlugin
} from
'@singapore-editor/fin
d'
import {
createTypeScriptLspPlu
gin } from
'@singapore-editor/typ
escript-lsp'
import { MAIN_TS,
MATH_TS } from
'./sample'
export function
mountPlayground(elemen
t: HTMLElement):
Editor {
const typescript =
createTypeScriptLspPlu
gin()
typescript.setWorkspac
eFiles([{ path:
'/src/math.ts', text:
MATH_TS }])
const editor = new
Editor(element, {
theme: { type:
'dark',
backgroundColor:
'#23211d',
foregroundColor:
'#d6d1c6' },
plugins: [
createTreeSitterLangua
gePlugin(TREE_SITTER_L
ANGUAGE_CONTRIBUTIONS)
,
createLineGutterPlugin
(),
createEditorFindPlugin
(),
typescript,
],
})
editor.openDocument({
documentId:
'/src/main.ts', text:
MAIN_TS, languageId:
'typescript' })
return editor
}
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'
import {
createLineGutterPlugin
} from
'@singapore-editor/gut
ters'
import {
createEditorFindPlugin
} from
'@singapore-editor/fin
d'
import {
createTypeScriptLspPlu
gin } from
'@singapore-editor/typ
escript-lsp'
import { MAIN_TS,
MATH_TS } from
'./sample'
export function
mountPlayground(elemen
t: HTMLElement):
Editor {
const typescript =
createTypeScriptLspPlu
gin()
typescript.setWorkspac
eFiles([{ path:
'/src/math.ts', text:
MATH_TS }])
const editor = new
Editor(element, {
theme: { type:
'dark',
backgroundColor:
'#23211d',
foregroundColor:
'#d6d1c6' },
plugins: [
createTreeSitterLangua
gePlugin(TREE_SITTER_L
ANGUAGE_CONTRIBUTIONS)
,
createLineGutterPlugin
(),
createEditorFindPlugin
(),
typescript,
],
})
editor.openDocument({
documentId:
'/src/main.ts', text:
MAIN_TS, languageId:
'typescript' })
return editor
}
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'
import {
createLineGutterPlugin }
from
'@singapore-editor/gutters'
import {
createEditorFindPlugin }
from
'@singapore-editor/find'
import {
createTypeScriptLspPlugin }
from
'@singapore-editor/typescrip
t-lsp'
import { MAIN_TS, MATH_TS }
from './sample'
export function
mountPlayground(element:
HTMLElement): Editor {
const typescript =
createTypeScriptLspPlugin()
typescript.setWorkspaceFiles
([{ path: '/src/math.ts',
text: MATH_TS }])
const editor = new
Editor(element, {
theme: { type: 'dark',
backgroundColor: '#23211d',
foregroundColor: '#d6d1c6'
},
plugins: [
createTreeSitterLanguagePlug
in(TREE_SITTER_LANGUAGE_CONT
RIBUTIONS),
createLineGutterPlugin(),
createEditorFindPlugin(),
typescript,
],
})
editor.openDocument({
documentId: '/src/main.ts',
text: MAIN_TS, languageId:
'typescript' })
return editor
}
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'
import {
createLineGutterPlugin }
from
'@singapore-editor/gutters'
import {
createEditorFindPlugin }
from
'@singapore-editor/find'
import {
createTypeScriptLspPlugin }
from
'@singapore-editor/typescrip
t-lsp'
import { MAIN_TS, MATH_TS }
from './sample'
export function
mountPlayground(element:
HTMLElement): Editor {
const typescript =
createTypeScriptLspPlugin()
typescript.setWorkspaceFiles
([{ path: '/src/math.ts',
text: MATH_TS }])
const editor = new
Editor(element, {
theme: { type: 'dark',
backgroundColor: '#23211d',
foregroundColor: '#d6d1c6'
},
plugins: [
createTreeSitterLanguagePlug
in(TREE_SITTER_LANGUAGE_CONT
RIBUTIONS),
createLineGutterPlugin(),
createEditorFindPlugin(),
typescript,
],
})
editor.openDocument({
documentId: '/src/main.ts',
text: MAIN_TS, languageId:
'typescript' })
return editor
}
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'
import { createLineGutterPlugin }
from '@singapore-editor/gutters'
import { createEditorFindPlugin }
from '@singapore-editor/find'
import { createTypeScriptLspPlugin }
from
'@singapore-editor/typescript-lsp'
import { MAIN_TS, MATH_TS } from
'./sample'
export function
mountPlayground(element:
HTMLElement): Editor {
const typescript =
createTypeScriptLspPlugin()
typescript.setWorkspaceFiles([{
path: '/src/math.ts', text: MATH_TS
}])
const editor = new Editor(element,
{
theme: { type: 'dark',
backgroundColor: '#23211d',
foregroundColor: '#d6d1c6' },
plugins: [
createTreeSitterLanguagePlugin(TREE_
SITTER_LANGUAGE_CONTRIBUTIONS),
createLineGutterPlugin(),
createEditorFindPlugin(),
typescript,
],
})
editor.openDocument({ documentId:
'/src/main.ts', text: MAIN_TS,
languageId: 'typescript' })
return editor
}
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'
import { createLineGutterPlugin }
from '@singapore-editor/gutters'
import { createEditorFindPlugin }
from '@singapore-editor/find'
import { createTypeScriptLspPlugin }
from
'@singapore-editor/typescript-lsp'
import { MAIN_TS, MATH_TS } from
'./sample'
export function
mountPlayground(element:
HTMLElement): Editor {
const typescript =
createTypeScriptLspPlugin()
typescript.setWorkspaceFiles([{
path: '/src/math.ts', text: MATH_TS
}])
const editor = new Editor(element,
{
theme: { type: 'dark',
backgroundColor: '#23211d',
foregroundColor: '#d6d1c6' },
plugins: [
createTreeSitterLanguagePlugin(TREE_
SITTER_LANGUAGE_CONTRIBUTIONS),
createLineGutterPlugin(),
createEditorFindPlugin(),
typescript,
],
})
editor.openDocument({ documentId:
'/src/main.ts', text: MAIN_TS,
languageId: 'typescript' })
return editor
}
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'
import { createLineGutterPlugin } from
'@singapore-editor/gutters'
import { createEditorFindPlugin } from
'@singapore-editor/find'
import { createTypeScriptLspPlugin } from
'@singapore-editor/typescript-lsp'
import { MAIN_TS, MATH_TS } from './sample'
export function mountPlayground(element:
HTMLElement): Editor {
const typescript = createTypeScriptLspPlugin()
typescript.setWorkspaceFiles([{ path:
'/src/math.ts', text: MATH_TS }])
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor:
'#23211d', foregroundColor: '#d6d1c6' },
plugins: [
createTreeSitterLanguagePlugin(TREE_SITTER_LANGUAGE
_CONTRIBUTIONS),
createLineGutterPlugin(),
createEditorFindPlugin(),
typescript,
],
})
editor.openDocument({ documentId: '/src/main.ts',
text: MAIN_TS, languageId: 'typescript' })
return editor
}
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'
import { createLineGutterPlugin } from
'@singapore-editor/gutters'
import { createEditorFindPlugin } from
'@singapore-editor/find'
import { createTypeScriptLspPlugin } from
'@singapore-editor/typescript-lsp'
import { MAIN_TS, MATH_TS } from './sample'
export function mountPlayground(element:
HTMLElement): Editor {
const typescript = createTypeScriptLspPlugin()
typescript.setWorkspaceFiles([{ path:
'/src/math.ts', text: MATH_TS }])
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor:
'#23211d', foregroundColor: '#d6d1c6' },
plugins: [
createTreeSitterLanguagePlugin(TREE_SITTER_LANGUAGE
_CONTRIBUTIONS),
createLineGutterPlugin(),
createEditorFindPlugin(),
typescript,
],
})
editor.openDocument({ documentId: '/src/main.ts',
text: MAIN_TS, languageId: 'typescript' })
return editor
}
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'
import { createLineGutterPlugin } from
'@singapore-editor/gutters'
import { createEditorFindPlugin } from '@singapore-editor/find'
import { createTypeScriptLspPlugin } from
'@singapore-editor/typescript-lsp'
import { MAIN_TS, MATH_TS } from './sample'
export function mountPlayground(element: HTMLElement): Editor {
const typescript = createTypeScriptLspPlugin()
typescript.setWorkspaceFiles([{ path: '/src/math.ts', text:
MATH_TS }])
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor: '#23211d',
foregroundColor: '#d6d1c6' },
plugins: [
createTreeSitterLanguagePlugin(TREE_SITTER_LANGUAGE_CONTRIBUTIONS
),
createLineGutterPlugin(),
createEditorFindPlugin(),
typescript,
],
})
editor.openDocument({ documentId: '/src/main.ts', text:
MAIN_TS, languageId: 'typescript' })
return editor
}
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'
import { createLineGutterPlugin } from
'@singapore-editor/gutters'
import { createEditorFindPlugin } from '@singapore-editor/find'
import { createTypeScriptLspPlugin } from
'@singapore-editor/typescript-lsp'
import { MAIN_TS, MATH_TS } from './sample'
export function mountPlayground(element: HTMLElement): Editor {
const typescript = createTypeScriptLspPlugin()
typescript.setWorkspaceFiles([{ path: '/src/math.ts', text:
MATH_TS }])
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor: '#23211d',
foregroundColor: '#d6d1c6' },
plugins: [
createTreeSitterLanguagePlugin(TREE_SITTER_LANGUAGE_CONTRIBUTIONS
),
createLineGutterPlugin(),
createEditorFindPlugin(),
typescript,
],
})
editor.openDocument({ documentId: '/src/main.ts', text:
MAIN_TS, languageId: 'typescript' })
return editor
}
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'
import { createLineGutterPlugin } from '@singapore-editor/gutters'
import { createEditorFindPlugin } from '@singapore-editor/find'
import { createTypeScriptLspPlugin } from '@singapore-editor/typescript-lsp'
import { MAIN_TS, MATH_TS } from './sample'
export function mountPlayground(element: HTMLElement): Editor {
const typescript = createTypeScriptLspPlugin()
typescript.setWorkspaceFiles([{ path: '/src/math.ts', text: MATH_TS }])
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor: '#23211d', foregroundColor:
'#d6d1c6' },
plugins: [
createTreeSitterLanguagePlugin(TREE_SITTER_LANGUAGE_CONTRIBUTIONS),
createLineGutterPlugin(),
createEditorFindPlugin(),
typescript,
],
})
editor.openDocument({ documentId: '/src/main.ts', text: MAIN_TS,
languageId: 'typescript' })
return editor
}
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'
import { createLineGutterPlugin } from '@singapore-editor/gutters'
import { createEditorFindPlugin } from '@singapore-editor/find'
import { createTypeScriptLspPlugin } from '@singapore-editor/typescript-lsp'
import { MAIN_TS, MATH_TS } from './sample'
export function mountPlayground(element: HTMLElement): Editor {
const typescript = createTypeScriptLspPlugin()
typescript.setWorkspaceFiles([{ path: '/src/math.ts', text: MATH_TS }])
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor: '#23211d', foregroundColor:
'#d6d1c6' },
plugins: [
createTreeSitterLanguagePlugin(TREE_SITTER_LANGUAGE_CONTRIBUTIONS),
createLineGutterPlugin(),
createEditorFindPlugin(),
typescript,
],
})
editor.openDocument({ documentId: '/src/main.ts', text: MAIN_TS,
languageId: 'typescript' })
return editor
}
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'
import { createLineGutterPlugin } from '@singapore-editor/gutters'
import { createEditorFindPlugin } from '@singapore-editor/find'
import { createTypeScriptLspPlugin } from '@singapore-editor/typescript-lsp'
import { MAIN_TS, MATH_TS } from './sample'
export function mountPlayground(element: HTMLElement): Editor {
const typescript = createTypeScriptLspPlugin()
typescript.setWorkspaceFiles([{ path: '/src/math.ts', text: MATH_TS }])
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor: '#23211d', foregroundColor: '#d6d1c6'
},
plugins: [
createTreeSitterLanguagePlugin(TREE_SITTER_LANGUAGE_CONTRIBUTIONS),
createLineGutterPlugin(),
createEditorFindPlugin(),
typescript,
],
})
editor.openDocument({ documentId: '/src/main.ts', text: MAIN_TS, languageId:
'typescript' })
return editor
}
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'
import { createLineGutterPlugin } from '@singapore-editor/gutters'
import { createEditorFindPlugin } from '@singapore-editor/find'
import { createTypeScriptLspPlugin } from '@singapore-editor/typescript-lsp'
import { MAIN_TS, MATH_TS } from './sample'
export function mountPlayground(element: HTMLElement): Editor {
const typescript = createTypeScriptLspPlugin()
typescript.setWorkspaceFiles([{ path: '/src/math.ts', text: MATH_TS }])
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor: '#23211d', foregroundColor: '#d6d1c6'
},
plugins: [
createTreeSitterLanguagePlugin(TREE_SITTER_LANGUAGE_CONTRIBUTIONS),
createLineGutterPlugin(),
createEditorFindPlugin(),
typescript,
],
})
editor.openDocument({ documentId: '/src/main.ts', text: MAIN_TS, languageId:
'typescript' })
return editor
}
ts example
Scroll here to run this step.

The worker downloads TypeScript and its standard library on first use, so diagnostics appear a few seconds after the text. Then try it:

  • Line 4 is underlined, because twice takes a number. Change 'two' to 2 and the error goes away.
  • Hover over twice to see its type.
  • Type orders[0]. on a new line to get completions.

The minimap draws the whole document beside the text. Drag it to scroll.

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'
import {
createLineGutterPlugin
} from
'@singapore-editor/gut
ters'
import {
createEditorFindPlugin
} from
'@singapore-editor/fin
d'
import {
createTypeScriptLspPlu
gin } from
'@singapore-editor/typ
escript-lsp'
import {
createMinimapPlugin }
from
'@singapore-editor/min
imap'
import { MAIN_TS,
MATH_TS } from
'./sample'
export function
mountPlayground(elemen
t: HTMLElement):
Editor {
const typescript =
createTypeScriptLspPlu
gin()
typescript.setWorkspac
eFiles([{ path:
'/src/math.ts', text:
MATH_TS }])
const editor = new
Editor(element, {
theme: { type:
'dark',
backgroundColor:
'#23211d',
foregroundColor:
'#d6d1c6' },
plugins: [
createTreeSitterLangua
gePlugin(TREE_SITTER_L
ANGUAGE_CONTRIBUTIONS)
,
createLineGutterPlugin
(),
createEditorFindPlugin
(),
typescript,
createMinimapPlugin(),
],
})
editor.openDocument({
documentId:
'/src/main.ts', text:
MAIN_TS, languageId:
'typescript' })
return editor
}
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'
import {
createLineGutterPlugin
} from
'@singapore-editor/gut
ters'
import {
createEditorFindPlugin
} from
'@singapore-editor/fin
d'
import {
createTypeScriptLspPlu
gin } from
'@singapore-editor/typ
escript-lsp'
import {
createMinimapPlugin }
from
'@singapore-editor/min
imap'
import { MAIN_TS,
MATH_TS } from
'./sample'
export function
mountPlayground(elemen
t: HTMLElement):
Editor {
const typescript =
createTypeScriptLspPlu
gin()
typescript.setWorkspac
eFiles([{ path:
'/src/math.ts', text:
MATH_TS }])
const editor = new
Editor(element, {
theme: { type:
'dark',
backgroundColor:
'#23211d',
foregroundColor:
'#d6d1c6' },
plugins: [
createTreeSitterLangua
gePlugin(TREE_SITTER_L
ANGUAGE_CONTRIBUTIONS)
,
createLineGutterPlugin
(),
createEditorFindPlugin
(),
typescript,
createMinimapPlugin(),
],
})
editor.openDocument({
documentId:
'/src/main.ts', text:
MAIN_TS, languageId:
'typescript' })
return editor
}
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'
import {
createLineGutterPlugin }
from
'@singapore-editor/gutters'
import {
createEditorFindPlugin }
from
'@singapore-editor/find'
import {
createTypeScriptLspPlugin }
from
'@singapore-editor/typescrip
t-lsp'
import { createMinimapPlugin
} from
'@singapore-editor/minimap'
import { MAIN_TS, MATH_TS }
from './sample'
export function
mountPlayground(element:
HTMLElement): Editor {
const typescript =
createTypeScriptLspPlugin()
typescript.setWorkspaceFiles
([{ path: '/src/math.ts',
text: MATH_TS }])
const editor = new
Editor(element, {
theme: { type: 'dark',
backgroundColor: '#23211d',
foregroundColor: '#d6d1c6'
},
plugins: [
createTreeSitterLanguagePlug
in(TREE_SITTER_LANGUAGE_CONT
RIBUTIONS),
createLineGutterPlugin(),
createEditorFindPlugin(),
typescript,
createMinimapPlugin(),
],
})
editor.openDocument({
documentId: '/src/main.ts',
text: MAIN_TS, languageId:
'typescript' })
return editor
}
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'
import {
createLineGutterPlugin }
from
'@singapore-editor/gutters'
import {
createEditorFindPlugin }
from
'@singapore-editor/find'
import {
createTypeScriptLspPlugin }
from
'@singapore-editor/typescrip
t-lsp'
import { createMinimapPlugin
} from
'@singapore-editor/minimap'
import { MAIN_TS, MATH_TS }
from './sample'
export function
mountPlayground(element:
HTMLElement): Editor {
const typescript =
createTypeScriptLspPlugin()
typescript.setWorkspaceFiles
([{ path: '/src/math.ts',
text: MATH_TS }])
const editor = new
Editor(element, {
theme: { type: 'dark',
backgroundColor: '#23211d',
foregroundColor: '#d6d1c6'
},
plugins: [
createTreeSitterLanguagePlug
in(TREE_SITTER_LANGUAGE_CONT
RIBUTIONS),
createLineGutterPlugin(),
createEditorFindPlugin(),
typescript,
createMinimapPlugin(),
],
})
editor.openDocument({
documentId: '/src/main.ts',
text: MAIN_TS, languageId:
'typescript' })
return editor
}
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'
import { createLineGutterPlugin }
from '@singapore-editor/gutters'
import { createEditorFindPlugin }
from '@singapore-editor/find'
import { createTypeScriptLspPlugin }
from
'@singapore-editor/typescript-lsp'
import { createMinimapPlugin } from
'@singapore-editor/minimap'
import { MAIN_TS, MATH_TS } from
'./sample'
export function
mountPlayground(element:
HTMLElement): Editor {
const typescript =
createTypeScriptLspPlugin()
typescript.setWorkspaceFiles([{
path: '/src/math.ts', text: MATH_TS
}])
const editor = new Editor(element,
{
theme: { type: 'dark',
backgroundColor: '#23211d',
foregroundColor: '#d6d1c6' },
plugins: [
createTreeSitterLanguagePlugin(TREE_
SITTER_LANGUAGE_CONTRIBUTIONS),
createLineGutterPlugin(),
createEditorFindPlugin(),
typescript,
createMinimapPlugin(),
],
})
editor.openDocument({ documentId:
'/src/main.ts', text: MAIN_TS,
languageId: 'typescript' })
return editor
}
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'
import { createLineGutterPlugin }
from '@singapore-editor/gutters'
import { createEditorFindPlugin }
from '@singapore-editor/find'
import { createTypeScriptLspPlugin }
from
'@singapore-editor/typescript-lsp'
import { createMinimapPlugin } from
'@singapore-editor/minimap'
import { MAIN_TS, MATH_TS } from
'./sample'
export function
mountPlayground(element:
HTMLElement): Editor {
const typescript =
createTypeScriptLspPlugin()
typescript.setWorkspaceFiles([{
path: '/src/math.ts', text: MATH_TS
}])
const editor = new Editor(element,
{
theme: { type: 'dark',
backgroundColor: '#23211d',
foregroundColor: '#d6d1c6' },
plugins: [
createTreeSitterLanguagePlugin(TREE_
SITTER_LANGUAGE_CONTRIBUTIONS),
createLineGutterPlugin(),
createEditorFindPlugin(),
typescript,
createMinimapPlugin(),
],
})
editor.openDocument({ documentId:
'/src/main.ts', text: MAIN_TS,
languageId: 'typescript' })
return editor
}
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'
import { createLineGutterPlugin } from
'@singapore-editor/gutters'
import { createEditorFindPlugin } from
'@singapore-editor/find'
import { createTypeScriptLspPlugin } from
'@singapore-editor/typescript-lsp'
import { createMinimapPlugin } from
'@singapore-editor/minimap'
import { MAIN_TS, MATH_TS } from './sample'
export function mountPlayground(element:
HTMLElement): Editor {
const typescript = createTypeScriptLspPlugin()
typescript.setWorkspaceFiles([{ path:
'/src/math.ts', text: MATH_TS }])
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor:
'#23211d', foregroundColor: '#d6d1c6' },
plugins: [
createTreeSitterLanguagePlugin(TREE_SITTER_LANGUAGE
_CONTRIBUTIONS),
createLineGutterPlugin(),
createEditorFindPlugin(),
typescript,
createMinimapPlugin(),
],
})
editor.openDocument({ documentId: '/src/main.ts',
text: MAIN_TS, languageId: 'typescript' })
return editor
}
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'
import { createLineGutterPlugin } from
'@singapore-editor/gutters'
import { createEditorFindPlugin } from
'@singapore-editor/find'
import { createTypeScriptLspPlugin } from
'@singapore-editor/typescript-lsp'
import { createMinimapPlugin } from
'@singapore-editor/minimap'
import { MAIN_TS, MATH_TS } from './sample'
export function mountPlayground(element:
HTMLElement): Editor {
const typescript = createTypeScriptLspPlugin()
typescript.setWorkspaceFiles([{ path:
'/src/math.ts', text: MATH_TS }])
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor:
'#23211d', foregroundColor: '#d6d1c6' },
plugins: [
createTreeSitterLanguagePlugin(TREE_SITTER_LANGUAGE
_CONTRIBUTIONS),
createLineGutterPlugin(),
createEditorFindPlugin(),
typescript,
createMinimapPlugin(),
],
})
editor.openDocument({ documentId: '/src/main.ts',
text: MAIN_TS, languageId: 'typescript' })
return editor
}
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'
import { createLineGutterPlugin } from
'@singapore-editor/gutters'
import { createEditorFindPlugin } from '@singapore-editor/find'
import { createTypeScriptLspPlugin } from
'@singapore-editor/typescript-lsp'
import { createMinimapPlugin } from '@singapore-editor/minimap'
import { MAIN_TS, MATH_TS } from './sample'
export function mountPlayground(element: HTMLElement): Editor {
const typescript = createTypeScriptLspPlugin()
typescript.setWorkspaceFiles([{ path: '/src/math.ts', text:
MATH_TS }])
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor: '#23211d',
foregroundColor: '#d6d1c6' },
plugins: [
createTreeSitterLanguagePlugin(TREE_SITTER_LANGUAGE_CONTRIBUTIONS
),
createLineGutterPlugin(),
createEditorFindPlugin(),
typescript,
createMinimapPlugin(),
],
})
editor.openDocument({ documentId: '/src/main.ts', text:
MAIN_TS, languageId: 'typescript' })
return editor
}
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'
import { createLineGutterPlugin } from
'@singapore-editor/gutters'
import { createEditorFindPlugin } from '@singapore-editor/find'
import { createTypeScriptLspPlugin } from
'@singapore-editor/typescript-lsp'
import { createMinimapPlugin } from '@singapore-editor/minimap'
import { MAIN_TS, MATH_TS } from './sample'
export function mountPlayground(element: HTMLElement): Editor {
const typescript = createTypeScriptLspPlugin()
typescript.setWorkspaceFiles([{ path: '/src/math.ts', text:
MATH_TS }])
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor: '#23211d',
foregroundColor: '#d6d1c6' },
plugins: [
createTreeSitterLanguagePlugin(TREE_SITTER_LANGUAGE_CONTRIBUTIONS
),
createLineGutterPlugin(),
createEditorFindPlugin(),
typescript,
createMinimapPlugin(),
],
})
editor.openDocument({ documentId: '/src/main.ts', text:
MAIN_TS, languageId: 'typescript' })
return editor
}
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'
import { createLineGutterPlugin } from '@singapore-editor/gutters'
import { createEditorFindPlugin } from '@singapore-editor/find'
import { createTypeScriptLspPlugin } from '@singapore-editor/typescript-lsp'
import { createMinimapPlugin } from '@singapore-editor/minimap'
import { MAIN_TS, MATH_TS } from './sample'
export function mountPlayground(element: HTMLElement): Editor {
const typescript = createTypeScriptLspPlugin()
typescript.setWorkspaceFiles([{ path: '/src/math.ts', text: MATH_TS }])
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor: '#23211d', foregroundColor:
'#d6d1c6' },
plugins: [
createTreeSitterLanguagePlugin(TREE_SITTER_LANGUAGE_CONTRIBUTIONS),
createLineGutterPlugin(),
createEditorFindPlugin(),
typescript,
createMinimapPlugin(),
],
})
editor.openDocument({ documentId: '/src/main.ts', text: MAIN_TS,
languageId: 'typescript' })
return editor
}
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'
import { createLineGutterPlugin } from '@singapore-editor/gutters'
import { createEditorFindPlugin } from '@singapore-editor/find'
import { createTypeScriptLspPlugin } from '@singapore-editor/typescript-lsp'
import { createMinimapPlugin } from '@singapore-editor/minimap'
import { MAIN_TS, MATH_TS } from './sample'
export function mountPlayground(element: HTMLElement): Editor {
const typescript = createTypeScriptLspPlugin()
typescript.setWorkspaceFiles([{ path: '/src/math.ts', text: MATH_TS }])
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor: '#23211d', foregroundColor:
'#d6d1c6' },
plugins: [
createTreeSitterLanguagePlugin(TREE_SITTER_LANGUAGE_CONTRIBUTIONS),
createLineGutterPlugin(),
createEditorFindPlugin(),
typescript,
createMinimapPlugin(),
],
})
editor.openDocument({ documentId: '/src/main.ts', text: MAIN_TS,
languageId: 'typescript' })
return editor
}
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'
import { createLineGutterPlugin } from '@singapore-editor/gutters'
import { createEditorFindPlugin } from '@singapore-editor/find'
import { createTypeScriptLspPlugin } from '@singapore-editor/typescript-lsp'
import { createMinimapPlugin } from '@singapore-editor/minimap'
import { MAIN_TS, MATH_TS } from './sample'
export function mountPlayground(element: HTMLElement): Editor {
const typescript = createTypeScriptLspPlugin()
typescript.setWorkspaceFiles([{ path: '/src/math.ts', text: MATH_TS }])
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor: '#23211d', foregroundColor: '#d6d1c6'
},
plugins: [
createTreeSitterLanguagePlugin(TREE_SITTER_LANGUAGE_CONTRIBUTIONS),
createLineGutterPlugin(),
createEditorFindPlugin(),
typescript,
createMinimapPlugin(),
],
})
editor.openDocument({ documentId: '/src/main.ts', text: MAIN_TS, languageId:
'typescript' })
return editor
}
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'
import { createLineGutterPlugin } from '@singapore-editor/gutters'
import { createEditorFindPlugin } from '@singapore-editor/find'
import { createTypeScriptLspPlugin } from '@singapore-editor/typescript-lsp'
import { createMinimapPlugin } from '@singapore-editor/minimap'
import { MAIN_TS, MATH_TS } from './sample'
export function mountPlayground(element: HTMLElement): Editor {
const typescript = createTypeScriptLspPlugin()
typescript.setWorkspaceFiles([{ path: '/src/math.ts', text: MATH_TS }])
const editor = new Editor(element, {
theme: { type: 'dark', backgroundColor: '#23211d', foregroundColor: '#d6d1c6'
},
plugins: [
createTreeSitterLanguagePlugin(TREE_SITTER_LANGUAGE_CONTRIBUTIONS),
createLineGutterPlugin(),
createEditorFindPlugin(),
typescript,
createMinimapPlugin(),
],
})
editor.openDocument({ documentId: '/src/main.ts', text: MAIN_TS, languageId:
'typescript' })
return editor
}
ts example
Scroll here to run this step.

That is the finished playground. Keep the returned editor and call editor.dispose() when the view closes, which also stops its workers.

  • Bundling and workers covers serving the worker and WebAssembly files in production.
  • Language servers connects the editor to a server process instead of an in-page worker.
  • The full demo is a larger application on the same packages. It loads this repository through the GitHub API into a file tree, so you can open and edit any of its files.