mirror of
https://github.com/atom/atom.git
synced 2026-02-11 07:05:11 -05:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user