Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions doc/status/vsc-ext.hmd
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ picks and re-indexes without a reload, since `0.6.1` [issue 0116].
| --- | --- | --- | --- |
| blocked | **Carry `hmd-lsp` in the build.** No VSIX holds the program, so a user gets the server only from `PATH` or from the setting. The server is released as 0.1.0. Unblocks when the pinned toolchain carries it; the client already looks in `toolchain/bin/` first | The release workflow checks which binaries a VSIX holds, and that list gains `hmd-lsp` | [[hmd-0033#distribution]] |
| todo | **Colour the listings in the preview.** A fenced block in Python, C, or any other language shows in one colour, because neither the extension nor the core has a highlighter. Colour it as the editor does [issue 0118] | Shiki reads the same TextMate grammars the editor uses, this extension's own among them, so a listing would look the same on both sides. It must run in the extension host and send coloured HTML, because the webview's content policy allows no script from outside | [[hmd-0021#11-webview-hardening]] |
| todo | **Colour a listing whose fence names a cell.** The editor colours a `python` fence through the Markdown grammar it includes. Check a fence with a cell suffix, such as `python#eval`, and fix the grammar when the suffix stops the Markdown grammar from recognising the language. `hql` and `d2` bodies have no grammar at all, and each needs one [issue 0118] | Not yet checked in a running editor | [[hmd-0026]] |
| todo | **Confirm the grammar colours a link inside a paragraph.** The grammar lists its link rules beside the Markdown grammar's. A paragraph is the Markdown grammar's rule, and once it is open only its own inline rules apply, so a link in the middle of a sentence may get no HyperMarkDown scope. Inspect the scopes in a running editor, and move the rules into an injection when they are missing [issue 0118] | A suspicion from reading the grammar, not a reproduced defect. The language server's tokens cover the same links, but only when the server is present | — |
| todo | **Colour a `d2` listing in the editor.** A `d2` fence shows in one colour unless the user has installed an extension for D2, because this extension carries no grammar for it. The fence table already gives a `d2` fence the scope `source.d2`. Carry a grammar that declares that scope [issue 0118] | `hql` has its grammar. The extension carries `d2` itself for the preview, so a user expects the editor to colour it without a second extension | [[hmd-0026]] |
| todo | **Colour a fence nested in a list or a quote.** The fence rules apply at the top level of a card. Inside a list item or a block quote the Markdown grammar reads the fence, so a cell there is not coloured, and a language outside the Markdown list is not either. Move the fence rules into an injection [issue 0118] | Not tested in a tokenizer; it follows from where the rules are included. The same change as the link rules need | — |
| todo | **Colour a link inside a paragraph from the grammar.** The grammar lists its link rules beside the rules of the Markdown grammar. A paragraph and a list item are rules of the Markdown grammar, and once one is open only its own inline rules apply. A link on a line of its own gets the HyperMarkDown scopes, and a link in the middle of a sentence or in a list item gets the Markdown scope of a reference link. Move the link rules into an injection [issue 0118] | Reproduced with the editor's tokenizer run outside the editor, not yet seen in a running editor. The language server's tokens cover the same links, but only when the server is present | — |
| todo | **Automate the by-hand checks.** The list in the extension's `DEVELOP.md` — the graph's legibility on a real vault, live editing, scroll sync — is read by hand before a release, and nothing stands in for it. The parked integration suite is where this would live [issue 0101] | Not a gate on shipping; it is the reason a release still costs an afternoon | [[hmd-0025]] |
| backlog | **Filter the graph by namespace and tag**, which the requirement asks for and the tab does not do. The index carries both on every node already | Waits on the open question below: what a filter does to the node cap | [[hmd-0025]] |
| todo | **Create the card a relative link points at.** Create-card places a bare target beside the linking card and an absolute one under the root, and declines `./` and `../` targets with a warning. Writing the link relative is how an author places a card deliberately, so the one form that says where the card goes is the form the action refuses | Path derivation and its test both encode the refusal today [`src/commands/createCard.ts`, `test/protocol.test.ts`] | [[hmd-0001#2-grammar]], [[hmd-0021#5-rendering-the-ir]] |
Expand Down Expand Up @@ -210,6 +211,20 @@ about 300 MB on first run, which is why it is not in the default test command.
shipped inside the VSIX — one build per platform, each gated on the binary
being there.
- **Syntax highlighting** for `.hmd` as its own language.
- **Highlighting for HQL** — the extension registers HQL as a language, so a
`.hql` file is coloured, and the body of an `hql` fence is coloured the same
way. The token rules follow the HQL scanner and parser of 0.8.0.
- **Highlighting for a cell in any language** — a fence with a cell suffix,
such as `python#eval`, is coloured as a plain `python` fence is. The
Markdown grammar does not accept `#` after the language, so the extension
has its own fence rules, generated from a table [`syntaxes/fences.mjs`].
The mode, the attributes, and the `hql:output` markers have their own
colours.
- **Fences for the languages of GitHub Linguist** — a fence may name any of
the 770 languages of Linguist 9.7.0 that have a TextMate scope, by name,
alias, or a file extension that one language alone uses. The body is
coloured when an installed extension declares the scope. A rule for any
other fence colours the fence line alone [`syntaxes/languages.json`].
- **Several vaults in one folder** — a vault is discovered by walking up from
the card to the nearest `.hmd/`, stopping at the containing workspace folder,
and the window holds one index, watcher, and diagnostic scope per vault, built
Expand Down
10 changes: 10 additions & 0 deletions examples/highlighting/.hmd/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Project config for the highlighting example: a vault to look at in the
# editor, with HQL cells, fences in many languages, and standalone source
# files. Open it with
# npm run example:highlighting (in tools/hmd-vsc-ext)
# and lint it with
# hmd lint --root examples/highlighting

[discovery]
autodiscovery = true
mode = "both"
10 changes: 10 additions & 0 deletions examples/highlighting/catalog/hql.hmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: HQL
metadata:
year: 2026
typing: static
grammar: extension
---
# HQL

A fence named `hql` is coloured by the grammar this extension carries, and so is a `.hql` file.
10 changes: 10 additions & 0 deletions examples/highlighting/catalog/index.hmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Catalog

One card for each language the cells in [[cells]] count. The header of each
card says where the grammar of the language comes from:

- `built-in`: the editor ships it.
- `extension`: this extension carries it.
- `install`: an extension for the language has to be installed.

The cards: [[python]], [[rust]], [[typescript]], [[hql]], [[kotlin]], [[zig]].
10 changes: 10 additions & 0 deletions examples/highlighting/catalog/kotlin.hmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: Kotlin
metadata:
year: 2011
typing: static
grammar: install
---
# Kotlin

A fence named `kotlin` or `kt` is coloured once an extension for Kotlin is installed.
10 changes: 10 additions & 0 deletions examples/highlighting/catalog/python.hmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: Python
metadata:
year: 1991
typing: dynamic
grammar: built-in
---
# Python

A fence named `python`, `py` or `python3` is coloured by the grammar the editor ships.
10 changes: 10 additions & 0 deletions examples/highlighting/catalog/rust.hmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: Rust
metadata:
year: 2015
typing: static
grammar: built-in
---
# Rust

A fence named `rust` or `rs` is coloured by the grammar the editor ships.
10 changes: 10 additions & 0 deletions examples/highlighting/catalog/typescript.hmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: TypeScript
metadata:
year: 2012
typing: static
grammar: built-in
---
# TypeScript

A fence named `typescript` or `ts` is coloured by the grammar the editor ships.
10 changes: 10 additions & 0 deletions examples/highlighting/catalog/zig.hmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: Zig
metadata:
year: 2016
typing: static
grammar: install
---
# Zig

A fence named `zig` is coloured once an extension for Zig is installed.
139 changes: 139 additions & 0 deletions examples/highlighting/cells.hmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
---
tags: [cells]
---
# Cells

Every kind of HQL fence. The body of each is coloured as HQL, and the line
that opens it has four parts with a colour each: the language, the `#`, the
mode, and the attributes.

## A cell that shows its value

```hql#eval id=languages
/// The `metadata` block in the header of a catalog card.
type Meta { year : Int, typing : String, grammar : String }
type Header : Data { metadata? : Meta }

type Language { name : String, year : Int, typing : String, grammar : String }

cards
| filter(c => c.path.starts_with("catalog/") and c.name != "index")
| flat_map(c => match (c.header | Header).metadata {
some(m) => [Language(name = c.title, year = m.year, typing = m.typing, grammar = m.grammar)],
_ => []
})
| sort(by = l => l.year)
```
<!-- hql:output id=languages hash=2cd4baa0a239 status=ok -->
- Language(name = "Python", year = 1991, typing = "dynamic", grammar = "built-in")
- Language(name = "Kotlin", year = 2011, typing = "static", grammar = "install")
- Language(name = "TypeScript", year = 2012, typing = "static", grammar = "built-in")
- Language(name = "Rust", year = 2015, typing = "static", grammar = "built-in")
- Language(name = "Zig", year = 2016, typing = "static", grammar = "install")
- Language(name = "HQL", year = 2026, typing = "static", grammar = "extension")
<!-- /hql:output -->

## A cell other cells read

`hql#query` is `hql#eval hidden`: it computes a value and shows nothing.

```hql#query id=installable
languages | filter(l => l.grammar == "install")
```

```hql#eval id=static hidden
languages | filter(l => l.typing == "static" and not (l.grammar == "install"))
```

## A table

```hql#eval
// Where the grammar of each language comes from.
fn source(grammar: String) : String = match grammar {
"built-in" => "the editor",
"extension" => "this extension",
_ => "an extension to install"
}

languages
| map(l => { "Language": l.name, "Since": l.year, "Grammar from": source(l.grammar) })
| Table(columns = ["Language", "Since", "Grammar from"])
| format(as = Markdown)
```
<!-- hql:output hash=09a58d02dd9c status=ok -->
| Language | Since | Grammar from |
| ---------- | ----- | ----------------------- |
| Python | 1991 | the editor |
| Kotlin | 2011 | an extension to install |
| TypeScript | 2012 | the editor |
| Rust | 2015 | the editor |
| Zig | 2016 | an extension to install |
| HQL | 2026 | this extension |
<!-- /hql:output -->

## A record

```hql#eval
{
languages: languages | size,
to_install: installable | size,
static_and_ready: static | size,
oldest: languages | map(l => l.year) | min | unwrap_or(0)
}
```
<!-- hql:output hash=a99ab0cad2b7 status=ok -->
| key | value |
| ---------------- | ----- |
| languages | 6 |
| oldest | 1991 |
| static_and_ready | 3 |
| to_install | 2 |
<!-- /hql:output -->

## Literals and operators

```hql#eval
// A string with escapes, an Int, a Decimal, a Float, and a comparison chain.
{
text: "tab\there, quote \"here\", slash \\ here",
whole: 10 % 3 - -4,
exact: 1.5 * 2.25,
rough: 1.5f * 2.0e3f,
truth: true and not false or 1 <= 2,
choice: "few" given (languages | size) < 3 otherwise "many"
}
```
<!-- hql:output hash=7f736bc41d11 status=ok -->
| key | value |
| ------ | ------------------------------------------ |
| choice | "many" |
| exact | 3.375 |
| rough | 3000.0 |
| text | "tab\there, quote \"here\", slash \\ here" |
| truth | true |
| whole | 5 |
<!-- /hql:output -->

## A document reference

```hql#eval
@[[catalog]].title
```
<!-- hql:output hash=48e5ae338462 status=ok -->
Catalog
<!-- /hql:output -->

## A listing is not a cell

A fence marked plain `hql` is shown as code and never runs. It is coloured the
same way.

```hql
cards | filter(c => c.title == "HQL") | map(c => c.path) | first
```

## Tildes

~~~hql#eval id=names
languages | map(l => l.name)
~~~
102 changes: 102 additions & 0 deletions examples/highlighting/fence-forms.hmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
---
tags: [fences]
---
# The forms of a fence

## Backticks and tildes

```python#eval
x = 1
```

~~~python#eval
x = 2
~~~

## A longer fence holds a shorter one

````python#eval id=outer
text = """
```
not the end of the cell
```
"""
````

## Attributes

A value and a bare word, then a quoted value. HQL reads `id` and `hidden`
and no other attribute, so the quoted one is on a Python cell.

```hql#eval id=a hidden
cards | size
```

```python#eval id=b title="Two words" timeout=30 cache
print("attributes")
```

## Upper case

```Python#eval
x = 3
```

```HQL
cards | size
```

## Indented by up to three spaces

```hql#eval
cards | size
```

## No blank line between a paragraph and a fence
```hql
cards | size
```
The paragraph continues here, and `[[links]]` still reads as a link: [[links]].

## Forms that stay with the Markdown grammar

A colon, a comma or a brace after the name is a form of the Markdown grammar,
which reads these two fences.

```python:example.py
x = 4
```

```{.python}
x = 5
```

## Fences the extension does not reach yet

A fence inside a list item or a block quote is read by the Markdown grammar.
A plain `python` fence is coloured there. A cell is not, and an `hql` fence is
not.

- A plain fence in a list:

```python
x = 6
```

- A cell in a list:

```python#eval
x = 7
```

- An HQL fence in a list:

```hql
cards | size
```

> A cell in a quote:
>
> ```hql#eval
> cards | size
> ```
34 changes: 34 additions & 0 deletions examples/highlighting/index.hmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
tags: [meta]
---
# Highlighting

A vault to look at in the editor, and not a vault to read. Each card holds one
kind of thing the extension colours, so that a colour that is missing or wrong
is easy to find.

## Map

- [[cells]]: HQL cells of every kind, with their saved output
- [[languages]]: fences in the languages the editor ships a grammar for
- [[more-languages]]: fences in languages that need an extension, and in none
- [[fence-forms]]: every way to write a fence, and the forms that stay with Markdown
- [[links]]: links, embeds and anchors, alone on a line and inside a sentence
- [[catalog]]: the cards the cells read

## Files that are not cards

- `queries/catalog.hql`: a standalone HQL program that reads this vault
- `queries/shapes.hql`: HQL declarations only, a trait and its implementations
- `src/`: the same small program in Python, Rust and TypeScript

## What to look at

| Where | What should be coloured |
| --- | --- |
| A `.hql` file | Keywords, types, function names, strings, numbers, comments |
| An `hql` fence | The same, inside the card |
| The line that opens a cell | The language, the `#`, the mode, and each attribute |
| A `python#eval` fence | The body, as Python |
| A `kotlin` fence | The opening line only, until an extension for Kotlin is installed |
| An `hql:output` marker | The marker and its attributes |
Loading
Loading