monaco-editor
monaco-editor copied to clipboard
[Bug] typescript class export is not shown in suggestion
Reproducible in vscode.dev or in VS Code Desktop?
- [X] 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
let m1=monaco.editor.createModel(
`export class Purple {\n\tpublic static color=55;\n}\n`
,'typescript'
,monaco.Uri.parse(`file:///f1.ts`)
);
let m2=monaco.editor.createModel(
`export class Blue {\n\tpublic static shade=Purple.color;\n}\n`
,'typescript'
,monaco.Uri.parse(`file:///f2.ts`)
);
monaco.editor.create(document.getElementById('container'), {
model:m2,
language: 'typescript'
});
Actual Behavior
Mouseover Purple.color will give the correct path to import './f1' file, which is good.
Now remove everything after 'shade=' and start typing the word 'Purple', it is not listed as part of the suggestions.
Expected Behavior
Word 'Purple' should also be part of the typeahead recommendations, as it is exported by another model.
Additional Context
I would like to know if the exported class name from other models should be part of suggestions. if so, how can i get it working. I tried in my local with various typescript/javascript options like setEagerModelSync=true, allowJs=true, etc. but no success.
I tried this and it works good. I guess you may need to add import { Purple } from 'f1';
Thanks, But the real issue is Purple is not shown in suggestions, if you remove '=Purple.color' and start re-typing Purple, the suggestions will be displayed without word 'Purple'.
Note: please remove import purple before testing suggestions.
Yeah, I think maybe in this case, only createModel
is not enough, you have to import Purple to get the suggestion. You can try to use monaco.languages.typescript.typescriptDefaults.addExtraLib(source, uri)
to get the suggestion
Thanks again, But still i am not able to get the suggestions for words exported in another typescript file.
let s1 = export class Purple {\n\tpublic static color=55;\n}\n
;
let s2 = export class Blue {\n\tpublic static shade=Purple.color;\n}\n
;
let p1 = file:///f1.ts
;
let p2 = file:///f2.ts
;
let m1=monaco.editor.createModel(s1,'typescript',monaco.Uri.parse(p1)); let m2=monaco.editor.createModel(s2,'typescript',monaco.Uri.parse(p2));
monaco.languages.typescript.typescriptDefaults.addExtraLib(s1, p1); monaco.languages.typescript.typescriptDefaults.addExtraLib(s2, p2);
monaco.languages.typescript.typescriptDefaults.setEagerModelSync(true);
monaco.editor.create(document.getElementById('container'), { model:m2, language: 'typescript' });
All right man, this is all I can think about lol.
In your last example try this for setting it as an external lib
let s1 = "declare global { \nexport class Purple {\n\tpublic static color=55;\n}\n}
Thanks much, this works as expected. But do we need to take declare approach, why not export is work directly. The file that needs the export items as part of suggestions, also need to be in declare global scope, if not the suggestion will not include them. Any ideas/suggestions.