[Feature Request] Support intellisense for AMD modules #3731
-
Context
DescriptionI want to support intellisense with in AMD modules (which are loaded using requirejs.). I created models for all the modules, but when I refer one of the module in another, I don't get any intellisense about the available properties/functions of the dependencies. For example, given: dep1.js: define("dep1", [], function () {
return { foo: { bar: 123, aaa: 456 } }
}); dep2.js: define(['dep1'], function (dep1) {
console.log(dep1.foo.bar); // <----- I want to get auto completions from `dep1`
}); What would be the best way to achieve this? Is there a way I can specify the prototype of a variable word? I looked at 'Configure JavaScript defaults' playground example too. I tried asking this question in StackOverFlow couple of weeks ago, but no luck. Thanks. Monaco Editor Playground LinkMonaco Editor Playground Codemonaco.languages.typescript.javascriptDefaults.setCompilerOptions({
target: monaco.languages.typescript.ScriptTarget.ES2015,
allowNonTsExtensions: true,
moduleResolution: monaco.languages.typescript.ModuleResolutionKind.Classic,
module: monaco.languages.typescript.ModuleKind.AMD,
noEmit: true,
esModuleInterop: true,
strict: true,
allowJs: true,
isolatedModules: true,
});
monaco.languages.typescript.javascriptDefaults.setEagerModelSync(true);
monaco.editor.createModel(
'define("dep1", [], function () { return { foo: { bar: 123, aaa: 456 } } })',
'javascript',
monaco.Uri.parse(`inmemory:///mylib/dep1.js`)
);
const instance = monaco.editor.create(document.getElementById("container"), {
language: 'javascript',
value: `define(['dep1'], function (dep1) {
console.log(dep1.foo.bar);
});
`
}); |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
I don't think is possible without significant effort. Maybe you can achieve it by generating some d.ts files in the background. |
Beta Was this translation helpful? Give feedback.
-
We closed this issue because we don't plan to address it in the foreseeable future. If you disagree and feel that this issue is crucial: we are happy to listen and to reconsider. If you wonder what we are up to, please see our roadmap and issue reporting guidelines. Thanks for your understanding, and happy coding! |
Beta Was this translation helpful? Give feedback.
-
I see, thanks for the update. Is there a way to specify the I have a JavaScript Class with jsdoc. Now whenever user types
Related SO questions: https://stackoverflow.com/questions/67505426/custom-javascript-code-completion-for-this-in-monaco-editor Can you please advice? Thanks |
Beta Was this translation helpful? Give feedback.
-
Never mind... I figured it out... using declaration files I achieved 90% of my requirement: getting proper completions in AMD module with For anyone else having same requirement: Monaco playground link Main thing to notice is how monaco.languages.typescript.javascriptDefaults.addExtraLib(
'declare function Factory (this: HTMLCanvasElement, n: Number) : void;', // <----- change the `this` type to whatever you want
'ts:this-lib.d.ts'
); Best thing is I don't have to fiddle with the current line/word based logic anymore (and no custom provider is needed), leaving all it to language worker which is best at it 👍 |
Beta Was this translation helpful? Give feedback.
Never mind... I figured it out... using declaration files I achieved 90% of my requirement: getting proper completions in AMD module with
this
context of chosen type.For anyone else having same requirement: Monaco playground link
Main thing to notice is how
this
is declared to be a specific type in the declaration file which is fed to monaco as a extra lib.Best thing is I don't have to fiddle with the current line/word based logic anymore (and no custom provider is needed…