nextflow-io / vscode-language-nextflow

Nextflow language support for Visual Studio Editor
MIT License
32 stars 14 forks source link

Support DAG previews offline #56

Open bentsherman opened 1 week ago

bentsherman commented 1 week ago

The VS Code extension uses a webview to render DAG previews, and the webview HTML simply embeds the mermaid-js library, which means the library is downloaded when the webview is created:

This means it requires an internet connection. So it would be nice to embed the mermaid-js library into the extension somehow so that it works offline.

I thought we might be able to import it as a server-side dependency, but it turns out that mermaid-js relies on the browser context (!) to render the SVG code. So it seems like we have to do it in the browser (or the mermaid CLI, which just spins up a headless browser...)

Instead, maybe it's possible to reference some kind of "resource" path here instead of an http url:

https://github.com/nextflow-io/vscode-language-nextflow/blob/b98a5ac48744e7fca572a3ff3a3010e96363bcce/src/main/ts/extension.ts#L117

Need to investigate whether that's possible with vs code extensions

joaquimgamero commented 2 days ago

I think it would help if we bundle mermaid into the package of the extension itself in the webpack config:

 plugins: [
    new CopyWebpackPlugin({
      patterns: [
        { 
          from: 'node_modules/mermaid/dist/mermaid.esm.min.js', 
          to: 'resources/mermaid.js' 
        }
      ]
    })
  ]

Then we can refer to mermaid as the bundled "copy" instead of the one from the CDN. I can give it a go if you want @bentsherman

bentsherman commented 2 days ago

Sounds good, feel free to give it a try!