microsoft / monaco-editor

A browser based code editor
https://microsoft.github.io/monaco-editor/
MIT License
40.2k stars 3.58k forks source link

[Bug] setExtraLibs does only work with relative paths #4166

Open jogibear9988 opened 1 year ago

jogibear9988 commented 1 year ago

Reproducible in vscode.dev or in VS Code Desktop?

Reproducible in the monaco editor playground?

Monaco Editor Playground Link

https://microsoft.github.io/monaco-editor/playground.html?source=v0.40.0-dev.20230703#XQAAAAIUAgAAAAAAAABBqQkHQ5NjdMjwa-jY7SIQ9S7DNlzs5W-mwj0fe1ZCDRFc9ws9XQE0SJE1jc2VKxhaLFIw9vEWSxW3yscw0eXaCAEiAKctgAboa7BDW-dD5UNujAS0b7QGpwJN09LIuNc-WgzFneLy7Iihhgtyajb-EbGjjyZzBHzOnGo_GbSrt3XR8_ZQ9Vxlw__KjuG51nRj7Q6gM5njKhM7hsDbeU_9vgXyoAAGToGYP0TTMRpo2a_UwFCzQP_E5Cwoqz4ecp52khFmSPRpjC5wrzfNh-K8uIrQzMP6cj0kSV-iEXC_jbYpilgg6kD8qTSlEyVwtCTGDL4MCVGpkC96Coiyfjo8WooJmsvFdzhAfffOYmpre8SjXnUnvR9frqdmDmIGwytNNl9QUEvArrNT624u5czPG_eSq0WvRtXLzDlxMgeq2YWD3VnJW5Ur1Bde5Z4qjKSLzjFX8xGKWWWHqfKP__lsk2s

Monaco Editor Playground Code

const value = `import { Class1 } from '/aa.js';
import { Class2 } from 'myLib';
new Class1;
new Class2;`;

monaco.languages.typescript.typescriptDefaults.setExtraLibs(
[
{content:'export class Class1 {}', filePath:'/aa.js'},
{content:'export class Class2 {}', filePath:'myLib'}
]);

// Hover on each property to see its docs!
const myEditor = monaco.editor.create(document.getElementById("container"), {
    value,
    language: "typescript",
    automaticLayout: true,
});

Reproduction Steps

look at the playground code

Actual (Problematic) Behavior

As importmaps are now a thing, not only relative path could be used, but also some with a package name, wich is then resolved via importmap. But the editor only works with imports with relative paths.

Expected Behavior

the sample provided should work and not show an error in the playground.

Additional Context

No response

jogibear9988 commented 9 months ago

It works if you change the defintion from

 {content:'export class Class2 {}', filePath:'myLib'}

to

 {content:'export class Class2 {}', filePath:'inmemory://model/myLib.d.ts'}

but I think, this is a dirty hack, wich should be removed, or applied by monaco editor itself (so every non relative path needs adjustment)