# @kunstmusik/codemirror-lang-csound

> CodeMirror 6 language support for Csound (CSD, ORC, SCO)

Latest version **1.0.3** (published 2026-09-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install @kunstmusik/codemirror-lang-csound
pnpm add @kunstmusik/codemirror-lang-csound
yarn add @kunstmusik/codemirror-lang-csound
bun add @kunstmusik/codemirror-lang-csound
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2026-09-23 |
| First published | 2026-04-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 7 |
| Unpacked size | 7.4 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | kunstmusik |
| Keywords | codemirror, codemirror6, csound, lezer, music, editor |

## Links

- npm: https://www.npmjs.com/package/@kunstmusik/codemirror-lang-csound
- Repository: https://github.com/kunstmusik/codemirror-lang-csound
- Homepage: https://github.com/kunstmusik/codemirror-lang-csound#readme
- Issues: https://github.com/kunstmusik/codemirror-lang-csound/issues
- npm.io page: https://npm.io/package/@kunstmusik/codemirror-lang-csound

## Dependencies (7)

- [@lezer/lr](https://npm.io/package/@lezer/lr.md) ^1.4.0
- [@lezer/common](https://npm.io/package/@lezer/common.md) ^1.2.0
- [@codemirror/view](https://npm.io/package/@codemirror/view.md) ^6.0.0
- [@lezer/highlight](https://npm.io/package/@lezer/highlight.md) ^1.2.0
- [@codemirror/state](https://npm.io/package/@codemirror/state.md) ^6.0.0
- [@codemirror/language](https://npm.io/package/@codemirror/language.md) ^6.10.0
- [@codemirror/autocomplete](https://npm.io/package/@codemirror/autocomplete.md) ^6.0.0

## Alternatives

- [ext-list](https://npm.io/package/ext-list.md) — 6.3M weekly downloads
- [@lexical/selection](https://npm.io/package/@lexical/selection.md) — 3.8M weekly downloads
- [@lexical/text](https://npm.io/package/@lexical/text.md) — 3.6M weekly downloads
- [@lexical/clipboard](https://npm.io/package/@lexical/clipboard.md) — 3.0M weekly downloads
- [@tiptap/extension-mention](https://npm.io/package/@tiptap/extension-mention.md) — 3.0M weekly downloads

## Recent versions

- 1.0.3 (latest) — 2026-09-23
- 1.0.2 — 2026-04-22
- 1.0.1 — 2026-04-22
- 1.0.0 — 2026-04-22

## README

# @kunstmusik/codemirror-lang-csound

CodeMirror 6 language support for Csound, covering CSD, ORC, and SCO files.

## Features

- One Lezer-based language package with modes for full `.csd`, orchestra `.orc`, and score `.sco` documents.
- Syntax highlighting, indentation, folding, and comment support for Csound editing.
- Opcode autocomplete backed by generated Csound opcode metadata.
- Semantic highlighting for built-in opcodes, UDOs, p-fields, named instruments, and score fragments.
- Hover info for built-in opcodes and document-local UDOs.

## Install

```sh
npm install @kunstmusik/codemirror-lang-csound
```

## Changelog

### 1.0.3

- Add a language-only `/compat` entry for old mode and completion option names. Colors, panels, and evaluation remain in host code.
- Add generated node names and grammar-owned identifier groups under `/syntax`, with type tests and stale-artifact checks.
- Parse Csound 7 declarations, multiline UDO signatures, Unicode names, boolean rates, and array expression indexing.
- Keep Unicode and multiline UDOs available to completion, hover, and semantic highlighting.
- Allow hosts to disable the built-in completion source with `csound({ completion: false })`.
- Let browser bundlers load the rich help catalog as a separate chunk.
- Add language-interface tests and a command to scan a Csound test checkout. Build the package automatically before packing it.

### 1.0.2

- Fix reading pfields to tokens with lower-case p. 

### 1.0.1

- Fixed the package `exports` condition ordering so newer Vite and Rolldown-based builds do not fail on the published package metadata.
- No runtime API changes. This is a packaging and compatibility release on top of 1.0.0.

### 1.0.0

- Initial public release of the Csound CodeMirror 6 language package.
- Shipped CSD, ORC, and SCO modes with autocomplete, semantic highlighting, hover info, and the rich opcode metadata entrypoint.

## Quick Start

```ts
import { EditorState } from "@codemirror/state"
import { EditorView } from "@codemirror/view"
import { basicSetup } from "codemirror"
import { csound } from "@kunstmusik/codemirror-lang-csound"

const doc = `<CsoundSynthesizer>
<CsOptions>
-odac
</CsOptions>
<CsInstruments>
instr 1
  a1 oscil 0.2, 440
  out a1
endin
</CsInstruments>
<CsScore>
i1 0 1
e
</CsScore>
</CsoundSynthesizer>`

const state = EditorState.create({
  doc,
  extensions: [
    basicSetup,
    csound({ mode: "csd" }),
  ],
})

new EditorView({
  state,
  parent: document.querySelector("#editor")!,
})
```

`csound()` defaults to `mode: "csd"`. It also enables semantic highlighting and hover support by default.

## Modes

```ts
import { csound } from "@kunstmusik/codemirror-lang-csound"

csound({ mode: "csd" })
csound({ mode: "orc" })
csound({ mode: "sco" })
```

If you need the bare languages instead of the bundled `LanguageSupport`, the package also exports `csoundCsdLanguage`, `csoundOrcLanguage`, and `csoundScoLanguage`.

## Optional Configuration

```ts
csound({
  mode: "orc",
  completion: false,
  semanticHighlighting: false,
  hover: false,
})
```

## Rich Metadata Entry Point

The package exposes a separate rich metadata bundle at `@kunstmusik/codemirror-lang-csound/rich` for consumers that want direct access to the manual-derived opcode catalog.

```ts
import { csoundRichOpcodeCatalog } from "@kunstmusik/codemirror-lang-csound/rich"
```

Hover support lazy-loads that richer catalog automatically when it needs manual metadata.

## V1 Scope

Some ambiguous opcode/assignment lines still fall back to generic-line parsing.
Some alternate score-bin dialects remain follow-up work.

## Migrating from @hlolli/codemirror-lang-csound

New integrations should use `csound({ mode })`. A temporary, language-only
adapter keeps the old mode and completion option names:

```ts
import { csoundMode } from "@kunstmusik/codemirror-lang-csound/compat"

csoundMode({
  fileType: "csd",             // "csd" (default), "orc", or "sco"
  enableCompletion: true,
})
```

Completion defaults to true. This adapter adds no semantic colors, hover UI,
synopsis panel, legacy CSS, or indentation preference. Hosts must supply their
own presentation and evaluation behavior. The old `enableSynopsis` and
`enableDefaultTheme` options do not belong to this adapter.

The `/compat` entry also exports `csdLanguage`, `orcLanguage`, and `scoLanguage`
as aliases for the bare languages. None of these compatibility names appear in
the main entry. `csound()` keeps its existing defaults.

## Checked syntax adapters

Use semantic and hover results where possible. Hosts that need syntax-tree
access can import the current parser's checked names and groups:

```ts
import {
  csoundNodeNames as nodes,
  csoundNodeGroups,
  csoundNodeSet,
  type CsoundNodeName,
} from "@kunstmusik/codemirror-lang-csound/syntax"

const identifiers = csoundNodeSet(csoundNodeGroups.CsoundIdentifier)
const statements = csoundNodeSet([nodes.OrcStatement, nodes.ScoStatement])
identifiers.has(node.name) // Raw Lezer names remain strings.
// csoundNodeSet(["TypedIndentifier"]) // Type error.
```

The grammar marks identifier tokens with `group=CsoundIdentifier`. The build
derives frozen names, root names, and group members from `parser.nodeSet`,
including `@name` aliases. Hosts do not need to copy the identifier list.
Numeric parser IDs and anonymous/error nodes are not part of this entry.

Highlight, fold, and indent maps in the package check their keys against
`CsoundNodeName`. Semantic and hover code use the same generated names.
This catches misspellings and removed names, not changes in tree structure or
host evaluation policy; keep integration tests for those.

After editing the grammar, run `npm run build:grammar` and commit the generated
parser and `src/syntax-nodes.ts`. `npm test` checks that these files match the
grammar **before** rebuilding, then runs declaration-level tests that must
reject invalid names. CI runs the same checks.

## Csound corpus tests

```sh
npm run test:csound -- /path/to/csound/tests
```

The scanner also reads `CSOUND_TESTS_DIR`. It checks `.csd`, `.orc`, `.sco`,
and `.udo` files and exits with an error on unexpected parser recovery.
It allows named or explicitly marked error fixtures. This checks editor parsing,
not whether Csound can compile or run a file.

---
_Source: https://npm.io/package/@kunstmusik/codemirror-lang-csound · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
