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
Markers are not shown in readonly models #311
Comments
This is by design, because seeing errors on read only editors is not helpful to end users (i.e. there is no way to "fix" them since the editor is read only). You could try to workaround this using |
You have not considered the case where the source code is generated. The user would want to check the generated code with error markers shown, which, I suspect, could be one of the main use cases of a readonly model in the first place, if not the only one. If the user would just want to have something shown to them, they can use |
Also, the workaround doesn't work because:
I even tried to set the editable region to |
Being able to display markers (info/warning) in read-only mode would be helpful. Our application is a read-only code browser for Scala and it would be really nice to be able display markers such as compiler warnings or info messages reported by libraries (for example, http://getquill.io/ reports compile-time generated SQL queries). |
I want this feature in https://mysticatea.github.io/vue-eslint-demo/ My use case is:
|
Are there any updates on this issue or useable workarounds? |
I need this feature too! I'm using Monaco as a read-only view for JSON content. The user can't edit the content in this editor instance, but they're still the source of the content, and seeing validation errors is still very important. This seems like an unnecessary and fairly arbitrary restriction to me. |
A little background on what it'd take to change this:
Testing locally, replacing the My one concern is that VS Code (and other users) likely depend on this behaviour as their way of hiding validation errors in cases where users really don't want to see them. We could solve that with a new Monaco option ( What do you think? (In the meantime, I'd love other suggestions for workarounds! This is a major problem for my application, as showing nice validation errors is one of the main reasons I'm using Monaco) |
Current workaround that I'm using is to reset the model in custom read-only mode. Below example is specific to ReactJS, but would work similarly in any other framework. Drawback is that the cursor still moves when typing (can probably be prevented by storing and resetting cursor position as well), and you'll have to provide a custom "read-only" message elsewhere in your application.
|
Nice, thanks @tsiq-bertram! I've tested that out but, as you mentioned, it does have some awkward side effects. I think I've found a side-effect free workaround: function enableMarkers(model) {
if (!model) return;
[
['getLineDecorations', 2],
['getLinesDecorations', 3],
['getDecorationsInRange', 2],
['getOverviewRulerDecorations', 1],
['getAllDecorations', 1],
].forEach(([functionName, maxArgs]) => {
const originalMethod = model[functionName];
model[functionName] = function() {
return originalMethod.apply(this, Array.from(arguments).slice(0, maxArgs));
};
});
} That code takes every method on the model for the line decorations which takes a To make it work, you just need to call this function on the model any time it changes. I'm doing that with: enableMarkers(editor.getModel());
editor.onDidChangeModel(() => enableMarkers(editor.getModel())); Seems to work perfectly. All other readonly behaviour works as before, but now decorations appear as well. This is decidedly fragile in the face of future changes to the model of course, but at a glance I wouldn't expect these methods to be changing drastically any time soon, so that's acceptable for my case. |
The workaround we got is this: onDidChangeContentGuard = 0;
...
onDidChangeContent = e => {
let model = this._editor.getModel();
if (this.props.readOnly) {
if (this.onDidChangeContentGuard === 0) {
this.onDidChangeContentGuard++;
try {
const viewStates = this._editor.saveViewState();
model.setValue(this.props.binding.value);
this._editor.restoreViewState(viewStates);
} finally {
this.onDidChangeContentGuard--;
}
}
return;
}
...
}; I think this is less intrusive. |
microsoft/vscode@c7cc30c adds a new editor option, |
This will be verified via microsoft/vscode#89057 |
monaco-editor npm version: 0.7.0
Browser: All
OS: All
monaco.editor.setModelMarkers
does not have an effect if the module is readonly.The text was updated successfully, but these errors were encountered: