Skip to content

The extension says why it went quiet: Doctor, image placeholders, and an integration suite - #17

Merged
ewiger merged 35 commits into
mainfrom
feature/vsc-ext-silent-failures
Nov 29, 2026
Merged

ewiger merged 35 commits into
mainfrom
feature/vsc-ext-silent-failures

Conversation

@ewiger

@ewiger ewiger commented Nov 29, 2026

Copy link
Copy Markdown
Owner

What changes

The extension had several ways to stop working without saying so. This branch gives each one a message.

Added

  • HyperMarkDown: Doctor. One command checks the card's language id, the vault and its configuration, workspace trust, the language server, semantic highlighting, hql, and d2. Each check is Passed, Warning, Failed, Information, or Skipped, and a failed one says what failed, why it matters, and how to resolve it. In an untrusted workspace the Doctor starts no program.
  • A warning when a card opens as another language. A files.associations entry that maps *.hmd to markdown turned off the grammar, the language server, and the cell lenses. The extension now says so once per session, and Open .hmd Files as HyperMarkDown removes the entry after a confirmation.
  • Remote images, when asked for. hyperMarkdown.preview.remoteImages, off by default, loads https: images in a trusted workspace. Only user settings can turn it on.
  • D2 is coloured in the editor, with Terrastruct's grammar, which the extension now carries.

Fixed

  • The preview button shows on every .hmd file, whatever language id the editor gave it.
  • A relative image shows in the preview, including inside an embed.
  • An image the preview does not show is replaced by its alt text, its reference, and the reason.
  • Links and cells are coloured inside a paragraph, a list, and a quote.
  • Create Missing Card accepts a relative link and is idempotent.

Tests

  • An integration suite runs the extension inside a real VS Code: six suites, 42 tests, in CI on Linux, macOS and Windows.

Merge with main

Main was merged in after the diagram cells and Mermaid landed. Both sides' code is kept. The preview controller had one counter from each branch guarding against a slow send, and one stays. The generated status views are rendered again.

One gap is recorded in the extension's tracker: the Doctor checks hql and d2, and does not check merman-cli yet.

Checked

  • Extension unit tests: 454 passed.
  • Python tests: 930 passed.
  • hmd lint in doc/: clean.
  • The integration suite was not run locally after the merge. CI runs it here.

…language id

A files.associations entry that maps *.hmd to markdown gave a card the
language id markdown, and the button and the preview commands were keyed on
the language id. They now also read the file name, so the preview opens and
can say what is wrong.
The warning names the files.associations entry that causes it and offers
two buttons: Remove the Association, which edits the setting at the scope
that holds the entry and gives every open card the language id hmd, and
Run Doctor. An entry another extension contributes as a default is
overridden in the user settings instead.
The preview kept an image's path as written, so the webview resolved it
against its own address, and its resource roots allowed only the
extension's media folder. The host now rewrites each image before it
posts the IR: a path is read from the folder of the card it is written
in (an embedded card's images from the embedded card, a cell's output
from the card that holds the cell), and becomes a webview resource URI.
A web address and a data image are posted as written. Any other scheme,
and a file outside every workspace folder, lose their src and show the
alt text. The webview may now read the workspace folders as well as the
media folder, and the roots follow the folders when they change.

Issue 0113.
A ./x or ../x/y red link now creates its card at the path resolved from
the linking card's folder, read the way the core's resolver reads it:
dot segments collapsed, .hmd added unless the name has a card extension,
and a heading, block id, or display text dropped. A target that names a
folder gets that folder's index.hmd, the only card it binds. A path above
the namespace root, into a nested vault, or through a link out of the
root is refused as HMD003.

Create never writes over a file: a card the link already reaches, or any
file at the path, stops the action, and the edit no longer passes
ignoreIfExists, which prepended a heading to an existing file.
Intermediate folders are created first.
The fence table gave a d2 fence the scope source.d2, but the extension
carried no grammar for it, so the body stayed one colour unless the D2
extension was installed. The extension now carries the grammar and the
language configuration of terrastruct/d2-vscode at commit 23346fb
(version 0.8.8), unchanged, under the BSD 3-Clause License, with a
notice beside the grammar that names the commit and the checksums.

It registers the language d2 for .d2 files with the same id and scope
as the D2 extension, so that VS Code merges the two when both are
installed. The fence table gains a built-in d2 row, so the body of a
d2 or d2#show fence is edited as d2.

A new test runs the grammars through vscode-textmate and
vscode-oniguruma: a .d2 file, and a card with d2, d2#show and d2lang
fences, get the expected scopes for comments, keys, connections,
strings, numbers, booleans and block strings.
…nd quotes

The card grammar listed its link, anchor, cell output and fence rules beside
the Markdown grammar's rules, so they applied only at the top level. A
Markdown paragraph, list item or block quote that is open applies only its
own patterns: a link in the middle of a sentence or in a list item got the
Markdown reference-link scope, and a cell fence in a list item or a block
quote was read by the Markdown grammar.

The rules now come in through an injection in the card grammar, with the
selector

  L:source.hmd -markup.fenced_code -markup.inline.raw -markup.raw
    -meta.embedded -meta.fence.guard -comment

so they apply ahead of Markdown's rules everywhere in a card and stay out of
code spans, fenced and indented code, the frontmatter and HTML comments.

The fence grammar's guard takes no text, so the injection matched again
inside it and the tokenizer gave up on the line. The generator now names the
guard meta.fence.guard.hmd, and the selector leaves that scope out. The cell
output marker accepts \G as well as ^, so it matches after a list's indent.

test/tokens.test.ts runs the grammars through vscode-textmate and
vscode-oniguruma with VS Code's Markdown grammar from tm-grammars, all three
as dev dependencies that do not ship in the VSIX.
…ragraphs, lists and quotes

# Conflicts:
#	tools/hmd-vsc-ext/DEVELOP.md
…port

The command runs nine checks: the language id and files.associations, the
vault, the vault configuration, workspace trust, the language server,
semantic highlighting, hql, d2, and the versions. Each check is a function
with tests for its passing and failing result. The report is a read-only
document with one line for each check, and a button above each line whose
fix the extension can apply. It runs in a workspace with no vault and in an
untrusted one. The README gains a troubleshooting section.
Five pieces of work are merged on this branch and pass the extension's
tests. The tracker marks each as doing until it is checked in a running
editor, issues 0113 and 0119 move to doing, and the changelog lists them
under Unreleased.
A link that already resolves now opens the card it reaches, at the heading
or block its fragment names, and writes nothing. A file at the derived path
that the index does not hold is opened with a message that says why the link
is still red. An ambiguous link names its candidates, offers to open one, and
creates nothing, because a new card beside the linking card would change what
the link means. A bare or relative name whose folder already exists creates
that folder's index.hmd rather than a card beside the folder.

The tests drive the plan through the core's Workspace over a MemoryHost and
over a vault on disk, and read the folder-note cases of the conformance
corpus.
…pace, confirmed association repair

Every Doctor check now gives one of five outcomes: Passed, Warning, Failed,
Information, or Skipped. A Failed or a Warning result carries what failed,
why it matters, and how to resolve it. The type requires the three fields,
and the constructors refuse an empty one, so no check can leave one out.

The Doctor runs no program in an untrusted workspace. probeProgram and
serverVersion refuse without calling the runner, and the runner the Doctor
uses asks the trust again before each run. The hql, d2 and language server
rows report Skipped with the reason and Manage Workspace Trust.

No active card, no vault, and an untrusted workspace are Information. A card
that is open and that no vault reads stays Failed.

HyperMarkDown: Open .hmd Files as HyperMarkDown is in the Command Palette. It
shows each entry that changes and its scope in a modal, and writes only on
Change the Settings. Every unrelated files.associations entry is kept, and
the warning's button leads to the same confirmation. With nothing to change,
it says so.
The integration suite cannot read a webview's DOM. With HMD_EXTENSION_TEST=1
the extension keeps the last messages each preview posted to its webview and
returns them from hyperMarkdown._test.postedMessages. Without the variable
nothing is kept and the command is not registered, and it is not contributed
in package.json.
An Extension Host integration suite under tools/hmd-vsc-ext/test-integration,
run with npm run -w tools/hmd-vsc-ext test:integration and kept out of npm
test because it downloads VS Code. It uses @vscode/test-electron 3.1.0, which
finds the macOS executable Contents/MacOS/Code by itself, and mocha.

Four suites, each in its own window on a fresh copy of a fixture: a vault
(activation, contributed commands, languages and grammars, the preview and a
relative image, creating the card for [[./new]], the Doctor), a vault whose
settings map *.hmd to markdown (the warning, the preview, the Doctor's row,
removing the association), a folder with no vault (the Doctor), and the vault
in Restricted Mode. The launcher starts VS Code itself, because runTests always
passes --disable-workspace-trust.

All four pass on macOS against VS Code 1.148.0. CI runs the suite on Linux
under xvfb-run, with macOS and Windows allowed to fail until they have passed
there. DEVELOP.md says how to run it, what it covers, and what stays manual.
…e preview shows them

The card grammar now reads math itself, with the smart-dollar rule of the
core's math plugin: a $$ line opens a block that the next $$ line closes,
and $…$ or $$…$$ on one line is math when no space or tab follows the
opening delimiter or precedes the closing one. The injection leaves math
out, so a link, an embed or an anchor inside it is not coloured. A whole
[[link]] inside math is read as one piece, because the core finds links
first. The [ of a shortcut reference such as A[$i$] is taken first, so the
math inside it is coloured.

The injection now excludes only the frontmatter and HTML comments, not
every embedded body or comment, so a link inside a <script> or <style>
block is coloured. The preview escapes raw HTML and renders such a link.

The token tests load VS Code's HTML grammars and cover math blocks, inline
math, prose about money, escapes, tables, and links in and around HTML.
… in to https images

The preview's content policy blocked every web image, and a missing local
file showed the same unexplained broken-image icon.

- Add hyperMarkdown.preview.remoteImages (boolean, default false, window
  scope). When it is on and the workspace is trusted, the shell adds https:
  to img-src and nothing else. http: is never loaded. The manifest lists the
  setting under restrictedConfigurations, and the host also checks trust, so
  an untrusted workspace loads no web images. Changing the setting or
  granting trust reloads the open previews.
- Replace each image the host does not show with a placeholder: the alt
  text, the reference as the card wrote it, and the reason. The reasons are
  a missing file, a file that cannot be read, a folder, a path outside the
  workspace, a refused scheme, an http address, and a web image while remote
  images are off or the workspace is untrusted. A blocked web image offers a
  link to open it in the browser and a button that opens the setting.
- Check image files with workspace.fs.stat before posting a render, in one
  batch, remembered until a watcher reports a change or ten seconds pass.
- Swap an image that fails to load in the webview for the same placeholder,
  built with DOM calls.
- Record the exception in the webview-hardening section of HMD-0021 and
  document the setting in the README.
The extension's tracker states the eight decisions of 2026-11-25 and the
integration suite, issue 0119 gains its five outcomes, HMD-0021 names the
workspace folders as resource roots, the core's tracker gets the math
placeholder defect, the language's tracker the question of links inside
math, and the changelog lists the work under Unreleased.
With HMD_EXTENSION_TEST=1, hyperMarkdown._test.webviewHtml returns the HTML
each preview was loaded with, so the integration suite can read the page's
content security policy. Without the variable nothing is kept and the
command is not registered.
The suite now asserts what the merged branch does, not either of two
behaviours:

- Create Missing Card, asked again for new.hmd, opens it with no message and
  leaves its bytes alone; on a link that already resolves it opens the card
  and creates nothing.
- The Doctor's outcomes are read exactly (PASSED, WARNING, FAILED,
  INFORMATION, SKIPPED), and every Failed or Warning row says what, why and
  how to resolve it. With no vault, the Vault row is Failed while the card is
  open and Information with no editor. In Restricted Mode trust is
  Information, the language server, hql and d2 are Skipped, and no hql, d2 or
  hmd-lsp process starts; in a trusted window the Doctor does run hql and d2.
- Removing the association asks in a modal that lists the *.hmd entry.
  Cancelled, it leaves settings.json byte for byte; confirmed, it removes
  *.hmd and keeps an unrelated *.foo entry.
- A missing image, an https image and an http image each become a placeholder
  with the reference and the reason, and img-src has no https: by default.
  Two new suites turn remote images on: trusted, the https image shows and
  img-src holds https:; untrusted, it does not.

Running the Doctor twice could read the previous report, because VS Code
returns the open document before the provider's new text arrives; the helper
now waits for the text to change.
The setting moves from window to application scope, and the preview reads
the user value alone, so a workspace's settings cannot enable web images.
Both sides' code is kept. The preview controller had two counters for a
slow send, one from each branch; one stays. The generated views are
rendered again. The tracker gains a row: the Doctor does not check
merman-cli yet.
fsPath writes a drive letter in lower case and the workspace path from the
environment keeps it in upper case, so two tests waited for an editor that
was already open.
@ewiger
ewiger merged commit 8a46368 into main Nov 29, 2026
15 checks passed
@ewiger
ewiger deleted the feature/vsc-ext-silent-failures branch November 29, 2026 23:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant