-
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
Peek reference and preview definition don't work across models #935
Comments
So I was able to get this to work by overriding const editor = monaco.editor.create(
document.getElementById("container"),
{},
{
textModelService: {
createModelReference: resource => {
const resourceModel = monaco.editor.getModel(resource);
const simpleModel = resourceModel
? new SimpleModel(resourceModel)
: null;
return window.monaco.Promise.as({
object: simpleModel,
dispose: () => {}
});
},
registerTextModelContentProvider: () => ({ dispose: () => {} })
}
}
); @alexandrudima does this look ok to you? |
If it works, then that's great. But be aware that this is internal API and things might break in the future... The standalone editor services are defined here: and here: |
I'll keep an eye out for changes. Thanks for the list By the way we adopted Monaco at repl.it and are using language servers https://repl.it/site/blog/intel. It's a really cool and transformative project, thank you for maintaining it. |
Was able to get peek, find all references and goto definition work across multiple models/tabs - had to override textModelService (as discussed earlier). This is how code change while creating monaco editor instance looks like for me .. const editor = monaco.editor.create(document.getElementById("container")!, {
glyphMargin: true,
lightbulb: {
enabled: true
},
}, {
editorService: tkeLangCodeEditorService,
textModelService: {
createModelReference: function(uri: monaco.Uri) {
const textEditorModel = {
load() {
return Promise.resolve(textEditorModel)
},
dispose() {},
textEditorModel: monaco.editor.getModel(uri)
}
return Promise.resolve({
object: textEditorModel,
dispose() {}
})
},
registerTextModelContentProvider: () => ({ dispose: () => {} })
}
}); to make goto definition work across multiple models/tabs, had to override editorService - findModel and doOpenEditor methods. As these function are defined to work in single editor / tab environment .. Existing standalone editorService implementation - with URI check in findModel: StandaloneCodeEditorServiceImpl.prototype.findModel = function (editor, resource) {
var model = editor.getModel();
if (model.uri.toString() !== resource.toString()) {
return null;
}
return model;
}; Enhancement to make it work for multiple models/tab: StandaloneCodeEditorServiceImpl.prototype.findModel = function (editor, resource) {
var model = null;
if(resource !== null)
model = monaco.editor.getModel(resource);
if(model == null) {
model = editor.getModel()
}
return model;
};
StandaloneCodeEditorServiceImpl.prototype.doOpenEditor = function (editor, input) {
var model = this.findModel(editor, input.resource);
//set editor to new model
if(model)
editor.setModel(model);
if (!model) {
if (input.resource) {
var schema = input.resource.scheme;
if (schema === Schemas.http || schema === Schemas.https) {
// This is a fully qualified http or https URL
windowOpenNoOpener(input.resource.toString());
return editor;
}
}
return null;
}
var selection = input.options.selection;
if (selection) {
if (typeof selection.endLineNumber === 'number' && typeof selection.endColumn === 'number') {
editor.setSelection(selection);
editor.revealRangeInCenter(selection, 1 /* Immediate */);
}
else {
var pos = {
lineNumber: selection.startLineNumber,
column: selection.startColumn
};
editor.setPosition(pos);
editor.revealPositionInCenter(pos, 1 /* Immediate */);
}
}
return editor;
}; |
Reproduction steps:
Same thing happens with peek definition with a different error.
Seems like the model resolution is failing.
Example simple code:
The text was updated successfully, but these errors were encountered: