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
Support for bulk adding models/extraLibs #2030
Comments
I don't know what's the bottleneck here but for bulk adding extra libs there is The relevant PR was microsoft/monaco-typescript#24 |
Hey @spahnke , thanks for the response. I've tried that and it seems to have the same effect. I believe the bottleneck is the monaco.languages.typescript.typescriptDefaults.setCompilerOptions({
target: monaco.languages.typescript.ScriptTarget.ES2016,
allowNonTsExtensions: true,
moduleResolution: monaco.languages.typescript.ModuleResolutionKind.NodeJs,
module: monaco.languages.typescript.ModuleKind.CommonJS,
noEmit: true,
typeRoots: ["node_modules/@types"]
});
let extraLibs = []
for (let i = 0; i < 500; i++) {
extraLibs.push(
{
content: `export declare function next${i}() : string`,
filePath: monaco.Uri.file(`/node_modules/@types/external${i}/index.d.ts`).toString(true)
}
);
}
monaco.languages.typescript.typescriptDefaults.setExtraLibs(extraLibs);
extraLibs.forEach((lib) => monaco.editor.createModel(lib.content, "typescript", monaco.Uri.parse(lib.filePath)))
monaco.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
noSemanticValidation: false,
noSyntaxValidation: false
})
var jsCode = `import * as x from "external1"
const tt : string = x.next1();`;
monaco.editor.create(document.getElementById("container"), {
model: monaco.editor.createModel(jsCode, "typescript", monaco.Uri.file("main.tsx")),
}); I've found the implementation for the and it appears to fire the |
Running your code with monaco.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
noSemanticValidation: true,
noSyntaxValidation: true,
noSuggestionDiagnostics: true
}) the language service reacts pretty fast so I don't think it's the model creation. It's more likely the 500 simultaneous requests to the language service to validate all those models. The validation is done in this class more specifically here if you want to play around with that. Unfortunately, I don't know another way to bulk add models and circumvent those language service requests. Good luck! |
Ah that's probably it. That's interesting. Maybe I'll try looking into a work around to exclude validation of the models that share a url with an extralib. That definitely helps, thanks! Edit: For anyone having the same issue, I've found that the best solution was to clone the monaco-typescript repo and customize how the validation works. I've adjusted it for myself so that any models that share the same url as an extralib will not be validated. Loading time has decreased significantly for situations where I have loaded a bunch of declaration files with that I'd also like to easily peek/go to definition with. |
Cool, I was having this perf issue myself yesterday in microsoft/monaco-typescript#64 while looking to see if I can make Monaco models for all of the lib.d.ts files shipped in monaco-ts. Thanks for the explanation, makes sense |
No worries. I should just mention, the method I used did have a side effect. |
monaco-editor version: 0.20.0
Browser: Chrome
OS: Windows
Playground code that reproduces the issue:
In the above sample, I can try to add 500 models to the editor. Normally, in small numbers, adding models isn't in issue, however, when adding more than about 100, I end up with "Loading..." when trying to hover over a function or import for about a minute or two.
The text was updated successfully, but these errors were encountered: