monaco-editor icon indicating copy to clipboard operation
monaco-editor copied to clipboard

[Bug] typescript class export is not shown in suggestion

Open pondyrvenky opened this issue 2 years ago • 7 comments

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?

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.

pondyrvenky avatar Apr 06 '22 18:04 pondyrvenky

I tried this and it works good. I guess you may need to add import { Purple } from 'f1';

ricenoddle avatar Apr 07 '22 08:04 ricenoddle

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.

pondyrvenky avatar Apr 07 '22 16:04 pondyrvenky

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

ricenoddle avatar Apr 08 '22 01:04 ricenoddle

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' });

pondyrvenky avatar Apr 08 '22 01:04 pondyrvenky

All right man, this is all I can think about lol.

ricenoddle avatar Apr 08 '22 02:04 ricenoddle

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}

mpcaddy avatar Apr 08 '22 18:04 mpcaddy

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.

pondyrvenky avatar Apr 08 '22 18:04 pondyrvenky