You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was going through the README and found this new method of creating a model using createModelReference. I'm using a websocket LSP server to provide LSP support in the Monaco editor. So, do I still need to create fileSystemProvider and other things before using createModelReference or can I simply replace createModel with createModelReference without making any other changes?
import*asmonacofrom'monaco-editor'import{RegisteredFileSystemProvider,RegisteredMemoryFile,registerFileSystemOverlay}from'@codingame/monaco-vscode-files-service-override'constfileUri=monaco.Uri.file(<fileuri>);
// Do I always need these three lines before creating a reference of the model
const fileSystemProvider = new RegisteredFileSystemProvider(false)
fileSystemProvider.registerFile(new RegisteredMemoryFile(fileUri, <filecontent>))
const overlayDisposable = registerFileSystemOverlay(1, fileSystemProvider)
const modelRef = await monaco.editor.createModelReference(fileUri)
const editor = monaco.editor.create({model: modelRef.object.textEditorModel})
One more thing: It seems like all the methods we used to access, like model.updateOptions, have been moved inside modelRef.object.textEditorModel. Am I right?
So, do I still need to create fileSystemProvider and other things before using createModelReference or can I simply replace createModel with createModelReference without making any other changes?
createModelReference create a model reference bound to a file, it needs the file to exist
One more thing: It seems like all the methods we used to access, like model.updateOptions, have been moved inside modelRef.object.textEditorModel. Am I right?
createModelReference returns a wrapper to the monaco model indeed, modelRef.object.textEditorModel is the exact same object as the one returned by createModel. modelRef is the ref itself you have to dispose when you don't need it anymore, modelRef.object is a wrapper for the model making the link between the model and the filesystem/workingcopy, allowing you to save/revert changes
This discussion was converted from issue #482 on August 21, 2024 12:09.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hello Team,
I was going through the README and found this new method of creating a model using
createModelReference. I'm using a websocket LSP server to provide LSP support in the Monaco editor. So, do I still need to createfileSystemProviderand other things before usingcreateModelReferenceor can I simply replacecreateModelwithcreateModelReferencewithout making any other changes?One more thing: It seems like all the methods we used to access, like
model.updateOptions, have been moved insidemodelRef.object.textEditorModel. Am I right?Thank you for your help!
All reactions