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

Extension API: Different Syntax Highlight Schemes for Output Window #72021

Closed
JustinGrote opened this issue Apr 9, 2019 · 2 comments
Closed
Labels
feature-request Request for new features or functionality *out-of-scope Posted issue is not in scope of VS Code output Output channel system issues
Milestone

Comments

@JustinGrote
Copy link
Contributor

JustinGrote commented Apr 9, 2019

Currently the Output Pane syntax highlighting can be performed by having an extension register the text/x-code-output mime type ala https://marketplace.visualstudio.com/itemdetails?itemName=IBM.output-colorizer.

The problem is that there can be only one by one extension for all output windows and as soon as one extension does this it will conflict with others that try to do the same thing. There are multiple extensions (e.g. Azure Functions) that support streaming logs along with standard Git/Terraform/etc. output views, and being able to specify log highlighting on a per output window basis would go a long way to ensuring richer log views and more constant use of the Output Window.

Potential Implementations

  1. Add a feature flag to add the window name to the output window mime type. For example if my Window is named Git then its mime type would be text/x-code-output-Git, if my window is named Terraform than mime type would be text/x-code-output-Terraform.

Now .tmlanguage highlighters can be registered on a per window name basis and different extensions can contribute different syntax highlighters for output windows rather than one "Global" one.

This would ensure broadest compatibility and probably least development effort, but more dynamic output window names may be tricky (perhaps allow wildcards in mime type definition for .tmlanguage)

  1. Make this more explicit, such as registering an output window handler contribution and having vscode handle it natively, or have the extension specify the handler or mime type for the output window to ensure consistency.

Both 1 and 2 can be implemented together to cover both explicit and implicit specification types.

@jrieken jrieken assigned isidorn and unassigned jrieken Apr 10, 2019
@isidorn isidorn assigned sandy081 and unassigned isidorn Apr 10, 2019
@sandy081 sandy081 added feature-request Request for new features or functionality output Output channel system issues labels Apr 11, 2019
@sandy081 sandy081 added this to the Backlog milestone Apr 11, 2019
@sandy081 sandy081 removed their assignment Apr 11, 2019
@sergei-dyshel
Copy link

For all interested, I've found a hacky workaround to change highlighting of output panel depending on its contents.

It seems that output channel is implemented as TextEditor which has document property on which you can use setTextDocumentLanguage. The problem is that setting language for this document changes language for all output channels (may be it's the same TextDocument reused or something). So the only way have separate highlighting for different channels is to exploit the fact that only one output can be visible at a time - subscribe to window.onDidChangeActiveTextEditor and apply different language, .e.g

  for (const editor of window.visibleTextEditors) {
    if (editor.document.fileName.startsWith('extension-output'))
      if (editor.document.lineAt(0).text.includes('this is my extension output'))
        vscode.languages.setTextDocumentLanguage(editor.document, 'myLogFormat');
      else
        vscode.languages.setTextDocumentLanguage(editor.document, 'Log');
  }

Also, there is no way to connect between this document/editor and OutputChannel name so one have to analyze text or cache document's name (i.e. extension-output-#7). But at least this workaround can be used to solve existing highlighting conflict between multiple extensions (such as #19561) until proper API is implemented.

@isidorn isidorn added the *out-of-scope Posted issue is not in scope of VS Code label Nov 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality *out-of-scope Posted issue is not in scope of VS Code output Output channel system issues
Projects
None yet
Development

No branches or pull requests

6 participants
@jrieken @isidorn @sergei-dyshel @sandy081 @JustinGrote and others