Skip to content

Support for bulk adding models/extraLibs #2030

@StefanRetief

Description

@StefanRetief

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions