I am trying to provide intellisense / code completion into a javascript editor using the Monaco editor. The code needs to be valid javascript, not typescript.
Given some user entered script like this:
function onMyEvent(event)
{
event.someProperty
}
I want to provide code completion on the event parameter, which is a typescript class I have the t.ds of, and can infer at runtime.
Ideally, I would just like to tell Monaco that the type of event
is SomeEventClass
, and let it do the rest.
Even if that meant adding type hints to the script. But I can't see how to do that.
I tried using JSDoc syntax and various combinations in the user script, but it looks like thats blocked FTB see:
https://github.com/Microsoft/monaco-editor/issues/203
and
Adding JavaScript type hints for VSCode/Monaco Intellisence
I also tried injecting a dynamic d.ts, as per https://microsoft.github.io/monaco-editor/playground.html#extending-language-services-configure-javascript-defaults
But declaring the function didn't seem to mean anything to the editor. Declaring a new class definitely worked, I just can't work out how to tell Monaco that event
in that function is a specific type.
I can see the registerCompletionItemProvider API, but that doesn't give you any context of where the item was declared etc, and also doesn't let me automatically use the d.ts file that I want to.