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
43 changes: 43 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,49 @@ jobs:
echo "The pinned server and the CLI both use comline-core ${server_core:0:7}."
fi

# The keys of `config.idp` (completion and hover in a `.idp`) are core's: core
# keeps a table of what its reader takes, held to the reader by its tests, and
# `src/idpSchema.generated.json` is that file at the rev `package.json` pins
# (`comline.idpSchema.rev`). Fails when the committed copy is not what the pin
# generates, or the pin is not on GitHub.
idp-schema:
name: Config schema
runs-on: ubuntu-24.04
timeout-minutes: 10

steps:
- name: Harden the runner
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit

- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Setup Node.js
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 20.20.2

- name: The committed schema must be core's at the pinned rev
run: node scripts/sync-idp-schema.mjs

# Advisory, like the language-server pin's: core changing what
# `config.idp` takes doesn't fail anything here, so say when the pin is
# behind core's default branch. A failed lookup is a warning too.
- name: The pin should be current
run: |
url=https://raw.githubusercontent.com/ComlineProject/core/HEAD/schemas/config-idp.json
if ! curl -fsSL --retry 3 "$url" -o "$RUNNER_TEMP/config-idp.json"; then
echo "::warning::couldn't fetch core's schemas/config-idp.json to check the pin"
elif cmp -s "$RUNNER_TEMP/config-idp.json" src/idpSchema.generated.json; then
echo "The pinned schema is core's current one."
else
echo "::warning file=package.json::core's schemas/config-idp.json has changed since comline.idpSchema.rev: bump the pin and run 'node scripts/sync-idp-schema.mjs --write'"
fi

package-test:
name: Package Test
runs-on: ubuntu-24.04
Expand Down
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ All notable changes to the "comline-vscode" extension will be documented in this
## [Unreleased]

### Added
- `.idp` completion and hover know every key core reads (#31). Missing before:
`id`, `handshake` (the name, and the dictionary form with `comline@2`'s
`scope`, `newer_consumer`, `same_version_differs` and `exchange`, each with its
values and its default first), `settings`, `unverified`, `encodings` (with
`kind`, `profile` and the per-language `map`) and a dependency's
`accept_unverified`. `wire` lists the formats and framings core declares and
names `datagram@3` as the default framing, and `specification_version` is
described as the edition. Completion marks a key a dictionary needs as
required. Dependency `group` follows core#284.
- The `.idp` schema is generated, not written: core keeps a table of every key its
reader takes (held to the reader by core's tests) and commits it as
`schemas/config-idp.json`; `src/idpSchema.generated.json` is that file at the
core commit `comline.idpSchema.rev` pins, refreshed by
`node scripts/sync-idp-schema.mjs --write`. CI fails when the committed copy
differs from the pin, so the schema can't drift from core again, and warns
when core's schema has moved past the pin.
- The package status bar item's tooltip says which language server and CLI
are in use: each one's version with its `comline-core` commit, and its path
with how it was found (bundled, PATH, custom path, or on the host). The CLI's
Expand Down
10 changes: 9 additions & 1 deletion RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ the CLI's. The server reports its core in `comline-lsp --version`.
> the release builds. Committing that lockfile would make releases fully
> reproducible.

The keys `.idp` completion and hover offer are core's, too: `src/idpSchema.generated.json`
is core's `schemas/config-idp.json` at the core commit
`comline.idpSchema.rev` pins. To follow core, move the pin and run
`node scripts/sync-idp-schema.mjs --write`; CI fails when the committed file is
not what the pin generates, and warns when core's current schema differs from
the pinned one.

The `comline` CLI is **not** bundled. Build/Check/Generate/Clean need it on
`PATH` (see the README's Requirements section).

Expand All @@ -81,7 +88,8 @@ The `comline` CLI is **not** bundled. Build/Check/Generate/Clean need it on
and start a fresh empty `## [Unreleased]` above it. That section becomes
the release notes word for word.
- optionally move `comline.languageServer.rev` to a newer `language-server`
commit
commit, and `comline.idpSchema.rev` to a newer core commit (then
`node scripts/sync-idp-schema.mjs --write`)

Merge it.

Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
"comline": {
"languageServer": {
"rev": "c56715ab44de036544150151a7eaf440d531c323"
},
"idpSchema": {
"rev": "4d5b19ca61871ee52423b8284acf20b664c8cf8e"
}
},
"categories": [
Expand Down Expand Up @@ -268,7 +271,7 @@
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"pretest": "yarn compile",
"test": "node --test out/resolve.test.js out/coreRev.test.js",
"test": "node --test out/resolve.test.js out/coreRev.test.js out/idpSchema.test.js",
"lint": "eslint src --ext ts",
"package": "bash scripts/package.sh",
"link-binary": "bash scripts/link-binary.sh",
Expand Down
63 changes: 63 additions & 0 deletions scripts/sync-idp-schema.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env node
// Keep `src/idpSchema.generated.json`, the keys of `config.idp`, equal to core's.
//
// node scripts/sync-idp-schema.mjs # check; exit 1 on drift
// node scripts/sync-idp-schema.mjs --write # refresh the committed copy
// node scripts/sync-idp-schema.mjs --rev <sha> [--write]
//
// Core keeps a table of every key its `config.idp` reader takes, with types,
// allowed values, defaults and prose (`comline_core::package::config::keys`,
// held to the reader by core's own tests), and commits it as
// `schemas/config-idp.json`. This copies that file at the core commit
// `comline.idpSchema.rev` in package.json pins (`--rev` tries another one), the
// way the docs repo keeps its copy of the `comline.toml` schema. Bump the pin
// when core changes what `config.idp` takes, then `--write`.
//
// Run by CI (`idp-schema` in ci.yml). Node built-ins only, so it runs before
// `yarn install`.

import { readFileSync, writeFileSync } from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";

const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
const copy = path.join(root, "src", "idpSchema.generated.json");

const args = process.argv.slice(2);
const write = args.includes("--write");
const revFlag = args.indexOf("--rev");
const pinned = JSON.parse(readFileSync(path.join(root, "package.json"), "utf8")).comline?.idpSchema?.rev;
const rev = revFlag >= 0 ? args[revFlag + 1] : pinned;
if (!rev || !/^[0-9a-f]{40}$/.test(rev)) {
console.error("sync-idp-schema: no core rev: set comline.idpSchema.rev in package.json (40 hex digits), or pass --rev");
process.exit(2);
}

const url = `https://raw.githubusercontent.com/ComlineProject/core/${rev}/schemas/config-idp.json`;
const response = await fetch(url);
if (!response.ok) {
console.error(`sync-idp-schema: ${url}: ${response.status} ${response.statusText}`);
process.exit(2);
}
const upstream = await response.text();

const name = path.relative(root, copy);
if (write) {
writeFileSync(copy, upstream);
console.log(`wrote ${name} from core ${rev.slice(0, 7)}`);
process.exit(0);
}

let current = "";
try {
current = readFileSync(copy, "utf8");
} catch {
// Missing counts as different.
}
if (current === upstream) {
console.log(`${name}: up to date with core ${rev.slice(0, 7)}`);
} else {
console.error(`${name} differs from ${url}`);
console.error("Refresh with:\n node scripts/sync-idp-schema.mjs --write");
process.exit(1);
}
21 changes: 13 additions & 8 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import {
resolveSchemaAtPath,
resolveFieldByPathAndWord,
idpValueKindLabel,
dictionaryFieldsOf,
mapEntryOf,
IdpFieldSchema,
} from './idpSchema';
import {
Expand Down Expand Up @@ -787,7 +789,7 @@ class LanguagesCompletionProvider {
const item = new CompletionItem(field.key, CompletionItemKind.Field);
item.insertText = field.key;
item.range = range;
item.detail = idpValueKindLabel(field.value);
item.detail = `${idpValueKindLabel(field.value)}${field.required ? ' (required)' : ''}`;
item.documentation = new MarkdownString(field.description);
return item;
});
Expand All @@ -800,7 +802,7 @@ class LanguagesCompletionProvider {
function renderFieldsBlock(fields: IdpFieldSchema[]): string {
const lines = fields.map((f) => ({
keyType: `${f.key}: ${idpValueKindLabel(f.value)}`,
summary: f.summary,
summary: f.required ? `required. ${f.summary}` : f.summary,
}));
const width = Math.max(...lines.map((l) => l.keyType.length));
return lines.map((l) => `${l.keyType.padEnd(width)} // ${l.summary}`).join('\n');
Expand All @@ -818,13 +820,16 @@ function renderFieldHover(field: IdpFieldSchema): MarkdownString {
md.appendMarkdown('---\n\n');
md.appendMarkdown(`${field.description}\n`);

if (field.value.kind === 'dictionary' && field.value.fields.length > 0) {
const fields = dictionaryFieldsOf(field.value);
const entry = mapEntryOf(field.value);
const entryFields = entry ? dictionaryFieldsOf(entry.value) : undefined;
if (fields && fields.length > 0) {
md.appendMarkdown('\n---\n\n#### Fields\n\n');
md.appendCodeblock(renderFieldsBlock(field.value.fields), 'comline-package');
} else if (field.value.kind === 'map' && field.value.entry.value.kind === 'dictionary') {
md.appendMarkdown(`\n---\n\n#### Each entry (${field.value.entry.key})\n\n`);
md.appendMarkdown(`${field.value.entry.description}\n\n`);
md.appendCodeblock(renderFieldsBlock(field.value.entry.value.fields), 'comline-package');
md.appendCodeblock(renderFieldsBlock(fields), 'comline-package');
} else if (entry && entryFields && entryFields.length > 0) {
md.appendMarkdown(`\n---\n\n#### Each entry (${entry.key})\n\n`);
md.appendMarkdown(`${entry.description}\n\n`);
md.appendCodeblock(renderFieldsBlock(entryFields), 'comline-package');
}

return md;
Expand Down
Loading
Loading