shikijs / twoslash

You take some Shiki, add a hint of TypeScript compiler, and 🎉 incredible static code samples
https://shikijs.github.io/twoslash/
MIT License
1.08k stars 54 forks source link

Multi-file + @errors result in wrong error position #135

Open gabro opened 2 years ago

gabro commented 2 years ago

Hello, thanks for this project, it looks really great and I'd love to use it for documenting a library I'm working on.

I've found an issue when trying to work with multiple files and error reporting. Here's a minimized example:

// @filename: sum.ts
export function sum(a: number, b: number): number {
  return a + b;
}

// @filename: main.ts
// @errors: 2345
import { sum } from "./sum";

sum(4, "woops");

The error should be reported at line 3 of the second filename, but it's reported at line 3 of the entire snippet instead:

image

Here's a playground link with the example above https://shikijs.github.io/twoslash/playground?strict=false&resolveJsonModule=true#code/PTAEAEDMEsBsFMB2BDAtvAXKAzgV1QHQAu2AUPAB4AOA9gE5GiS6IDGR0NiO+AFMlkT4ARvDoAaUMMEixAShmpRdUAG9SoUHXhFcdbslABqKQG5SAX1KkQEGAhTosqZNETEyt8GLr1sWACYAZgAWAFZSaFRaBjUeVFALJl8EgCICYDxUVPNSLN4QyVSAdxoaKmxUuVMgA

As an aside, this was especially confusing because I had a ---cut--- before the second file, so the error simply wasn't rendered.

gabro commented 2 years ago

I've tracked this down to https://github.com/microsoft/TypeScript-Website/blob/v2/packages/ts-twoslasher/src/index.ts#L722.

It seems the position of errors is offset correctly, but the line is not.

I'll attempt a fix there

gabro commented 2 years ago

Here it is https://github.com/microsoft/TypeScript-Website/pull/2239