Skip to content
Multi-Language Support
On this page

Using selfdoc across languages: per-source-entry language declarations, the nine extractors, directive examples, source detection, and multi-language dispatch.

#Multi-Language Support

selfdoc ships an extractor for each of the languages in the table below. Each one knows how to read its source files and resolve directives against them. The same directive syntax works across all of them -- only the source file format changes.

#Declaring languages

There is no top-level language key. Every source entry names its own language, so one project documents as many languages as it declares:

{} json
{
  "source": [
    {"path": "internal/", "language": "go"},
    {"path": "cmd/", "language": "go"},
    {"path": "web/src/", "language": "typescript"}
  ]
}

Valid language values are the names in the extractor table below. There is no javascript value -- .js and .jsx files belong to the typescript extractor, so declare typescript for them.

selfdoc init writes the entries for you. It probes for each language's marker files in priority order -- Python (pyproject.toml, setup.py), Go (go.mod), Svelte, TypeScript (tsconfig.json, package.json), Zig, Swift, Kotlin, Dart -- and writes an entry for every language it finds, not just the first. Svelte is probed before TypeScript because a Svelte project also carries TypeScript files and a tsconfig.json, so TypeScript would otherwise win every Svelte project. SQL is never auto-detected: a .sql file in a repository says nothing about what the repository is, so a SQL source path is always declared by hand.

#Go Examples

#Module reference

Show package-level documentation and all exported functions for a Go package. The ref directive extracts the package doc comment from the source files and lists every exported function with its full signature and associated doc comment. Use the package import path relative to your source directories:

M markdown
:<: ref path="internal/config"
:=:
:>:

#Struct schema table

Render a Go struct's exported fields as a Markdown table with columns for field name, type, and documentation extracted from doc comments or struct tags. This is useful for configuration structs, request/response types, and any data structure readers need to understand at a glance:

M markdown
:<: table-schema path="internal/server/handler.go" target="ServerConfig"
:=:
:>:

This finds the ServerConfig struct and generates a table with field names, types, and doc comments (or struct tags).

#Embedding test code

Pull a Go test function body into your documentation as a runnable code example. The code-test directive extracts the function body and renders it as a Go code block, giving readers a real example they know compiles and passes tests:

M markdown
:<: code-test path="internal/config/config_test.go" target="TestLoadConfig"
:=:
:>:

The test body is rendered as a Go code block, giving readers a real example they know actually compiles.

#TypeScript / JavaScript Examples

The TypeScript extractor handles .ts, .tsx, .js and .jsx, matching export declarations, interfaces, type aliases, and JSDoc/TSDoc comments. The same directive syntax works across all four extensions since they share the same export conventions:

#Module reference

M markdown
:<: ref path="src/client"
:=:
:>:

Shows exported functions, classes, and interfaces from the module with their JSDoc or TSDoc comments.

#Interface or class schema

M markdown
:<: table-schema path="src/types.ts" target="AppConfig"
:=:
:>:

Renders an interface or class as a table of property names, types, and descriptions from doc comments.

#Code examples from tests

M markdown
:<: code-test path="src/__tests__/client.test.ts" target="creates a new client"
:=:
:>:

For TypeScript tests, the target matches the test description string (the first argument to it() or test()).

#Source File Detection

Each language extractor knows which file extensions to scan when walking your source directories. Only files matching the active extractor's extensions are read during directive resolution, coverage analysis, and symbol enumeration for the auto-generated documentation pages:

Source File Detection
language valueExtensionsAuto-detected
python.pyyes
go.goyes
svelte.svelteyes
typescript.ts, .tsx, .js, .jsxyes
zig.zigyes
swift.swiftyes
kotlin.ktyes
dart.dartyes
sql.sqlno -- declare it by hand

The source array tells selfdoc which directories to scan, and with which extractor:

{} json
{
  "source": [
    {"path": "internal/", "language": "go"},
    {"path": "cmd/", "language": "go"}
  ]
}

#One project, several languages

A Go backend and a TypeScript frontend in one repository are one selfdoc project: declare a source entry for each, and a directive is dispatched to whichever entry owns the path it names. A path that resolves under more than one entry is an ambiguity error naming the languages it matched, never a silent pick -- narrow the path attribute, or narrow the source paths, until one entry owns it.

Splitting a repository into several selfdoc projects merged by a unified build remains the right shape when the components ship and version separately, not merely because they are written in different languages.

Next: Root Files

More tools from this site

  • claudestream Drive Claude Code from Python: run it as a subprocess and read its output as typed events, with async and sync sessions, sandbox policies, and tools you define in Python
  • claudewheel A TUI Claude Code Launcher that lets you have more than one profile, manage sessions lifecycle, pick the exact CC version, model to use (even older unlisted ones), pick which GitHub account to use, etc.
  • dirstat Fast, single-binary directory statistics CLI: every file under a tree grouped by format, with counts, sizes, and lines of code, as a colored terminal table or as JSON
  • fastware A batteries-included ASGI framework: msgspec JSON, a managed Granian server, dependency injection, SSE, WebSockets, auth, and a test client
  • go-toml-edit Zero-dep TOML editing library for Go with comment preservation
  • howmuchleft The fastest Claude Code statusline: context window, 5-hour, and weekly limit usage as three customizable gradient bars, rendering in about 6 ms
  • orxtra
  • pgdesign
  • predraw Declarative rendering pipeline: describe a scene in JSON and get SVG, PNG and WebP out, with light and dark style tokens, reusable components and text converted to path outlines
  • reposummary Turn a git repository's history into a Markdown journal: pick a time window or revision range and get a readable digest of what changed, optionally narrated by an LLM
  • rlsbl Release orchestration and project scaffolding CLI that bumps versions, validates a structured JSONL changelog, tags only the commit CI verified, and publishes to npm, PyPI, Go and more
  • safegit git wrapper CLI that gives each commit its own temporary index and retries ref updates on conflict, so concurrent agents share one repository
  • saferm Command-line replacement for rm that archives every deletion with a mandatory reason and the context it ran in, so deleted files can be listed, inspected and restored
  • strictcli
  • stricttest An always-on test-isolation floor: a pytest plugin and a Go env-hygiene module that make a test suite structurally unable to reach real credentials, the real HOME, the network, or the development repository.
  • wesktop A Python framework that turns an ASGI web app into a desktop application, serving it from a local Granian server and displaying it in a native OS window via pywebview
Search