Skip to content

WebAssembly bindings for the Rust codespan-reporting crate

License

Notifications You must be signed in to change notification settings

Chriscbr/codespan-wasm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

codespan-wasm

An unnofficial set of Node.js bindings for codespan-reporting - a library for generating beautiful diagnostics for text-based programming languages.

Example preview

Usage

const diagnostic = emitDiagnostic([{
  name: "FizzBuzz.fun",
  source: `module FizzBuzz where

fizz₁ : Nat → String
fizz₁ num = case (mod num 5) (mod num 3) of
    0 0 => "FizzBuzz"
    0 _ => "Fizz"
    _ 0 => "Buzz"
    _ _ => num

fizz₂ : Nat → String
fizz₂ num =
    case (mod num 5) (mod num 3) of
        0 0 => "FizzBuzz"
        0 _ => "Fizz"
        _ 0 => "Buzz"
        _ _ => num`,
}], {
  severity: "error",
  message: "`case` clauses have incompatible types",
  code: "E0308",
  labels: [
    {
      style: "primary",
      fileId: "FizzBuzz.fun",
      rangeStart: 328,
      rangeEnd: 331,
      message: "expected `String`, found `Nat`",
    },
    {
      style: "secondary",
      fileId: "FizzBuzz.fun",
      rangeStart: 211,
      rangeEnd: 331,
      message: "`case` clauses have incompatible types",
    },
    {
      style: "secondary",
      fileId: "FizzBuzz.fun",
      rangeStart: 258,
      rangeEnd: 268,
      message: "this is found to be of type `String`",
    },
    {
      style: "secondary",
      fileId: "FizzBuzz.fun",
      rangeStart: 284,
      rangeEnd: 290,
      message: "this is found to be of type `String`",
    },
    {
      style: "secondary",
      fileId: "FizzBuzz.fun",
      rangeStart: 306,
      rangeEnd: 312,
      message: "this is found to be of type `String`",
    },
    {
      style: "secondary",
      fileId: "FizzBuzz.fun",
      rangeStart: 186,
      rangeEnd: 182,
      message: "expected type `String` found here",
    },
  ],
  notes: [`expected type \`String\`
    found type \`Nat\``],
}, {
  displayStyle: "rich",
  chars: CHARS_ASCII,
});
console.log(diagnostic);

Future work

Add a cleaner API for emitting diagnostics, using the builder pattern.

Contributing

Contributions are welcome.