Add Custom Completition to javascript function node

Is there a way to add custom code completition to the javascript function. Espacially I want to define some "global" objects, constants and/or functions which I want to use in almost every node, without knowning all names.

lets say i want to define some mqtt topic names like this

let global.context.lights.kitchen = "actor/light/kitchen";
...

and in some script node i need the code completition for

global.context.<ctrl+space>
suggest :
global.context.lights.<ctrl+space>
suggest:
global.context.lights.kitchen

and so on...

Of course I could remember the variables or copy them elsewhere and paste to my nodes, but it would be very helpful, if i could configure nodered, that the function node would suggest me this variable with the code-completition.

No, there is no way to add custom completions to the Function node.

Perhaps if/when the Monaco editor is made available (at least NR v2, perhaps later?) as an option it might be possible?

If we expose a means yes, possible. Would need some thought along the effort Vs benefit.

1 thing that might be worth exploring is items added to global function context get added to Monacos completion. That would be a possible solution.

Something to keep in mind for if/when Monaco lands.

1 Like

You can add custom completions to ACE. That isn't the issue.

The question was whether you can add custom completions to the Function node - and you cannot do that today regardless of what editor component is used.

Adding auto complete to the TypedInput for flow/global types is on the to-do list. Not immediately clear how that could be extended to the Function node given the completions have to be dynamically resolved.

One of the nice(r) thing about Monaco is it understands JSdoc out of the box, so future features like this are not beyond the realms of possibility. for example, permitting a user to write to a .ts or .js file containing their desired type defs (demoed here by simply entering the JSDoc directly in the Monaco editor)...

NOTE: this demo is running in node red ^

2 Likes

Hi,
thanks for that information. I've also looked into the discussion about the integration of the monaco editor. It looks very promising and it could definitely be very helpful to me.
I think the demo in node red is a self-compiled-version?
Hope it will be included ...

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.