WIP: Start on Project.prototype.scan

Right now it calls out to grep and parses the output, but doesn't do anything with it just yet.
This commit is contained in:
Nathan Sobo
2012-07-11 18:50:38 -06:00
parent db6692b2f6
commit 3854f73c84
5 changed files with 29 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ Buffer = require 'buffer'
EditSession = require 'edit-session'
EventEmitter = require 'event-emitter'
Directory = require 'directory'
ChildProcess = require 'child-process'
module.exports =
class Project
@@ -126,4 +127,16 @@ class Project
bufferWithPath: (path) ->
return editSession.buffer for editSession in @editSessions when editSession.buffer.getPath() == path
scan: ({regex}, callback) ->
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
_.extend Project.prototype, EventEmitter

View File

@@ -14,6 +14,7 @@ class ChildProccess
options.stderr = @bufferLines(options.stderr) if options.stderr
$native.exec command, options, (exitStatus, stdout, stderr) ->
console.log exitStatus
if exitStatus != 0
error = new Error("Exec failed (#{exitStatus}) command '#{command}'")
error.exitStatus = exitStatus