src/JSUtils/ScopeManager.js
function doEditorChange(session, document, previousDocument) {
            var file        = document.file,
                path        = file.fullPath,
                dir         = file.parentPath,
                pr;

            var addFilesDeferred = $.Deferred();

            documentChanges = null;
            addFilesPromise = addFilesDeferred.promise();
            pr = ProjectManager.getProjectRoot() ? ProjectManager.getProjectRoot().fullPath : null;

            // avoid re-initializing tern if possible.
            if (canSkipTernInitialization(path)) {

                // update the previous document in tern to prevent stale files.
                if (isDocumentDirty && previousDocument) {
                    var updateFilePromise = updateTernFile(previousDocument);
                    updateFilePromise.done(function () {
                        primePump(path, document.isUntitled());
                        addFilesDeferred.resolveWith(null, [_ternNodeDomain]);
                    });
                } else {
                    addFilesDeferred.resolveWith(null, [_ternNodeDomain]);
                }

                isDocumentDirty = false;
                return;
            }
            
            if (previousDocument && previousDocument.isDirty) {
                updateTernFile(previousDocument);
            }
    
            isDocumentDirty = false;
            resolvedFiles = {};
            projectRoot = pr;

            ensurePreferences();
            deferredPreferences.done(function () {
                if (file instanceof InMemoryFile) {
                    initTernServer(pr, []);
                    var hintsPromise = primePump(path, true);
                    hintsPromise.done(function () {
                        addFilesDeferred.resolveWith(null, [_ternNodeDomain]);
                    });
                    return;
                }

                FileSystem.resolve(dir, function (err, directory) {
                    if (err) {
                        console.error("Error resolving", dir);
                        addFilesDeferred.resolveWith(null);
                        return;
                    }

                    directory.getContents(function (err, contents) {
                        if (err) {
                            console.error("Error getting contents for", directory);
                            addFilesDeferred.resolveWith(null);
                            return;
                        }

                        var files = contents
                            .filter(function (entry) {
                                return entry.isFile && !isFileExcluded(entry);
                            })
                            .map(function (entry) {
                                return entry.fullPath;
                            });

                        initTernServer(dir, files);

                        var hintsPromise = primePump(path, false);
                        hintsPromise.done(function () {
                            if (!usingModules()) {
                                // Read the subdirectories of the new file's directory.
                                // Read them first in case there are too many files to
                                // read in the project.
                                addAllFilesAndSubdirectories(dir, function () {
                                    // If the file is in the project root, then read
                                    // all the files under the project root.
                                    var currentDir = (dir + "/");
                                    if (projectRoot && currentDir !== projectRoot &&
                                            currentDir.indexOf(projectRoot) === 0) {
                                        addAllFilesAndSubdirectories(projectRoot, function () {
                                            // prime the pump again but this time don't wait
                                            // for completion.
                                            primePump(path, false);
                                            addFilesDeferred.resolveWith(null, [_ternNodeDomain]);
                                        });
                                    } else {
                                        addFilesDeferred.resolveWith(null, [_ternNodeDomain]);
                                    }
                                });
                            } else {
                                addFilesDeferred.resolveWith(null, [_ternNodeDomain]);
                            }
                        });
                    });
                });
            });
        }
function doEditorChange(session, document, previousDocument) {
            var file        = document.file,
                path        = file.fullPath,
                dir         = file.parentPath,
                pr;

            var addFilesDeferred = $.Deferred();

            documentChanges = null;
            addFilesPromise = addFilesDeferred.promise();
            pr = ProjectManager.getProjectRoot() ? ProjectManager.getProjectRoot().fullPath : null;

            // avoid re-initializing tern if possible.
            if (canSkipTernInitialization(path)) {

                // update the previous document in tern to prevent stale files.
                if (isDocumentDirty && previousDocument) {
                    var updateFilePromise = updateTernFile(previousDocument);
                    updateFilePromise.done(function () {
                        primePump(path, document.isUntitled());
                        addFilesDeferred.resolveWith(null, [_ternNodeDomain]);
                    });
                } else {
                    addFilesDeferred.resolveWith(null, [_ternNodeDomain]);
                }

                isDocumentDirty = false;
                return;
            }
            
            if (previousDocument && previousDocument.isDirty) {
                updateTernFile(previousDocument);
            }
    
            isDocumentDirty = false;
            resolvedFiles = {};
            projectRoot = pr;

            ensurePreferences();
            deferredPreferences.done(function () {
                if (file instanceof InMemoryFile) {
                    initTernServer(pr, []);
                    var hintsPromise = primePump(path, true);
                    hintsPromise.done(function () {
                        addFilesDeferred.resolveWith(null, [_ternNodeDomain]);
                    });
                    return;
                }

                FileSystem.resolve(dir, function (err, directory) {
                    if (err) {
                        console.error("Error resolving", dir);
                        addFilesDeferred.resolveWith(null);
                        return;
                    }

                    directory.getContents(function (err, contents) {
                        if (err) {
                            console.error("Error getting contents for", directory);
                            addFilesDeferred.resolveWith(null);
                            return;
                        }

                        var files = contents
                            .filter(function (entry) {
                                return entry.isFile && !isFileExcluded(entry);
                            })
                            .map(function (entry) {
                                return entry.fullPath;
                            });

                        initTernServer(dir, files);

                        var hintsPromise = primePump(path, false);
                        hintsPromise.done(function () {
                            if (!usingModules()) {
                                // Read the subdirectories of the new file's directory.
                                // Read them first in case there are too many files to
                                // read in the project.
                                addAllFilesAndSubdirectories(dir, function () {
                                    // If the file is in the project root, then read
                                    // all the files under the project root.
                                    var currentDir = (dir + "/");
                                    if (projectRoot && currentDir !== projectRoot &&
                                            currentDir.indexOf(projectRoot) === 0) {
                                        addAllFilesAndSubdirectories(projectRoot, function () {
                                            // prime the pump again but this time don't wait
                                            // for completion.
                                            primePump(path, false);
                                            addFilesDeferred.resolveWith(null, [_ternNodeDomain]);
                                        });
                                    } else {
                                        addFilesDeferred.resolveWith(null, [_ternNodeDomain]);
                                    }
                                });
                            } else {
                                addFilesDeferred.resolveWith(null, [_ternNodeDomain]);
                            }
                        });
                    });
                });
            });
        }
function doEditorChange ( session , document , previousDocument ) { var file = document . file , path = file . fullPath , dir = file . parentPath , pr ; var addFilesDeferred = $ . Deferred ( ) ; documentChanges = null ; addFilesPromise = addFilesDeferred . promise ( ) ; pr = ProjectManager . getProjectRoot ( ) ? ProjectManager . getProjectRoot ( ) . fullPath : null ; // avoid re-initializing tern if possible. if ( canSkipTernInitialization ( path ) ) { // update the previous document in tern to prevent stale files. if ( isDocumentDirty && previousDocument ) { var updateFilePromise = updateTernFile ( previousDocument ) ; updateFilePromise . done ( function ( ) { primePump ( path , document . isUntitled ( ) ) ; addFilesDeferred . resolveWith ( null , [ _ternNodeDomain ] ) ; } ) ; } else { addFilesDeferred . resolveWith ( null , [ _ternNodeDomain ] ) ; } isDocumentDirty = false ; return ; } if ( previousDocument && previousDocument . isDirty ) { updateTernFile ( previousDocument ) ; } isDocumentDirty = false ; resolvedFiles = { } ; projectRoot = pr ; ensurePreferences ( ) ; deferredPreferences . done ( function ( ) { if ( file instanceof InMemoryFile ) { initTernServer ( pr , [ ] ) ; var hintsPromise = primePump ( path , true ) ; hintsPromise . done ( function ( ) { addFilesDeferred . resolveWith ( null , [ _ternNodeDomain ] ) ; } ) ; return ; } FileSystem . resolve ( dir , function ( err , directory ) { if ( err ) { console . error ( "Error resolving" , dir ) ; addFilesDeferred . resolveWith ( null ) ; return ; } directory . getContents ( function ( err , contents ) { if ( err ) { console . error ( "Error getting contents for" , directory ) ; addFilesDeferred . resolveWith ( null ) ; return ; } var files = contents . filter ( function ( entry ) { return entry . isFile && ! isFileExcluded ( entry ) ; } ) . map ( function ( entry ) { return entry . fullPath ; } ) ; initTernServer ( dir , files ) ; var hintsPromise = primePump ( path , false ) ; hintsPromise . done ( function ( ) { if ( ! usingModules ( ) ) { // Read the subdirectories of the new file's directory. // Read them first in case there are too many files to // read in the project. addAllFilesAndSubdirectories ( dir , function ( ) { // If the file is in the project root, then read // all the files under the project root. var currentDir = ( dir + "/" ) ; if ( projectRoot && currentDir !== projectRoot && currentDir . indexOf ( projectRoot ) === 0 ) { addAllFilesAndSubdirectories ( projectRoot , function ( ) { // prime the pump again but this time don't wait // for completion. primePump ( path , false ) ; addFilesDeferred . resolveWith ( null , [ _ternNodeDomain ] ) ; } ) ; } else { addFilesDeferred . resolveWith ( null , [ _ternNodeDomain ] ) ; } } ) ; } else { addFilesDeferred . resolveWith ( null , [ _ternNodeDomain ] ) ; } } ) ; } ) ; } ) ; } ) ; }
Do the work to initialize a code hinting session.

@param {Session} session - the active hinting session (TODO: currently unused)
@param {!Document} document - the document the editor has changed to
@param {?Document} previousDocument - the document the editor has changed from
Do the work to initialize a code hinting session .