Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(typst): add typst completion spec #2144

Merged
merged 1 commit into from
Nov 30, 2023
Merged
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
376 changes: 376 additions & 0 deletions src/typst.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,376 @@
import { filepaths } from "@fig/autocomplete-generators";

const completionSpec: Fig.Spec = {
name: "typst",
description: "The Typst compiler",
icon: "📄",
subcommands: [
{
name: ["compile", "c"],
description: "Compiles an input file into a supported output format",
icon: "📄",
options: [
{
name: "--root",
description: "Configures the project root (for absolute paths)",
args: {
name: "root",
template: "folders",
},
},
{
name: "--font-path",
description: "Adds additional directories to search for fonts",
isRepeatable: true,
args: {
name: "font_paths",
template: "filepaths",
},
},
{
name: "--diagnostic-format",
description: "The format to emit diagnostics in",
args: {
name: "diagnostic_format",
suggestions: ["human", "short"],
default: "human",
},
},
{
name: ["-f", "--format"],
description:
"The format of the output file, inferred from the extension by default",
args: {
name: "format",
suggestions: ["pdf", "png", "svg"],
},
},
{
name: "--open",
description:
"Opens the output file using the default viewer after compilation",
args: {
name: "open",
isVariadic: true,
isOptional: true,
},
},
{
name: "--ppi",
description: "The PPI (pixels per inch) to use for PNG export",
args: {
name: "ppi",
default: "144.0",
},
},
{
name: "--flamegraph",
description: "Produces a flamegraph of the compilation process",
args: {
name: "flamegraph",
isVariadic: true,
isOptional: true,
template: "filepaths",
},
},
{
name: ["-h", "--help"],
description: "Print help",
},
],
args: [
{
name: "input",
description: "Path to input Typst file",
generators: filepaths({
extensions: ["typ"],
}),
},
{
name: "output",
description: "Path to output file (PDF, PNG, or SVG)",
isOptional: true,
template: "filepaths",
},
],
},
{
name: ["watch", "w"],
description: "Watches an input file and recompiles on changes",
icon: "🔄",
options: [
{
name: "--root",
description: "Configures the project root (for absolute paths)",
args: {
name: "root",
template: "folders",
},
},
{
name: "--font-path",
description: "Adds additional directories to search for fonts",
isRepeatable: true,
args: {
name: "font_paths",
template: "filepaths",
},
},
{
name: "--diagnostic-format",
description: "The format to emit diagnostics in",
args: {
name: "diagnostic_format",
suggestions: ["human", "short"],
default: "human",
},
},
{
name: ["-f", "--format"],
description:
"The format of the output file, inferred from the extension by default",
args: {
name: "format",
suggestions: ["pdf", "png", "svg"],
},
},
{
name: "--open",
description:
"Opens the output file using the default viewer after compilation",
args: {
name: "open",
isVariadic: true,
isOptional: true,
},
},
{
name: "--ppi",
description: "The PPI (pixels per inch) to use for PNG export",
args: {
name: "ppi",
default: "144.0",
},
},
{
name: "--flamegraph",
description: "Produces a flamegraph of the compilation process",
args: {
name: "flamegraph",
isVariadic: true,
isOptional: true,
template: "filepaths",
},
},
{
name: ["-h", "--help"],
description: "Print help",
},
],
args: [
{
name: "input",
description: "Path to input Typst file",
generators: filepaths({
extensions: ["typ"],
}),
},
{
name: "output",
description: "Path to output file (PDF, PNG, or SVG)",
isOptional: true,
template: "filepaths",
},
],
},
{
name: "query",
description: "Processes an input file to extract provided metadata",
icon: "🔍",
options: [
{
name: "--root",
description: "Configures the project root (for absolute paths)",
args: {
name: "root",
template: "folders",
},
},
{
name: "--font-path",
description: "Adds additional directories to search for fonts",
isRepeatable: true,
args: {
name: "font_paths",
template: "filepaths",
},
},
{
name: "--diagnostic-format",
description: "The format to emit diagnostics in",
args: {
name: "diagnostic_format",
suggestions: ["human", "short"],
default: "human",
},
},
{
name: "--field",
description: "Extracts just one field from all retrieved elements",
args: {
name: "field",
},
},
{
name: "--format",
description: "The format to serialize in",
args: {
name: "format",
suggestions: ["json", "yaml"],
default: "json",
},
},
{
name: "--one",
description: "Expects and retrieves exactly one element",
},
{
name: ["-h", "--help"],
description: "Print help",
},
],
args: [
{
name: "input",
description: "Path to input Typst file",
generators: filepaths({
extensions: ["typ"],
}),
},
{
name: "selector",
description: "Defines which elements to retrieve",
},
],
},
{
name: "fonts",
description: "Lists all discovered fonts in system and custom font paths",
icon: "🔤",
options: [
{
name: "--font-path",
description: "Adds additional directories to search for fonts",
isRepeatable: true,
args: {
name: "font_paths",
template: "filepaths",
},
},
{
name: "--variants",
description: "Also lists style variants of each font family",
},
{
name: ["-h", "--help"],
description: "Print help",
},
],
},
{
name: "update",
description: "Self update the Typst CLI (disabled)",
icon: "🆙",
options: [
{
name: "--force",
description:
"Forces a downgrade to an older version (required for downgrading)",
exclusiveOn: ["--revert"],
},
{
// TODO: Make it impossible to use with one or more of the other specified arguments (e.g version)
name: "--revert",
description:
"Reverts to the version from before the last update (only possible if `typst update` has previously ran)",
exclusiveOn: ["--force"],
},
{
name: ["-h", "--help"],
description: "Print help",
},
],
args: {
name: "version",
description: "Which version to update to (defaults to latest)",
isOptional: true,
},
},
{
name: "help",
description: "Print this message or the help of the given subcommand(s)",
icon: "ℹ️",
subcommands: [
{
name: "compile",
description: "Compiles an input file into a supported output format",
icon: "📄",
},
{
name: "watch",
description: "Watches an input file and recompiles on changes",
icon: "🔄",
},
{
name: "query",
description: "Processes an input file to extract provided metadata",
icon: "🔍",
},
{
name: "fonts",
description:
"Lists all discovered fonts in system and custom font paths",
icon: "🔤",
},
{
name: "update",
description: "Self update the Typst CLI (disabled)",
icon: "🆙",
},
{
name: "help",
description:
"Print this message or the help of the given subcommand(s)",
icon: "ℹ️",
},
],
},
],
options: [
{
name: "--cert",
description:
"Path to a custom CA certificate to use when making network requests",
args: {
name: "cert",
template: "filepaths",
},
},
{
name: ["-v", "--verbosity"],
description:
"Sets the level of logging verbosity: -v = warning & error, -vv = info, -vvv = debug, -vvvv = trace",
isRepeatable: 4,
},
Comment on lines +359 to +364
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit of an edge case, but I think it makes sense to split these into two options.

Suggested change
{
name: ["-v", "--verbosity"],
description:
"Sets the level of logging verbosity: -v = warning & error, -vv = info, -vvv = debug, -vvvv = trace",
isRepeatable: 4,
},
{
name: ["-v"],
description:
"Sets the level of logging verbosity",
isRepeatable: 4,
},
{
name: ["--verbosity"],
args: {
name: "level",
suggestions: ["warning", "error", "info", "debug", "trace"]
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. An option like that --verbosity might be easier to use. Since I am not an typst maintainer, it might be good if you could suggest it for typst.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is verbatim how the command works right now, you can literally repeat --verbosity up to 4 times.

{
name: ["-h", "--help"],
description: "Print help",
},
{
name: ["-V", "--version"],
description: "Print version",
},
],
};

export default completionSpec;