I am using monaco-editor and I would like to include suggestions from multiple files. I am not sure what is the best way to do it but basically, I want that when I am exporting some functions in a file2.js, to be able to access that from another file1.js in the suggestions.
Any idea on how to achieve that ? Thank you !
file1
var express = require('express');
var pug = require('pug');
var config = require('./config');
var fs = require('fs');
var router = express.Router();
var utils = require('/utils');
// Here I would like to use the function newTest from the other file
but it does not show in the suggestions
router.get('/', function (req, res) {
console.log("ip - ", req.connection.remoteAddress)
res.send(pug.compileFile('views/main.pug')({
config
}))
});
module.exports = router;
file2
function newTest() {
}
module.exports.newTest = newTest;
editorFile
$(document).ready(function() {
// I prefetch my models, then I have a callback to create an instance of the editor
preFetchAllModels(function() {
var models = monaco.editor.getModels();
// I check that I have my models (file1 and file2) prefetched before creating the editor
console.log("models", models);
monaco.languages.typescript.javascriptDefaults.setEagerModelSync(true)
monacoEditor = monaco.editor.create(document.getElementById("editor"), {
value: "loading...",
language: "javascript",
theme: 'monokai',
lineHeight: 20,
fontSize: 16,
wordWrap: "bounded",
automaticLayout: true,
wrappingIndent: 'indent'
});
});
Component { code: string = ''; codeEditorOptions = { theme: 'vs-dark', language: 'json', automaticLayout: true }; ... } import {MonacoEditorModule} from 'ngx-monaco-editor'; ... @NgModule({ ... imports: [ ..., MonacoEditorModule.
The easiest way to use the react-monaco-editor with create-react-app is to use the react-app-rewired project. For setting it up, the following steps are required: Install react-app-rewired : npm install -D react-app-rewired. Replace react-scripts by react-app-rewired in the scripts section of your packages.
To achieve the goal of IntelliSense across multiple files, you need to use a single instance of monaco.editor
and for each file you want IntelliSense for, initialize a new model, during application boot. Additionally, for autocompletion support,
you must implement a completion item provider. Read below for more details.
const myEditorInstance = monaco.editor.create({ ... , model: null })
to create a single editor instance.monaco.editor.createModel(...)
where n
is the number of files.monaco.languages.typescript.javascriptDefaults.setEagerModelSync(true)
.monaco.editor.getModels()
.myEditorInstance.setModel(model)
.myEditorInstance.saveViewState()
.myEditorInstance.restoreState()
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With