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

(Twoslash) Bug: Two files in a single codeblock can fail #36

Open
juancampa opened this issue Dec 28, 2024 · 2 comments
Open

(Twoslash) Bug: Two files in a single codeblock can fail #36

juancampa opened this issue Dec 28, 2024 · 2 comments
Labels
bug Something isn't working twoslash expressive-code-twoslash

Comments

@juancampa
Copy link

Describe the bug

When using the twoslash plugin, if you have a codeblock with multiple files, for example:

// @filename module.ts

...

// @filename index.ts
import * from "module";

...

Typescript will fail to compile because it can't find the module named module.

After digging into it, I noticed that the first @filename was missing by the time the code reaches twoslash. It turns out that the ec "frames" plugin is stripping it away.

The fix is to use this config:

{
  plugins: [ecTwoSlash({})],
  frames: {
    extractFileNameFromCode: false,
  },
},

It wasn't obvious at all and it makes the plugin feel broken. Should we add it to these instructions in the docs?

@juancampa juancampa added bug Something isn't working twoslash expressive-code-twoslash labels Dec 28, 2024
@Adammatthiesen
Copy link
Member

Hi, the // @filename syntax is actually part of the Show Emitted Files system that is part of Twoslash (more specifically the Twoslash VFS) and is not yet supported in EC-Twoslash

Though this information does help me understand part of the reasons things with the Twoslash VFS system aren't working with EC-Twoslash, i actually pull in the full raw code block and overwrite it with the Twoslashed output... so the filename tags are supposed to still be there in the code since i use one of the earliest EC hooks available to plugins to process the whole code block.

A good part of this issue is actually related to the way Twoslash VFS works... or well doesn't work with EC. And have been trying to get a better understanding of what they (Twoslash) are doing under the hood to be able to re-implement this system within EC correctly.

I have an open issue: twoslashes/twoslash#59 but have not gotten any responses.

@hippotastic
Copy link

hippotastic commented Jan 13, 2025

If changing the config of the default plugin plugin-frames actually fixes this, I'd consider this an EC issue I can fix rather than a Twoslash issue. I could ensure that the special @filename syntax is ignored by the frames plugin in order not to interfere with Twoslash.

As my default plugins get prepended to the plugins array internally by the expressive-code package, it could very well be that the plugin-frames processing runs before your Twoslash plugin is able to access the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working twoslash expressive-code-twoslash
Projects
None yet
Development

No branches or pull requests

3 participants