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

[Feature Request] Display a table in diagnostic window of Monaco Editor #2856

Closed
2 tasks done
chengtie opened this issue Dec 27, 2021 · 5 comments
Closed
2 tasks done
Labels

Comments

@chengtie
Copy link

Context

  • This issue is not a bug report. (please use a different template for reporting a bug)
  • This issue is not a duplicate of an existing issue. (please use the search to find existing issues)

Description

(* I don't know if it is an existing feature or not *)

In this sample of Monaco Editor, when we hover on the Hover over this text, we could see markdown result in the diagnostic window. The contents of the window are provided by the code:

	contents: [
	    { value: '**SOURCE**' },
		{ value: '```html\n' + res.responseText.substring(0, 200) + '\n```' }
	]

I'm wondering if it is possible to draw a table in the diagnostic window.

enter image description here

I tried to add { value: '| a | b | c | d | e | |---|---|---|---|---| | 1 | 2 | 3 | 4 | 5 |'}, it did not work.

Could anyone help?

@chengtie chengtie added the feature-request Request for new features or functionality label Dec 27, 2021
@rcjsuen
Copy link
Contributor

rcjsuen commented Dec 27, 2021

I tried to add { value: '| a | b | c | d | e | |---|---|---|---|---| | 1 | 2 | 3 | 4 | 5 |'}, it did not work.

@chengtie You can achieve this with raw HTML and specifying supportHtml. You may also be interested in #801.

image

table, th, td {
  border: 1px solid black;
}
monaco.languages.register({ id: 'mySpecialLanguage' });

monaco.languages.registerHoverProvider('mySpecialLanguage', {
    provideHover: function (model) {
        return {
            range: new monaco.Range(1, 1, model.getLineCount(), model.getLineMaxColumn(model.getLineCount())),
            contents: [
                {
                    value: "<table><tr><td>abc</td><td>123</td></tr><tr><td>abc</td><td>123</td></tr></table>",
                    supportHtml: true
                },
            ]
        }
    }
});

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

@chengtie
Copy link
Author

@rcjsuen Thank you, that works great!

Additionally, i guess it is impossible to use table solutions like https://github.com/handsontable/handsontable here?

@spahnke
Copy link
Contributor

spahnke commented Dec 27, 2021

You can use a template string for that (the line breaks are important for the table rendering).

CSS (augmented from post above):

.monaco .hover-content table, th, td {
    border: 1px solid black;
}

Hover element:

contents: [
    { value: '**SOURCE**' },
    { value: `
| a | b | c | d | e |
|---|---|---|---|---|
| f | g | h | i | j |` 
    }
]

@chengtie
Copy link
Author

@spahnke it works, thank you!

Again, i guess it is impossible to use table solutions like https://github.com/handsontable/handsontable here?

@hediet hediet added question and removed feature-request Request for new features or functionality labels Jan 3, 2022
@alexdima
Copy link
Member

@chengtie It is not possible to render a special table widget inside the hover via the hover provider.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants