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

Allow re-rendering Markdown preview when updated extra configurations provided by extension #70936

Closed
yhatt opened this issue Mar 22, 2019 · 8 comments
Assignees
Labels
feature-request Request for new features or functionality markdown Markdown support issues verified Verification succeeded
Milestone

Comments

@yhatt
Copy link
Contributor

yhatt commented Mar 22, 2019

If Markdown extension provides some extra settings to affect the rendering of Markdown, it would want to re-render Markdown preview when changed configuration values. In fact, VS Code built-in configurations (e.g. markdown.preview.breaks) will behave like that. (Tested in 1.33.0-insider)

breaks

I have met with such a case while creating a Markdown extension that has configurable rendering, but I could not find a way to re-trigger Markdown rendering manually. markdown.preview.refresh command is meaningless because it just refresh WebView and not triggered a rendering process.

import { ExtensionContext, commands, workspace } from 'vscode'

export const activate = ({ subscriptions }: ExtensionContext) => {
  subscriptions.push(
    workspace.onDidChangeConfiguration(e => {
      if (e.affectsConfiguration('extension.configuration')) {
        // FIXME: `markdown.preview.refresh` won't re-trigger rendering
        commands.executeCommand('markdown.preview.refresh')
      }
    })
  )

  return {
    extendMarkdownIt: md => {
      md.use(() => {
        const conf = workspace.getConfiguration('extension').get('configuration')
        // ... and use configured value in markdown-it plugin ...
      })
    }
  }
}

Thus, user have to change Markdown buffer once for previewing with updated configurations. Probably many users would expect to reflect the changed configuration to preview immediately.

It would be awesome if there was a command (or API for extension) to re-trigger rendering of Markdown.

@vscodebot vscodebot bot added the markdown Markdown support issues label Mar 22, 2019
@mjbvz mjbvz added the help wanted Issues identified as good community contribution opportunities label Mar 22, 2019
@mjbvz
Copy link
Collaborator

mjbvz commented Mar 22, 2019

PRs welcome to make the refresh command re-render

@vitaliymaz
Copy link

Reproducible for me, can I work on the PR?

@vitaliymaz
Copy link

The problem happens with cached tokens here
https://github.com/Microsoft/vscode/blob/2f2085f3e1e3c75916ea950d5c8c2e1e4c28b3dd/extensions/markdown-language-features/src/markdownEngine.ts#L121

It makes a decision whether to recalculate tokens based on the document version and markdown extension configurations. But it doesn't consider changing configurations of markdownItPlugins.

There are two possible solutions I see:

  1. Extract configurations of all plugins which extend markdown base plugin and recalculate tokens if something changed there.
  2. Clean tokens cache on refresh command or pass some force flag.

@mjbvz , maybe you can help me with a decision.

@yhatt
Copy link
Contributor Author

yhatt commented Mar 26, 2019

IMO I prefer 2, a controllable way in per extension.

Some settings defined in Markdown extension would not require clearing cache. I'm afraid to degraded performance.

In addition, I have an extension that must trigger re-rendering Markdown by VSCode native configuration window.zoomLevel. It does not defined in the extension. (marp-team/marp-vscode#8 (comment))

@mjbvz
Copy link
Collaborator

mjbvz commented Mar 31, 2019

@vitaliymaz I'm in favor of the second approach as well: making the refresh command flush the cache. That way it's entirely up to the extension to say when the preview is refreshed

@vitaliymaz
Copy link

@mjbvz, thank you for the feedback. Working on the second approach.

@mjbvz mjbvz added this to the April 2019 milestone Apr 2, 2019
@mjbvz mjbvz added feature-request Request for new features or functionality and removed help wanted Issues identified as good community contribution opportunities labels Apr 2, 2019
@mjbvz
Copy link
Collaborator

mjbvz commented Apr 2, 2019

Fixed by #71442

@mjbvz mjbvz closed this as completed Apr 2, 2019
@yhatt
Copy link
Contributor Author

yhatt commented Apr 3, 2019

Thanks @mjbvz, and @vitaliymaz's awesome work! I'll start to test in the next insider version. Cheers 🍻

UPDATE: 1.34 is getting work 😄

vscode

@aeschli aeschli added the verified Verification succeeded label May 8, 2019
@vscodebot vscodebot bot locked and limited conversation to collaborators May 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality markdown Markdown support issues verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

4 participants