question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for bulk adding models/extraLibs

See original GitHub issue

monaco-editor version: 0.20.0 Browser: Chrome OS: Windows Playground code that reproduces the issue:

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"]
});

for (let i = 0; i < 500; i++) {
    monaco.languages.typescript.typescriptDefaults.addExtraLib(
        `export declare function next${i}() : string`,
        `file:///node_modules/@types/external${i}/index.d.ts`
    )
    monaco.editor.createModel(`export declare function next${i}() : string`, "typescript", monaco.Uri.file(`/node_modules/@types/external${i}/index.d.ts`));
    
}

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")),
});

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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
spahnkecommented, Jul 8, 2020

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 https://github.com/microsoft/monaco-typescript/blob/778ace10c0b702197eb06a3a1dc3b62b46eb5ceb/src/languageFeatures.ts#L90

more specifically here https://github.com/microsoft/monaco-typescript/blob/778ace10c0b702197eb06a3a1dc3b62b46eb5ceb/src/languageFeatures.ts#L173-L181

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!

0reactions
StefanRetiefcommented, Jul 16, 2020

No worries. I should just mention, the method I used did have a side effect. eagerModelSync had to be set to false, otherwise I ran into performance issues with validating the model as the user types (i.e. marker data would lag behind whatever the user typed by about 1-2 seconds). Setting it to false corrected the issue and didn’t seem to cause any other issues that I have found.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bulk add members to a distribution list - Microsoft Community
I need to bulk add member of my organization to a new distribution list. I have been using PowerShell commands but can't get...
Read more >
How to Add Bulk Users to Distribution Group in Office 365 via ...
This blog helps admins add multiple members to the distribution group using PowerShell. The script accepts bulk users through import CSV and ...
Read more >
Add/update multiple devices in bulk - AlgoSec
Open a text or csv file, and add a list of comma separated column headers. Each column header supports a device property or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found