123 456 789 0
123 456 789 0

Reputation: 10865

How to add clickable link on completion items documentation

Is there an api where I can specify to use markup to display links in the documentation tooltip?

The only place where I can find it supports markup are in the hover.

For example:

monaco.languages.register({ id: 'mySpecialLanguage' });

monaco.languages.registerHoverProvider('mySpecialLanguage', {
    provideHover: function(model, position) {
        return xhr('../playground.html').then(function(res) {
            return {
                range: new monaco.Range(1, 1, model.getLineCount(), model.getLineMaxColumn(model.getLineCount())),
                contents: [
                    '**SOURCE** [Im an inline-style link](https://www.google.com)',
                    { language: 'html', value: res.responseText }
                ]
            }
        });
    }
});

monaco.editor.create(document.getElementById("container"), {
    value: '\n\nHover over this text',
    language: 'mySpecialLanguage'
});

function xhr(url) {
    var req = null;
    return new monaco.Promise(function(c,e,p) {
        req = new XMLHttpRequest();
        req.onreadystatechange = function () {
            if (req._canceled) { return; }

            if (req.readyState === 4) {
                if ((req.status >= 200 && req.status < 300) || req.status === 1223) {
                    c(req);
                } else {
                    e(req);
                }
                req.onreadystatechange = function () { };
            } else {
                p(req);
            }
        };

        req.open("GET", url, true );
        req.responseType = "";

        req.send(null);
    }, function () {
        req._canceled = true;
        req.abort();
    });
}

Upvotes: 2

Views: 1352

Answers (1)

tracksaw
tracksaw

Reputation: 11

From the code for the suggestWidget it appears that you can set the ICompletionItem item.suggestion.documentation to be an IMarkdownString (as opposed to a regular string) and the MarkdownRenderer will be used to render it.

export interface IMarkdownString {
    value: string;
    isTrusted?: boolean;
}

Caveat: I happen to have been looking at this code earlier, but have not tried the above suggestion.

Upvotes: 1

Related Questions