Repository navigation
feat(md,wit): format WIT and nested code inside markdown files #379
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
base: main
Are you sure you want to change the base?
Changes from all commits
79d151e
b8d0577
6c5c53d
969ae33
39e62fc
d184976
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| languages = { | ||
| markdown = { | ||
| grammar.source = { | ||
| git = { | ||
| git = "https://github.com/tree-sitter-grammars/tree-sitter-markdown.git", | ||
| rev = "a0a00f817d02412bd92c54d316f164d827b57b5c", | ||
| subdir = "tree-sitter-markdown", | ||
| }, | ||
| }, | ||
| queries.injections.source.path = "queries/injections.scm", | ||
| }, | ||
| wit.indent = " ", # 4 spaces | ||
| }, | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| (fenced_code_block | ||
| (info_string | ||
| (language) @injection.language) @info | ||
| (code_fence_content) @injection.content | ||
| ; mdBook inline macro | ||
| (#not-match? @info ".*(nofmt|rust).*") | ||
| (#not-match? @injection.content "\\{\\{\\#include") | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. used to skip mdbook directives |
||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| package foo:wasi-http-service; | ||
|
|
||
| world target-world { | ||
| include wasi:http/proxy@0.2.3; | ||
| include wasi:http/proxy@0.2.3; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. up to us what indentation we prefer, this can be set in |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,33 +8,32 @@ has an `add` operation: | |
| ```wit adder | ||
| package docs:adder@0.1.0; | ||
|
|
||
|
|
||
| interface add { | ||
| add: func(x: u32, y: u32) -> u32; | ||
| add: func(x: u32, y: u32) -> u32; | ||
| } | ||
|
|
||
| world adder { | ||
| export add; | ||
| export add; | ||
| } | ||
| ``` | ||
|
|
||
| ```wit calculator | ||
| package docs:calculator@0.1.0; | ||
|
|
||
| interface calculate { | ||
| enum op { | ||
| add, | ||
| } | ||
| eval-expression: func(op: op, x: u32, y: u32) -> u32; | ||
| enum op { | ||
| add, | ||
| } | ||
| eval-expression: func(op: op, x: u32, y: u32) -> u32; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice if we defaulted to a space between items inside an interface.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this apply to worlds as well? We can do only a subset of each as well: world_definition: ($) =>
choice(
$.export_item,
$.import_item,
$.use_item,
$.typedef_item,
$.include_item,
),
// ...
_interface_definition: ($) =>
choice(
$.use_item,
seq(optional($.external_id), choice($.typedef_item, $.func_item)),
), |
||
| } | ||
|
|
||
| world calculator { | ||
| export calculate; | ||
| import docs:adder/add; | ||
| export calculate; | ||
| import docs:adder/add; | ||
| } | ||
|
|
||
| world app { | ||
| import calculate; | ||
| import calculate; | ||
| } | ||
| ``` | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,5 @@ interface add { | |
|
|
||
| world adder { | ||
| include wasi:cli/imports@0.2.0; | ||
|
|
||
| export add; | ||
| } | ||
|
Comment on lines
8
to
-11
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. up to us if we want to preserve double newlines between certain items
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah let's have newlines between this, but only for worlds? I like the idea of separating the imports, includes and exports in a world declaration |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,4 +6,4 @@ interface add { | |
|
|
||
| world adder { | ||
| export add; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,5 @@ interface wall-clock { | |
| seconds: u64, | ||
| nanoseconds: u32, | ||
| } | ||
|
|
||
| now: func() -> datetime; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,5 @@ interface types { | |
| open-at: func( | ||
| path: string, | ||
| ) -> result<descriptor, error-code>; | ||
|
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -33,7 +33,7 @@ WASI 0.3 replaces every `wasi:io` resource with a Canonical ABI primitive. The t | |||
|
|
||||
| A WASI 0.2 read call returned a single `input-stream` resource and surfaced terminal errors only as you consumed it. WASI 0.3 splits those concerns: the call returns a `stream<u8>` for the data and a `future<result<_, error-code>>` for the outcome, packed into a tuple. | ||||
|
|
||||
| ```wit | ||||
| ```wit nofmt | ||||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||
| // WASI 0.2 (filesystem read) | ||||
| read-via-stream: func(offset: filesize) -> result<input-stream, error-code>; | ||||
|
|
||||
|
|
@@ -47,7 +47,7 @@ In WASI 0.3, the caller does not have to drain the stream to learn whether the r | |||
|
|
||||
| WASI 0.2 write paths handed a guest some host-owned resource (an `output-stream`) and let the guest push bytes into it. WASI 0.3 inverts that: the guest supplies the data as a `stream<u8>` value, and the host returns a `future` that resolves once it has finished consuming the stream. | ||||
|
|
||||
| ```wit | ||||
| ```wit nofmt | ||||
| // WASI 0.2: receive an output-stream resource, write into it | ||||
| get-stdout: func() -> output-stream; | ||||
|
|
||||
|
|
@@ -59,7 +59,7 @@ write-via-stream: func(data: stream<u8>) -> future<result<_, error-code>>; | |||
|
|
||||
| WASI 0.2 modeled operations that could suspend as a `start-foo` / `finish-foo` pair, with a `pollable` for readiness in between. WASI 0.3 collapses each pair into a single call: | ||||
|
|
||||
| ```wit | ||||
| ```wit nofmt | ||||
| // WASI 0.2 | ||||
| start-connect: func(network: borrow<network>, remote-address: ip-socket-address) -> result<_, error-code>; | ||||
| finish-connect: func() -> result<tuple<input-stream, output-stream>, error-code>; | ||||
|
|
@@ -77,7 +77,7 @@ The complete per-interface diff lives on [WASI 0.3](https://wasi.dev/releases/wa | |||
| - **`wasi:io` is gone.** The package has no 0.3.0 release. Every resource it exposed (`pollable`, `input-stream`, `output-stream`) is replaced by a Component Model primitive, per the [concept mapping](#concept-mapping) above. | ||||
| - **`wasi:http` collapses from nine resources to two.** The incoming/outgoing × request/response/body matrix plus `future-trailers`, `future-incoming-response`, and `response-outparam` all become `request` and `response`, with `stream<u8>` bodies and a `future` for trailers. The handler is now an `async func`: | ||||
|
|
||||
| ```wit | ||||
| ```wit nofmt | ||||
| // WASI 0.2 | ||||
| handle: func(request: incoming-request, response-out: response-outparam); | ||||
|
|
||||
|
|
||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The repo has a mix of 2 and 4 space indentation for WIT and this helps align it.