src/JSUtils/ScopeManager.js
function initTernModule() {
            var moduleDeferred = $.Deferred();
            ternPromise = moduleDeferred.promise();
            
            function prepareTern() {  
                _ternNodeDomain.exec("setInterface", {
                    messageIds : MessageIds
                });

                _ternNodeDomain.exec("invokeTernCommand", {
                    type: MessageIds.SET_CONFIG,
                    config: config
                });
                moduleDeferred.resolveWith(null, [_ternNodeDomain]);
            }
            
            if (_ternNodeDomain) {
                _ternNodeDomain.exec("resetTernServer");
                moduleDeferred.resolveWith(null, [_ternNodeDomain]);
            } else {
                _ternNodeDomain     = new NodeDomain("TernNodeDomain", _domainPath);
                _ternNodeDomain.on("data", function (evt, data) {
                    if (config.debug) {
                        console.log("Message received", data.type);
                    }

                    var response = data,
                        type = response.type;

                    if (type === MessageIds.TERN_COMPLETIONS_MSG ||
                            type === MessageIds.TERN_CALLED_FUNC_TYPE_MSG) {
                        // handle any completions the tern server calculated
                        handleTernCompletions(response);
                    } else if (type === MessageIds.TERN_GET_FILE_MSG) {
                        // handle a request for the contents of a file
                        handleTernGetFile(response);
                    } else if (type === MessageIds.TERN_JUMPTODEF_MSG) {
                        handleJumptoDef(response);
                    } else if (type === MessageIds.TERN_SCOPEDATA_MSG) {
                        handleScopeData(response);
                    } else if (type === MessageIds.TERN_REFS) {
                        handleRename(response);
                    } else if (type === MessageIds.TERN_PRIME_PUMP_MSG) {
                        handlePrimePumpCompletion(response);
                    } else if (type === MessageIds.TERN_GET_GUESSES_MSG) {
                        handleGetGuesses(response);
                    } else if (type === MessageIds.TERN_UPDATE_FILE_MSG) {
                        handleUpdateFile(response);
                    } else if (type === MessageIds.TERN_INFERENCE_TIMEDOUT) {
                        handleTimedOut(response);
                    } else if (type === MessageIds.TERN_WORKER_READY) {
                        moduleDeferred.resolveWith(null, [_ternNodeDomain]);
                    } else if (type === "RE_INIT_TERN") {
                        // Ensure the request is because of a node restart
                        if (currentModule) {
                            prepareTern();
                            // Mark the module with resetForced, then creation of TernModule will 
                            // happen again as part of '_maybeReset' call
                            currentModule.resetForced = true;
                        }
                    } else {
                        console.log("Tern Module: " + (response.log || response));
                    }
                });
            
                _ternNodeDomain.promise().done(prepareTern);
            }
        }
function initTernModule() {
            var moduleDeferred = $.Deferred();
            ternPromise = moduleDeferred.promise();
            
            function prepareTern() {  
                _ternNodeDomain.exec("setInterface", {
                    messageIds : MessageIds
                });

                _ternNodeDomain.exec("invokeTernCommand", {
                    type: MessageIds.SET_CONFIG,
                    config: config
                });
                moduleDeferred.resolveWith(null, [_ternNodeDomain]);
            }
            
            if (_ternNodeDomain) {
                _ternNodeDomain.exec("resetTernServer");
                moduleDeferred.resolveWith(null, [_ternNodeDomain]);
            } else {
                _ternNodeDomain     = new NodeDomain("TernNodeDomain", _domainPath);
                _ternNodeDomain.on("data", function (evt, data) {
                    if (config.debug) {
                        console.log("Message received", data.type);
                    }

                    var response = data,
                        type = response.type;

                    if (type === MessageIds.TERN_COMPLETIONS_MSG ||
                            type === MessageIds.TERN_CALLED_FUNC_TYPE_MSG) {
                        // handle any completions the tern server calculated
                        handleTernCompletions(response);
                    } else if (type === MessageIds.TERN_GET_FILE_MSG) {
                        // handle a request for the contents of a file
                        handleTernGetFile(response);
                    } else if (type === MessageIds.TERN_JUMPTODEF_MSG) {
                        handleJumptoDef(response);
                    } else if (type === MessageIds.TERN_SCOPEDATA_MSG) {
                        handleScopeData(response);
                    } else if (type === MessageIds.TERN_REFS) {
                        handleRename(response);
                    } else if (type === MessageIds.TERN_PRIME_PUMP_MSG) {
                        handlePrimePumpCompletion(response);
                    } else if (type === MessageIds.TERN_GET_GUESSES_MSG) {
                        handleGetGuesses(response);
                    } else if (type === MessageIds.TERN_UPDATE_FILE_MSG) {
                        handleUpdateFile(response);
                    } else if (type === MessageIds.TERN_INFERENCE_TIMEDOUT) {
                        handleTimedOut(response);
                    } else if (type === MessageIds.TERN_WORKER_READY) {
                        moduleDeferred.resolveWith(null, [_ternNodeDomain]);
                    } else if (type === "RE_INIT_TERN") {
                        // Ensure the request is because of a node restart
                        if (currentModule) {
                            prepareTern();
                            // Mark the module with resetForced, then creation of TernModule will 
                            // happen again as part of '_maybeReset' call
                            currentModule.resetForced = true;
                        }
                    } else {
                        console.log("Tern Module: " + (response.log || response));
                    }
                });
            
                _ternNodeDomain.promise().done(prepareTern);
            }
        }
function initTernModule ( ) { var moduleDeferred = $ . Deferred ( ) ; ternPromise = moduleDeferred . promise ( ) ; function prepareTern ( ) { _ternNodeDomain . exec ( "setInterface" , { messageIds : MessageIds } ) ; _ternNodeDomain . exec ( "invokeTernCommand" , { type : MessageIds . SET_CONFIG , config : config } ) ; moduleDeferred . resolveWith ( null , [ _ternNodeDomain ] ) ; } if ( _ternNodeDomain ) { _ternNodeDomain . exec ( "resetTernServer" ) ; moduleDeferred . resolveWith ( null , [ _ternNodeDomain ] ) ; } else { _ternNodeDomain = new NodeDomain ( "TernNodeDomain" , _domainPath ) ; _ternNodeDomain . on ( "data" , function ( evt , data ) { if ( config . debug ) { console . log ( "Message received" , data . type ) ; } var response = data , type = response . type ; if ( type === MessageIds . TERN_COMPLETIONS_MSG || type === MessageIds . TERN_CALLED_FUNC_TYPE_MSG ) { // handle any completions the tern server calculated handleTernCompletions ( response ) ; } else if ( type === MessageIds . TERN_GET_FILE_MSG ) { // handle a request for the contents of a file handleTernGetFile ( response ) ; } else if ( type === MessageIds . TERN_JUMPTODEF_MSG ) { handleJumptoDef ( response ) ; } else if ( type === MessageIds . TERN_SCOPEDATA_MSG ) { handleScopeData ( response ) ; } else if ( type === MessageIds . TERN_REFS ) { handleRename ( response ) ; } else if ( type === MessageIds . TERN_PRIME_PUMP_MSG ) { handlePrimePumpCompletion ( response ) ; } else if ( type === MessageIds . TERN_GET_GUESSES_MSG ) { handleGetGuesses ( response ) ; } else if ( type === MessageIds . TERN_UPDATE_FILE_MSG ) { handleUpdateFile ( response ) ; } else if ( type === MessageIds . TERN_INFERENCE_TIMEDOUT ) { handleTimedOut ( response ) ; } else if ( type === MessageIds . TERN_WORKER_READY ) { moduleDeferred . resolveWith ( null , [ _ternNodeDomain ] ) ; } else if ( type === "RE_INIT_TERN" ) { // Ensure the request is because of a node restart if ( currentModule ) { prepareTern ( ) ; // Mark the module with resetForced, then creation of TernModule will  // happen again as part of '_maybeReset' call currentModule . resetForced = true ; } } else { console . log ( "Tern Module: " + ( response . log || response ) ) ; } } ) ; _ternNodeDomain . promise ( ) . done ( prepareTern ) ; } }
Init the Tern module that does all the code hinting work.
Init the Tern module that does all the code hinting work .