mirror of
https://github.com/atom/atom.git
synced 2026-02-10 22:55:09 -05:00
Project.scan invokes the callback with matches
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
fs = require 'fs'
|
||||
_ = require 'underscore'
|
||||
$ = require 'jquery'
|
||||
|
||||
Range = require 'range'
|
||||
Buffer = require 'buffer'
|
||||
EditSession = require 'edit-session'
|
||||
EventEmitter = require 'event-emitter'
|
||||
@@ -127,16 +127,18 @@ class Project
|
||||
bufferWithPath: (path) ->
|
||||
return editSession.buffer for editSession in @editSessions when editSession.buffer.getPath() == path
|
||||
|
||||
scan: ({regex}, callback) ->
|
||||
scan: (regex, iterator) ->
|
||||
regex = new RegExp(regex.source, 'g')
|
||||
command = "grep --null --perl-regexp --with-filename --line-number --recursive --regexp=#{regex.source} #{@getPath()}"
|
||||
ChildProcess.exec command, bufferLines: false, stdout: (data) ->
|
||||
for grepLine in data.split('\n') when grepLine.length
|
||||
nullCharIndex = grepLine.indexOf('\0')
|
||||
colonIndex = grepLine.indexOf(':')
|
||||
path = grepLine.substring(0, nullCharIndex)
|
||||
row = parseInt(grepLine.substring(nullCharIndex + 1, colonIndex)) - 1
|
||||
line = grepLine.substring(colonIndex + 1)
|
||||
|
||||
console.log path, row, line
|
||||
ChildProcess.exec command, bufferLines: true, stdout: (data) ->
|
||||
for grepLine in data.split('\n') when grepLine.length
|
||||
nullCharIndex = grepLine.indexOf('\0')
|
||||
colonIndex = grepLine.indexOf(':')
|
||||
path = grepLine.substring(0, nullCharIndex)
|
||||
row = parseInt(grepLine.substring(nullCharIndex + 1, colonIndex)) - 1
|
||||
line = grepLine.substring(colonIndex + 1)
|
||||
while match = regex.exec(line)
|
||||
range = new Range([row, match.index], [row, match.index + match[0].length])
|
||||
iterator({path, match, range})
|
||||
|
||||
_.extend Project.prototype, EventEmitter
|
||||
|
||||
Reference in New Issue
Block a user