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
Activity
buglessbuild commentedon Aug 20, 2024
@CGNonofr do you have any thoughts on this?
CGNonofr commentedon Aug 20, 2024
createModelReferencecreate a model reference bound to a file, it needs the file to existcreateModelReferencereturns a wrapper to the monaco model indeed,modelRef.object.textEditorModelis the exact same object as the one returned bycreateModel.modelRefis the ref itself you have to dispose when you don't need it anymore,modelRef.objectis a wrapper for the model making the link between the model and the filesystem/workingcopy, allowing you to save/revert changes