Project::scan uses a task to do its work

This commit is contained in:
probablycorey
2013-09-24 13:21:12 -07:00
committed by Ben Ogle
parent e26d7a0320
commit cd554a4f7b
2 changed files with 22 additions and 10 deletions

View File

@@ -1,7 +1,6 @@
fsUtils = require './fs-utils'
path = require 'path'
url = require 'url'
{PathSearcher, PathScanner, search} = require 'scandal'
_ = require './underscore-extensions'
$ = require './jquery-extensions'
@@ -11,6 +10,7 @@ TextBuffer = require './text-buffer'
EditSession = require './edit-session'
EventEmitter = require './event-emitter'
Directory = require './directory'
Task = require './task'
Git = require './git'
# Public: Represents a project that's opened in Atom.
@@ -288,23 +288,20 @@ class Project
options = {}
deferred = $.Deferred()
searchOptions =
ignoreCase: regex.ignoreCase
inclusions: options.paths
includeHidden: true
excludeVcsIgnores: config.get('core.excludeVcsIgnoredPaths')
# args.unshift('--ignore', ignoredNames.join(',')) if ignoredNames.length > 0
searcher = new PathSearcher()
scanner = new PathScanner(@getPath(), searchOptions)
searcher.on 'results-found', (result) ->
iterator(result)
console.time("search")
search regex, scanner, searcher, ->
console.timeEnd("search")
task = Task.once require.resolve('./scan-handler'), @getPath(), regex.source, searchOptions, ->
deferred.resolve()
task.on 'scan:result-found', (result) =>
iterator(result)
deferred
# Private:

15
src/scan-handler.coffee Normal file
View File

@@ -0,0 +1,15 @@
{PathSearcher, PathScanner, search} = require 'scandal'
module.exports = (rootPath, regexSource, options) ->
callback = @async()
searcher = new PathSearcher()
scanner = new PathScanner(rootPath, rootPath)
searcher.on 'results-found', (result) ->
emit('scan:result-found', result)
flags = "g"
flags += "i" if options.ignoreCase
regex = new RegExp(regexSource, flags)
search regex, scanner, searcher, callback