Skip to content

special characters (<,>,&) not rendered correctly in intellisense preview #65956

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

Closed
sandy081 opened this issue Jan 3, 2019 · 9 comments
Closed
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug editor-hover Editor mouse hover important Issue identified as high-priority regression Something that used to work is now broken verified Verification succeeded

Comments

@sandy081
Copy link
Member

sandy081 commented Jan 3, 2019

We used backtick-enclosed strings for types and since everything is escaped now to render a custom hover window, the error messages are illegible now, for example:

current output

note: expected type std::option::Option&lt;std::string::String&gt; found type std::option::Option&lt;&amp;std::string::String&gt;

previous output

note: expected type std::option::Option<std::string::String> found type std::option::Option<&std::string::String>

Ref - rust-lang/vscode-rust#479
Regression from #62370

@sandy081 sandy081 added bug Issue identified by VS Code Team member as probable bug editor-hover Editor mouse hover regression Something that used to work is now broken labels Jan 3, 2019
@sandy081 sandy081 added this to the November 2018 Recovery milestone Jan 3, 2019
@sandy081 sandy081 self-assigned this Jan 3, 2019
@sandy081
Copy link
Member Author

sandy081 commented Jan 3, 2019

@jrieken I was assuming we do not support markdown strings in diagnostic message? Was it leaking somehow before?

@jrieken
Copy link
Member

jrieken commented Jan 3, 2019

I was assuming we do not support markdown strings in diagnostic message?

Is this really a diagnostic message and not just a hover?

@sandy081
Copy link
Member Author

sandy081 commented Jan 4, 2019

It is a diagnostic message like follow

const message = "`std::option::Option<&std::string::String>`";

@hokein
Copy link

hokein commented Jan 4, 2019

I encountered this issue (VSCode 1.30.1 ) as well:

  1. The C++ LSP server (clangd) sends the hover content Declared in function main\n\nstd::vector<std::string> s to vscode
  2. The hover dialog renders the content like below, the <> around std::string is missing

image

@sandy081
Copy link
Member Author

sandy081 commented Jan 7, 2019

Ok, I see the issue. It is because, I am rendering the diagnostic message as markdown and I am escaping the string only for html content. Strangely markdown renderer is not rendering markdown tags always but only some times. For example

"`std::option::Option<&std::string::String>`"

Markdown tag (tick) is not considered in above case where as it is in following

"this is new line\n\n`std::option::Option<&std::string::String>`"

@sandy081
Copy link
Member Author

sandy081 commented Jan 7, 2019

Analysis

In order to have nice hover for a diagnostic, I was generating the html and sending it using markdown string. While doing this, I am escaping the message, but the markdown tags are not escaped and they are getting rendered.

Fix

Quick and safe fix is to revert the above change.

The proper fix would be is to move diagnostic hover rendering as an editor contribution. Otherwise, it is quiet impossible to generate a model hover decoration for a diagnostic that shows message and details (source+code) nicely as I can only provide string or markdown string.

@sandy081 sandy081 mentioned this issue Jan 7, 2019
@sandy081 sandy081 added the important Issue identified as high-priority label Jan 7, 2019
@sandy081 sandy081 closed this as completed Jan 7, 2019
@mjbvz
Copy link
Collaborator

mjbvz commented Jan 8, 2019

@sandy081 I just tested this in 61122f8 with the following extension:

import * as vscode from 'vscode';

export function activate(context: vscode.ExtensionContext) {
    vscode.languages.registerHoverProvider('markdown', new Provider())
}

class Provider implements vscode.HoverProvider {
    provideHover(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): vscode.ProviderResult<vscode.Hover> {
        return new vscode.Hover("std::option::Option<std::string::String> found type std::option::Option<&std::string::String>");
    }
}

I still see the content being treated as markdown:

screen shot 2019-01-07 at 5 20 43 pm

@mjbvz mjbvz reopened this Jan 8, 2019
@mjbvz mjbvz added the verification-found Issue verification failed label Jan 8, 2019
@sandy081 sandy081 closed this as completed Jan 8, 2019
@sandy081 sandy081 removed the verification-found Issue verification failed label Jan 8, 2019
@sandy081
Copy link
Member Author

sandy081 commented Jan 8, 2019

Fix is for Diagnostic messages and not for hover providers. Please verify using a diagnostic provider.

'use strict';
import * as vscode from 'vscode';

export function activate(context: vscode.ExtensionContext) {

    const diagnosticsCollection = vscode.languages.createDiagnosticCollection('test');
    vscode.window.onDidChangeActiveTextEditor(e => {
        if (e && e.document) {
            const diagnostics: vscode.Diagnostic[] = [];
            let message = "std::option::Option<std::string::String> found type std::option::Option<&std::string::String>";
            const diagnostic = new vscode.Diagnostic(new vscode.Range(new vscode.Position(10, 1), new vscode.Position(10, 10)), message, vscode.DiagnosticSeverity.Error);
            diagnostic.source = 'test';
            diagnostic.code = 'something';
            diagnostics.push(diagnostic);
            diagnosticsCollection.set(e.document.uri, diagnostics);
        }
    });


}


// this method is called when your extension is deactivated
export function deactivate() {
}

image

@joaomoreno
Copy link
Member

LGTM
image

@joaomoreno joaomoreno added the verified Verification succeeded label Jan 8, 2019
@vscodebot vscodebot bot locked and limited conversation to collaborators Feb 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug editor-hover Editor mouse hover important Issue identified as high-priority regression Something that used to work is now broken verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

7 participants
@joaomoreno @jrieken @hokein @kieferrm @sandy081 @mjbvz and others