how to support global object? mode? autocomplete?

I am going to be using CM in a custom JS scripting application which uses v8 to expose a “custom” global object specific to my application. Let’s call it myApp.

So myApp is a global in what are otherwise normal javascript files. I am going to use CodeMirror to create a script writing interface inside my overall app and had a couple of questions (more like clarifications) after reading some CM docs and examples.

  1. Do I need/want to have a mode for my global object? I am thinking not as it’s just Javascript. But if I wanted my myApp methods/properties to be identified/styled differently than a normal Javascript object, I might want to create a custom mode and multiplex with JS?

  2. Is there an example of CM autocomplete being driven off of TypeScript definition files? One of my peers wants to allow the scripts to be written in TypeScript and then transpile them to javascript, which is a good idea but we would love to be able to make use of the myApp.d.ts information for code completion in the cm-based editor. Any thoughts/examples here would be great.

Thanks

so far no luck getting info on this.

I was looking at an approach where I would add the keywords for my global object in a registerHelper() function but I am not sure that will work properly since the mode is still Javascript. The docs say something about iterating through helpers using getHelpers() so maybe it would work?

Can someone let me know if they thought this approach is viable?

var myGlobal = {
     foo: "foo",
     bar: function(baz) {
         var loc = baz;}
};

and then in an addon:

CodeMirror.registerHelper("hints", "myGlobal", 
      ["myGlobal", "myGlobal.foo", "myGlobal.bar("]);

And I would just add that as a addon and load with show-hint.js? If so, would it still work if I also loaded javascript-hint.js?

I am unsure of the use of “hints” as the type parameter in registerHelper. Is this supposed to be something more specific to myGlobal?

The JavaScript mode doesn’t highlight library variables, so there’s no need to configure the mode for your globals.

If you are using the javascript-hint addon, set a custom globalScope option (hintOptions: {globalScope: {....}} in your CodeMirror options), passing in an object that mimics your global scope (i.e. its properties correspond to your global variables).