From f0ddcee35fdcd68cc27bd4a79baf38fdb02321ef Mon Sep 17 00:00:00 2001 From: Yauhen Yakimovich Date: Wed, 25 Nov 2026 19:39:14 +0100 Subject: [PATCH] Toolchain 0.6.0: carry hmd-lsp 0.1.0 The HyperMarkDown language server joins d2 and hql in all five archives, pinned from the lsp-v0.1.0 release of the main repository. The build reads an upstream asset published as a zip, which is how hmd-lsp publishes its Windows program. The release check runs one protocol session against the server on each platform. --- CHANGELOG.md | 16 +++++++++ README.md | 38 +++++++++++++------- scripts/build-release.mjs | 28 +++++++++++---- scripts/lib/tools.mjs | 5 +-- scripts/lib/zip.mjs | 9 +++-- scripts/verify-release.mjs | 73 ++++++++++++++++++++++++++++++++++++-- toolchain.json | 33 ++++++++++++++++- 7 files changed, 174 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2013c13..ca61797 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,22 @@ immutable. ## [Unreleased] +## [0.6.0] — 2026-11-25 + +### Added + +- **`hmd-lsp` 0.1.0**, the HyperMarkDown language server + (`ewiger/hypermarkdown` `lsp-v0.1.0`), in all five archives as `bin/hmd-lsp`, + or `bin/hmd-lsp.exe` on Windows, with its licence at + `licenses/hmd-lsp/LICENSE`. It is one native program that speaks the Language + Server Protocol over standard input and output. `d2` 0.9.0 and `hql` 0.8.0 + are unchanged. +- The build reads an upstream asset published as a zip, which is how `hmd-lsp` + publishes its Windows program. `d2` and `hql` publish a tarball for every + platform. +- The release check starts `hmd-lsp` on each platform and runs one session: it + opens a card in a vault, asks for its semantic tokens, and stops the server. + ## [0.5.3] — 2026-11-25 ### Changed diff --git a/README.md b/README.md index 8b0b993..be7c17a 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,15 @@ Pinned native binaries for [HyperMarkDown](https://github.com/ewiger/hypermarkdown). -HyperMarkDown needs two native binaries: +HyperMarkDown needs three native binaries: - [`d2`](https://github.com/d2lang/d2) to render diagrams — in CI, in the documentation build, and inside the VS Code extension; - [`hql`](https://github.com/ewiger/hql) to run HQL cells — inside the VS Code - extension. + extension; +- [`hmd-lsp`](https://github.com/ewiger/hypermarkdown/tree/main/tools/hmd-lsp), + the HyperMarkDown language server, to colour links by whether they resolve + and to answer hover and Go to Definition — inside the VS Code extension. Before this repository existed `d2` was acquired separately in each place from a moving `:latest` Docker tag, so two runs could render the same diagram @@ -17,8 +20,10 @@ reproducible archive per platform, one checksum file. It packages only native executables released elsewhere. HQL is its own project with its own releases, so to HyperMarkDown it is a pinned binary like `d2`. The -`hmd` CLI, the HMD LSP and the VS Code extension are HyperMarkDown components and -live in the main repository. +language server is built and released by the main repository, on its own +`lsp-v` tags, and is pinned here from that release like the other two. The +`hmd` CLI and the VS Code extension are HyperMarkDown components that live in +the main repository and are not packaged here. ## What a release contains @@ -37,14 +42,16 @@ all of them: ```text bin/d2 # bin/d2.exe on Windows +bin/hmd-lsp # bin/hmd-lsp.exe on Windows bin/hql # where HQL publishes this platform -licenses/d2/LICENSE # d2 is MPL-2.0; each binary travels with its licence -licenses/hql/LICENSE # hql is MIT +licenses/d2/LICENSE # d2 is MPL-2.0; each binary travels with its licence +licenses/hmd-lsp/LICENSE # hmd-lsp is MIT +licenses/hql/LICENSE # hql is MIT manifest.json # toolchain version, platform, and each tool's version and upstream pin ``` A tool is in an archive exactly when `toolchain.json` pins an asset for that -platform. `d2` is in all five. HQL 0.8.0 publishes Linux x86_64, both macOS +platform. `d2` and `hmd-lsp` are in all five. HQL 0.8.0 publishes Linux x86_64, both macOS targets and Windows x86_64, so only the Linux ARM64 archive carries `d2` alone; `manifest.json` lists what an archive holds. @@ -58,10 +65,10 @@ happens to have. CI rebuilds and compares on every push. ## Consuming a release Download the archive for your platform, verify it against `SHA256SUMS`, unpack -it, and use `bin/d2` and `bin/hql`. Nothing here is meant to be consumed as source: HyperMarkDown +it, and use `bin/d2`, `bin/hql` and `bin/hmd-lsp`. Nothing here is meant to be consumed as source: HyperMarkDown pins a toolchain *version* and fetches the published artifact over HTTPS. -The version lines are independent. Bumping d2 or hql happens here; +The version lines are independent. Bumping d2, hql or hmd-lsp happens here; HyperMarkDown bumps only the toolchain version it pins, and a published toolchain release is immutable. @@ -80,7 +87,7 @@ node scripts/bump-d2.mjs v0.10.0 # repin d2 to a new upstream release `build-release.mjs` verifies the upstream assets twice: once against the digests pinned in `toolchain.json`, and once against the digests upstream publishes for -that tag — a `SHA256SUMS` for d2, a `.sha256` beside each asset for hql. The first catches a moved tag; the second catches a pin that was +that tag — a `SHA256SUMS` for d2 and for hmd-lsp, a `.sha256` beside each asset for hql. The first catches a moved tag; the second catches a pin that was written wrong to begin with. `verify-release.mjs` is the single definition of a good release — both workflows @@ -88,13 +95,16 @@ call it rather than each describing the checks themselves. It confirms every digest, the exact file list, the executable bit, and that the embedded manifest agrees with `toolchain.json`; and for the archive matching the host it extracts each binary and runs it the way its consumer does — `d2 - -` renders `a -> b`, -and `hql render --emit after --envelope json -` runs a cell. +`hql render --emit after --envelope json -` runs a cell, and `hmd-lsp --stdio` +answers one session of the Language Server Protocol. ## Releasing 1. `node scripts/bump-d2.mjs ` if d2 is moving. To move hql, edit its `version`, `tag` and the three asset digests in `toolchain.json`; the build - checks them against HQL's published `.sha256` files. + checks them against HQL's published `.sha256` files. To move hmd-lsp, edit + its `version`, `tag`, and the five asset names and digests, from the + `SHA256SUMS` of its release; the build checks them against that file. 2. Bump `toolchain` in `toolchain.json` and add a `CHANGELOG.md` entry. 3. Tag `v`. The release workflow rejects a tag that disagrees with `toolchain.json`, builds, verifies on all five platforms, and publishes. @@ -103,4 +113,6 @@ and `hql render --emit after --envelope json -` runs a cell. This repository is MIT ([LICENSE](LICENSE)). The `d2` binary it redistributes is MPL-2.0 and ships with upstream's licence text at `licenses/d2/LICENSE`; the -`hql` binary is MIT and ships with its licence at `licenses/hql/LICENSE`. +`hql` binary is MIT and ships with its licence at `licenses/hql/LICENSE`; the +`hmd-lsp` binary is MIT and ships with its licence at +`licenses/hmd-lsp/LICENSE`. diff --git a/scripts/build-release.mjs b/scripts/build-release.mjs index 7c89e36..32f351a 100644 --- a/scripts/build-release.mjs +++ b/scripts/build-release.mjs @@ -3,7 +3,7 @@ // // node scripts/build-release.mjs [--platform ]... [--out dist] // -// Downloads the pinned upstream assets of every tool — d2 and hql — verifies +// Downloads the pinned upstream assets of every tool — d2, hql and hmd-lsp — verifies // them twice over, and repacks them into one archive per platform with a // stable internal layout. Output is // byte-reproducible: given the same toolchain.json, two runs produce identical @@ -26,7 +26,7 @@ import { } from "./lib/common.mjs"; import { readTarGz, writeTarGz } from "./lib/tar.mjs"; import { binaryPath, licensePath, toolsFor } from "./lib/tools.mjs"; -import { writeZip } from "./lib/zip.mjs"; +import { readZip, writeZip } from "./lib/zip.mjs"; const ARCHIVE_MODE = 0o755; const LICENSE_MODE = 0o644; @@ -45,8 +45,21 @@ function parseArgs(argv) { } /** - * Find a tool's single executable in an extracted upstream tarball. d2 nests it - * at `d2-v/bin/d2` and hql at `hql-v-/hql`; searching + * The entries of an upstream archive, whichever format upstream chose. d2 and + * hql publish a tarball for every platform; hmd-lsp publishes a zip for + * Windows. A zip entry carries no type, so one is given here: a name ending in + * `/` is a directory and everything else is a file, which is all the search + * below needs to know. + */ +function readUpstream(name, body) { + if (!name.endsWith(".zip")) return readTarGz(body); + return readZip(body).map((entry) => ({ ...entry, type: entry.name.endsWith("/") ? "5" : "0" })); +} + +/** + * Find a tool's single executable in an extracted upstream archive. d2 nests it + * at `d2-v/bin/d2`, hql at `hql-v-/hql`, and hmd-lsp + * at `hmd-lsp-v-/hmd-lsp`; searching * by name means a layout change surfaces as a clear failure here rather than as * an archive that is missing its binary. */ @@ -67,8 +80,9 @@ function findExecutable(entries, tool) { } function findLicense(entries) { - // d2 is MPL-2.0 and hql is MIT, not this repo's licence, so redistributing a - // binary means shipping upstream's licence text alongside it. + // d2 is MPL-2.0, and hql and hmd-lsp are MIT under their own copyright + // lines, so redistributing a binary means shipping upstream's licence text + // alongside it. const match = entries.find((entry) => /(^|\/)LICENSE(\.[A-Za-z]+)?$/.test(entry.name) && entry.type === "0"); if (!match) fail("no LICENSE file found in the upstream archive"); return match; @@ -88,7 +102,7 @@ async function toolFiles(manifest, tool, platform) { fail(`${asset.name}: pinned sha256 ${asset.sha256}, downloaded ${actual}`); } - const entries = readTarGz(upstreamArchive); + const entries = readUpstream(asset.name, upstreamArchive); const path = binaryPath(tool, platform); return { files: [ diff --git a/scripts/lib/tools.mjs b/scripts/lib/tools.mjs index 84f8ee1..ee812b7 100644 --- a/scripts/lib/tools.mjs +++ b/scripts/lib/tools.mjs @@ -2,8 +2,9 @@ // verifier so the two cannot disagree about a layout. // // A tool appears in a platform's archive exactly when toolchain.json pins an -// asset for that platform. d2 publishes all five; hql publishes four, and the -// Linux ARM64 archive simply carries no hql — a consumer falls back to PATH there. +// asset for that platform. d2 and hmd-lsp publish all five; hql publishes four, +// and the Linux ARM64 archive simply carries no hql — a consumer falls back to +// PATH there. /** The tools pinned for a platform, in a stable order. */ export function toolsFor(manifest, platform) { diff --git a/scripts/lib/zip.mjs b/scripts/lib/zip.mjs index f7b89be..d1c013d 100644 --- a/scripts/lib/zip.mjs +++ b/scripts/lib/zip.mjs @@ -102,9 +102,12 @@ export function writeZip(files) { } /** - * Read a zip written by writeZip. Enough of the format to let the verifier - * inspect the Windows artifact the same way it inspects the tarballs — it - * walks the central directory rather than scanning for local headers. + * Read a zip. Enough of the format to let the verifier inspect the Windows + * artifact the same way it inspects the tarballs, and to let the build read an + * upstream asset published as a zip. It walks the central directory rather + * than scanning for local headers, so sizes are right even for an archiver + * that writes them after the data. Stored and deflated entries only, and no + * zip64: every archive read here is a few megabytes. * * @param {Buffer} buf * @returns {{name: string, mode: number, body: Buffer}[]} diff --git a/scripts/verify-release.mjs b/scripts/verify-release.mjs index e9380bf..a930318 100644 --- a/scripts/verify-release.mjs +++ b/scripts/verify-release.mjs @@ -6,8 +6,8 @@ // Checks every archive in the output directory: its digest matches SHA256SUMS, // it contains exactly the files the layout promises for its platform, its // embedded manifest agrees with toolchain.json, and — for the archive matching -// the host — every extracted binary actually runs: d2 renders, and hql runs a -// cell. Both workflows call this, so +// the host — every extracted binary actually runs: d2 renders, hql runs a +// cell, and hmd-lsp answers a client. Both workflows call this, so // there is one definition of "a good release" rather than a copy in each. import { execFileSync } from "node:child_process"; @@ -15,6 +15,7 @@ import { chmodSync, mkdirSync, mkdtempSync, writeFileSync } from "node:fs"; import { readFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import { join } from "node:path"; +import { pathToFileURL } from "node:url"; import { ROOT, fail, parseSums, readManifest, sha256 } from "./lib/common.mjs"; import { readTarGz } from "./lib/tar.mjs"; @@ -95,6 +96,74 @@ const EXERCISE = { }, }; +/** One Language Server Protocol message, framed as the protocol frames it. */ +function frame(message) { + const body = JSON.stringify({ jsonrpc: "2.0", ...message }); + return `Content-Length: ${Buffer.byteLength(body)}\r\n\r\n${body}`; +} + +/** The messages in a server's output, in the order it wrote them. */ +function unframe(output) { + const messages = []; + let rest = Buffer.from(output, "utf8"); + for (;;) { + const head = rest.indexOf("\r\n\r\n"); + if (head === -1) return messages; + const length = /Content-Length: (\d+)/i.exec(rest.subarray(0, head).toString("utf8")); + if (length === null) return messages; + const start = head + 4; + const end = start + Number(length[1]); + messages.push(JSON.parse(rest.subarray(start, end).toString("utf8"))); + rest = rest.subarray(end); + } +} + +EXERCISE["hmd-lsp"] = (binary, expectedVersion, dir) => { + const version = execFileSync(binary, ["--version"], { encoding: "utf8" }).trim(); + check( + version === `hmd-lsp ${expectedVersion}`, + `hmd-lsp --version reported ${JSON.stringify(version)}, expected "hmd-lsp ${expectedVersion}"`, + ); + // One whole session over stdin and stdout, as the extension starts it: + // `--stdio`, diagnostics off, a card opened, its tokens asked for, and a + // clean stop. The card links to a card that exists and to one that does + // not, so the answer shows the server resolved against the vault on disk. + const vault = join(dir, "lsp-vault"); + mkdirSync(join(vault, ".hmd"), { recursive: true }); + writeFileSync(join(vault, "tokens.hmd"), "# Tokens\n"); + const uri = pathToFileURL(join(vault, "login.hmd")).href; + const session = [ + { id: 1, method: "initialize", params: { capabilities: {}, initializationOptions: { diagnostics: false } } }, + { method: "initialized", params: {} }, + { + method: "textDocument/didOpen", + params: { textDocument: { uri, languageId: "hmd", version: 1, text: "[[tokens]] [[nowhere]]\n" } }, + }, + { id: 2, method: "textDocument/semanticTokens/full", params: { textDocument: { uri } } }, + { id: 3, method: "shutdown", params: null }, + { method: "exit", params: null }, + ]; + const answers = unframe( + execFileSync(binary, ["--stdio"], { input: session.map(frame).join(""), encoding: "utf8", timeout: 30_000 }), + ); + const answer = (id) => answers.find((message) => message.id === id)?.result; + check( + answer(1)?.serverInfo?.name === "hmd-lsp" && answer(1)?.serverInfo?.version === expectedVersion, + `hmd-lsp introduced itself as ${JSON.stringify(answer(1)?.serverInfo)}`, + ); + // Two tokens: `tokens` resolves, and `nowhere` carries the first modifier, + // which the server's legend names `unresolved`. + check( + JSON.stringify(answer(2)?.data) === JSON.stringify([0, 2, 6, 0, 0, 0, 11, 7, 0, 1]), + `hmd-lsp answered semantic tokens ${JSON.stringify(answer(2)?.data)}`, + ); + check( + answer(1)?.capabilities?.semanticTokensProvider?.legend?.tokenModifiers?.[0] === "unresolved", + "hmd-lsp's first token modifier is not `unresolved`", + ); + return version; +}; + async function main() { const outIndex = process.argv.indexOf("--out"); const out = join(ROOT, outIndex === -1 ? "dist" : process.argv[outIndex + 1]); diff --git a/toolchain.json b/toolchain.json index 1eed8f6..221fc4d 100644 --- a/toolchain.json +++ b/toolchain.json @@ -1,5 +1,5 @@ { - "toolchain": "0.5.3", + "toolchain": "0.6.0", "platforms": [ "linux-x86_64", "linux-arm64", @@ -65,6 +65,37 @@ "sha256": "5064a257e475fe92481e19a785146253362c92d239d3a5021288b446244d4d8f" } } + }, + "hmd-lsp": { + "version": "0.1.0", + "upstream": { + "repo": "ewiger/hypermarkdown", + "tag": "lsp-v0.1.0" + }, + "checksums": "SHA256SUMS", + "license": "MIT", + "assets": { + "linux-x86_64": { + "name": "hmd-lsp-v0.1.0-x86_64-unknown-linux-musl.tar.gz", + "sha256": "99791d0774cbd0d52da2243011313b3fcd29cd577dcfcf6b0db16230236802ee" + }, + "linux-arm64": { + "name": "hmd-lsp-v0.1.0-aarch64-unknown-linux-musl.tar.gz", + "sha256": "a789727661fcb23c353c60f8b0ad96831b94779262b6dbacc39cf8f9cccd899a" + }, + "macos-x86_64": { + "name": "hmd-lsp-v0.1.0-x86_64-apple-darwin.tar.gz", + "sha256": "9d7b2fb7c1f5bcd8a5b74be71b51e7d825f92b378241a96cd4eed58b58e700c0" + }, + "macos-arm64": { + "name": "hmd-lsp-v0.1.0-aarch64-apple-darwin.tar.gz", + "sha256": "f06b73071d5543d85f1f65301d00c0345b4c76579c3d25b25eb2158b882c9f57" + }, + "windows-x86_64": { + "name": "hmd-lsp-v0.1.0-x86_64-pc-windows-msvc.zip", + "sha256": "162b800f390b8d49bde4c994d1df13df8622c0df036ac8e0aeeab4f79be9795c" + } + } } } }