ditacraft
Copilot instructions17 starsChanged 56 days agoMITView on GitHub
DitaCraft is a VS Code extension for editing and publishing DITA XML content. It provides a full-featured Language Server Protocol (LSP) implementation with validation, IntelliSense, navigation, and DITA-OT publishing integration. Server tests (server/test/) are Mocha TDD (suite/test blocks) and can run standalone. Client tests (src/test/suite/) require the VS Code test electron runner via @vscode/test-electron. Always run server tests to validate LSP changes; client tests need xvfb-run on headless Linux. This is a client-server VS Code extension using the Language Server…
- Installs packages
The file
We split this copilot-instructions.md into the rules it gives an agent
5 rules. About 0 are common, 0 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 65
Use getErrorMessage(error) from src/utils/errorUtils.ts for safe message extraction.
- Very specific: line 66
Use fireAndForget() to run async operations from synchronous activation contexts (prevents unhandled rejections).
- Very specific: line 70
All diagnostic codes are centralized in server/src/utils/diagnosticCodes.ts (e.g., DITA-STRUCT-001, DITA-XREF-002).
- Very specific: line 134
Never inline diagnostic code strings: add/update codes in server\src\utils\diagnosticCodes.ts.
- Very specific: line 147
Add command contributions in package.json under contributes.commands.
≈ “Common” is an estimate: at least 1 in 5 of the 1,644 Copilot instructions files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
DitaCraft — Copilot Instructions
DitaCraft is a VS Code extension for editing and publishing DITA XML content. It provides a full-featured Language Server Protocol (LSP) implementation with validation, IntelliSense, navigation, and DITA-OT publishing integration.
Build, Test, and Lint
# Install dependencies (both client and server)
npm install && cd server && npm install && cd ..
# Full build (type-check + esbuild bundle)
npm run compile
# Type-check only (client + server)
npm run check-types
# Lint
npm run lint
# Server tests (Mocha TDD, fast, no VS Code needed)
cd server && npm test
# Run a single server test file
cd server && tsc -p tsconfig.test.json && npx mocha out/test/validation.test.js --ui tdd --timeout 10000
# Client tests (requires VS Code test electron harness)
npm test
# Coverage
npm run coverageServer tests (server/test/) are Mocha TDD (suite/test blocks) and can run standalone. Client tests (src/test/suite/) require the VS Code test electron runner via @vscode/test-electron. Always run server tests to validate LSP changes; client tests need xvfb-run on headless Linux.
Architecture
This is a client-server VS Code extension using the Language Server Protocol:
- Client (
src/): VS Code extension that registers commands, tree view providers, webview panels, and starts the language server. Entry point:src/extension.ts. The language client is configured insrc/languageClient.tsand communicates over IPC. - Server (
server/): Standalone LSP server with its ownpackage.json,tsconfig.json, and dependencies. Entry point:server/src/server.ts. It wires allconnection.on*handlers to feature modules. - Build:
esbuild.jsbundles both client (src/extension.ts→out/extension.js) and server (server/src/server.ts→server/out/server.js) as CommonJS.
Server internals (server/src/)
| Directory | Purpose |
features/ | One file per LSP capability (completion, hover, validation, codeActions, etc.). Each exports a handler function like handleCompletion(params, documents, ...). |
services/ | Domain services: validationPipeline.ts orchestrates a 13-phase validation pipeline; keySpaceService.ts resolves DITA key spaces via BFS map traversal; catalogValidationService.ts handles DTD validation with OASIS catalogs. |
utils/ | Shared utilities: xmlTokenizer.ts (state-machine XML tokenizer), i18n.ts (localization), diagnosticCodes.ts (central code registry), patterns.ts (regex constants). |
data/ | Static schema data: ditaSchema.ts defines DITA element hierarchy, attributes, and documentation. |
messages/ | Localization JSON files (en.json, fr.json). |
Client internals (src/)
| Directory | Purpose |
commands/ | Command implementations (validate, publish, preview, file creation). Barrel-exported from index.ts. |
providers/ | Tree view providers (DITA Explorer, Key Space, Diagnostics), webview panels (preview, map visualizer, validation report), link/decoration providers. |
utils/ | Client utilities: ditaOtWrapper.ts (DITA-OT CLI integration), errorUtils.ts (safe error extraction + fireAndForget for async ops), configurationManager.ts, logger.ts. |
Key Conventions
Error handling
- Catch blocks use
catch (error: unknown)— never assume error type. - Use
getErrorMessage(error)fromsrc/utils/errorUtils.tsfor safe message extraction. - Use
fireAndForget()to run async operations from synchronous activation contexts (prevents unhandled rejections). - The validation pipeline wraps each phase in independent try-catch for error isolation — one phase failing must not break others.
Diagnostic codes
All diagnostic codes are centralized in server/src/utils/diagnosticCodes.ts (e.g., DITA-STRUCT-001, DITA-XREF-002). Never define diagnostic code strings inline in feature files.
i18n / Localization
Server diagnostic messages use the t() function from server/src/utils/i18n.ts with message keys from server/src/messages/{locale}.json. Use parameterized messages (e.g., t('id.duplicate', idValue)) — never interpolate directly into message strings.
LSP feature pattern
Each LSP feature in server/src/features/ exports a pure handler function that takes LSP params + TextDocuments (+ optional services). The server wires them in server.ts. Keep features stateless — state lives in services.
Test helpers
Server tests use createDoc() and createDocs() from server/test/helper.ts to create TextDocument instances and mock TextDocuments collections. These are lightweight and don't require a running server.
TypeScript strictness
Both tsconfig.json files enable strict: true with noUnusedLocals, noUnusedParameters, noImplicitReturns, and noFallthroughCasesInSwitch.
ESLint
@typescript-eslint/no-explicit-anyis warn-level (prefer typed alternatives).- Unused variables prefixed with
_are allowed. - Root
npm run lintruns the root ESLint config (primarily client code). The LSP server has its own config/ignores underserver/.
Running tests (fast paths)
Server (LSP) tests (Mocha TDD)
cd server
# Run all server tests
npm test
# Run a single suite/test by name
npm test -- --grep "validateDITADocument"
# Run a single compiled test file directly
tsc -p tsconfig.test.json && npx mocha out/test/validation.test.js --ui tdd --timeout 10000Client (VS Code integration) tests
# Runs via @vscode/test-electron
npm testTo focus on a single client test, filter/limit what gets required in src\test\suite\index.ts (the harness loads tests from there).
High-level architecture (how it hangs together)
- This is a VS Code extension (client) + separate LSP server (server) communicating over IPC / LSP 3.17+.
- Client entry + wiring:
src\extension.tsregisters commands, views, providers, and starts the language client.src\languageClient.tsconfigures the language client and launches the server process.
- Server entry + wiring:
server\src\server.tsis the LSP entry point.server\src\serverHandlers.tswiresconnection.on*handlers to feature modules.
- Build output:
esbuild.jsbundles client →out\extension.jsand server →server\out\server.js(CommonJS).
Validation + diagnostics model (server)
- The core validator is
server\src\services\validationPipeline.ts: a 13-phase pipeline with per-phase try/catch isolation (one phase failing must not break others). - Performance guardrails:
- Smart debouncing: topics ~300ms, maps ~1000ms, with per-document cancellation.
- Large file optimization: files over the configured threshold skip heavier phases.
- Diagnostics conventions:
- Never inline diagnostic code strings: add/update codes in
server\src\utils\diagnosticCodes.ts. - All diagnostic text is localized: messages come from
server\src\messages\{locale}.jsonand are retrieved viat()fromserver\src\utils\i18n.ts. - Severity overrides are driven by the
ditacraft.validationSeverityOverridessetting (applied in the pipeline). - Suppression is comment-based:
<!-- ditacraft-disable CODE -->/<!-- ditacraft-enable CODE -->(range)<!-- ditacraft-disable-file CODE -->(entire file)
- Settings are cached per-document in
server\src\settings.tsand refreshed viaworkspace/didChangeConfiguration.
- Never inline diagnostic code strings: add/update codes in
Feature implementation patterns
- Server features live in
server\src\features\and export handler functions (stateless). Put state/caching inserver\src\services\. - Client commands live in
src\commands\:- Register command handlers in
src\extension.ts. - Add command contributions in
package.jsonundercontributes.commands.
- Register command handlers in
- Tests:
- Server tests use helpers like
createDoc()/createDocs()fromserver\test\helper.tsto mockTextDocumentswithout running VS Code. - Client tests run in the VS Code test harness and typically assert via diagnostics/commands.
- Server tests use helpers like
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

