microsoft / microsoft/monaco-editor
[Bug] Sometimes Monaco loads extraLibs into models which causes IntelliSense to blow up
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 46.8k
- Forks
- 4.1k
- Avg merge
- 17h 58m
- Merged PRs (30d)
- 1
Description
Reproducible in vscode.dev or in VS Code Desktop?
- Not reproducible in vscode.dev or VS Code Desktop
Reproducible in the monaco editor playground?
- Not reproducible in the monaco editor playground
Monaco Editor Playground Code
fetch('https://unpkg.com/@avst-types/runtime@0.14.1/index.d.ts')
.then(res => res.text())
.then(dts => {
monaco.editor.create(document.getElementById('container'), {
value: "export const initialize: InitializeFunction = async (event, context) => {\n\n}",
language: 'typescript',
});
monaco.languages.typescript.typescriptDefaults.setExtraLibs([{
content: dts,
filePath: 'file:///node_modules/@types/avst-types__runtime/index.d.ts'
}])
// monaco.editor.createModel(dts, undefined, monaco.Uri.file('file:///node_modules/@types/avst-types__runtime/index.d.ts'))
})
Actual Behavior
https://user-images.githubusercontent.com/9930079/145574787-3dcb1c66-e256-401f-a78e-2f3293b1d711.mov
As seen in the video. Initially IntelliSense works properly for context argument, inferring the type. But when I do SHIFT+F12 it breaks afterwards, the type then becomes any. It seems to be the issue of Monaco then going and loading this file of ambient types as a model (verified by debugging locally) and then TS is going to get confused because there are 2 identical files loaded both having the same types in it. If I go and dispose the model that Monaco created under the hood, then IntelliSense gets fixed.
If I replace loading those types using setExtraLibs, but creating the model for it instead in the first place, effectively preventing Monaco creating duplications, then it works correctly, but I no longer can do SHIFT+F12 to go to the reference.
Expected Behavior
IntelliSense not breaking when Monaco loads libs added via setExtraLibs into modules when it needs to.
Additional Context
When loading libs into Monaco, which is the correct API to do it these days, still using setExtraLibs or creating models for them? Apparently creating modes will break IntelliSense elsewhere (preventing SHIFT+F12 lookup).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the playground example using setExtraLibs, monaco.editor.create, and createModel, then trace what happens when SHIFT+F12 loads an extra lib as a model. Reproduce the duplicate ambient-types behavior and verify that IntelliSense remains correct while reference lookup still works.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- frontend, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100