-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Hovers don't support syntax highlighting like VS Code #802
Comments
This is very important code editing feature I believe. |
Just in case I tried writing a code block explicitly in Markdown but it didn't colour anything. monaco.languages.register({ id: 'mySpecialLanguage' });
monaco.languages.registerHoverProvider('mySpecialLanguage', {
provideHover: function(model, position) {
return {
range: new monaco.Range(1, 1, model.getLineCount(), model.getLineMaxColumn(model.getLineCount())),
contents: [
{ value: '**asdf**' },
{ value:
'```js\n' +
'var x = blah.toString();\n' +
'```\n'
},
{ value:
'```JavaScript\n' +
'var x = blah.toString();\n' +
'```\n'
}
]
}
}
});
monaco.editor.create(document.getElementById("container"), {
value: 'Hover over this text',
language: 'mySpecialLanguage'
}); |
@rcjsuen could you try with another example? the one from |
@AlexTugarev I'm not sure what case you would like tested exactly but it seems like Monaco is very selective about what "language" it supports in its Markdown code blocks. Consider the following piece of code where monaco.languages.registerHoverProvider('javascript', {
provideHover: function(model, position) {
return {
range: new monaco.Range(1, 1, model.getLineCount(), model.getLineMaxColumn(model.getLineCount())),
contents: [
{ value:
'```js\n' +
'var x = "string";\n' +
'```\n'
},
{ value:
'```javascript\n' +
'var x = "string";\n' +
'```\n'
},
{ value:
'```JavaScript\n' +
'var x = "string";\n' +
'```\n'
}
]
}
}
});
monaco.editor.create(document.getElementById("container"), {
value: '// hover here',
language: 'javascript'
}); |
The discrepancy is because in PR welcome. |
The coloring is given by the tokenizer. VS Code uses a TM grammar for TypeScript: While the editor uses the TS lexer to generate tokens: They will never match, given the source code is tokenized with two different tokenization engines. But equal effects can be achieved if you would write a different tokenizer... |
monaco-editor version: 0.11.x in the playground
Browser: Version 65.0.3325.181 (Official Build) (64-bit)
OS: Windows 10
If you try to hover over
toString()
, you'll get no syntax highlighting in the browser but you'll get something in VS Code.VS Code 1.21.1
Monaco playground
The text was updated successfully, but these errors were encountered: