Пример #1
0
 return session.getText(path).then(function(text) {
     try {
         json = JSON.parse(text);
     } catch (e) {
         return console.error("Could not parse package.json");
     }
     return project.listFiles();
 }).then(function(files) {
Пример #2
0
            session.goto("zed::search", function() {
                function append(text) {
                    session.append("zed::search", text, function() {});
                }

                var results = 0;

                project.listFiles(function(err, fileList) {
                    fileList = fileList.filter(function(filename) {
                        var parts = filename.split('.');
                        var ext = parts[parts.length - 1];
                        return filterExtensions.indexOf(ext) === -1;
                    });

                    session.setText("zed::search", "Searching " + fileList.length + " files for '" + phrase + "'...\nPut your cursor on the result press Enter to jump.\n", function() {});
                    async.eachLimit(fileList, 10, function(path, next) {
                        if (results >= MAX_RESULTS) {
                            return next();
                        }

                        if (path === "/tags") {
                            return next();
                        }

                        project.readFile(path, function(err, text) {
                            if (err) {
                                console.error(path, err);
                                return next();
                            }
                            if (!stringIsText(text)) {
                                return next();
                            }
                            var matchIdx = 0;
                            while ((matchIdx = text.indexOf(phrase, matchIdx)) !== -1) {
                                append("\n" + path + ":" + indexToLine(text, matchIdx) + "\n\t" + getLine(text, matchIdx) + "\n");
                                matchIdx++;
                                results++;
                                if (results >= MAX_RESULTS) {
                                    break;
                                }
                            }
                            next();
                        });
                    }, function() {
                        if (results === 0) {
                            append("\nNo results found.");
                        } else {
                            append("\nFound " + results + " results.");
                        }
                        callback();
                    });
                });
            });