mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-13 08:44:12 +03:00
Use child_process.spawn from Project.scan
This commit is contained in:
parent
eddfb8a1bb
commit
c22d14c5b0
@ -1,6 +1,7 @@
|
||||
Project = require 'project'
|
||||
fs = require 'fs'
|
||||
_ = require 'underscore'
|
||||
BufferedProcess = require 'buffered-process'
|
||||
|
||||
describe "Project", ->
|
||||
beforeEach ->
|
||||
@ -239,12 +240,12 @@ describe "Project", ->
|
||||
expect(fs.base(paths[4])).toBe "utfa\u0306.md"
|
||||
|
||||
it "handles breaks in the search subprocess's output following the filename", ->
|
||||
spyOn $native, 'exec'
|
||||
spyOn(BufferedProcess.prototype, 'bufferStream')
|
||||
|
||||
iterator = jasmine.createSpy('iterator')
|
||||
project.scan /a+/, iterator
|
||||
|
||||
stdout = $native.exec.argsForCall[0][1].stdout
|
||||
stdout = BufferedProcess.prototype.bufferStream.argsForCall[0][1]
|
||||
stdout ":#{require.resolve('fixtures/dir/a')}\n"
|
||||
stdout "1;0 3:aaa bbb\n2;3 2:cc aa cc\n"
|
||||
|
||||
|
@ -6,7 +6,7 @@ Buffer = require 'buffer'
|
||||
EditSession = require 'edit-session'
|
||||
EventEmitter = require 'event-emitter'
|
||||
Directory = require 'directory'
|
||||
ChildProcess = require 'child-process'
|
||||
BufferedProcess = require 'buffered-process'
|
||||
|
||||
module.exports =
|
||||
class Project
|
||||
@ -159,9 +159,7 @@ class Project
|
||||
_.remove(@buffers, buffer)
|
||||
|
||||
scan: (regex, iterator) ->
|
||||
command = "#{require.resolve('ag')} --ackmate '#{regex.source}' '#{@getPath()}'"
|
||||
bufferedData = ""
|
||||
|
||||
state = 'readingPath'
|
||||
path = null
|
||||
|
||||
@ -193,11 +191,22 @@ class Project
|
||||
match = lineText.substr(column, length)
|
||||
iterator({path, range, match})
|
||||
|
||||
ChildProcess.exec command , bufferLines: true, stdout: (data) ->
|
||||
deferred = $.Deferred()
|
||||
exit = (code) ->
|
||||
if code is -1
|
||||
deferred.reject({command, code})
|
||||
else
|
||||
deferred.resolve()
|
||||
stdout = (data) ->
|
||||
lines = data.split('\n')
|
||||
lines.pop() # the last segment is a spurious '' because data always ends in \n due to bufferLines: true
|
||||
for line in lines
|
||||
readPath(line) if state is 'readingPath'
|
||||
readLine(line) if state is 'readingLines'
|
||||
|
||||
command = require.resolve('ag')
|
||||
args = ['--ackmate', regex.source, @getPath()]
|
||||
new BufferedProcess({command, args, stdout, exit})
|
||||
deferred
|
||||
|
||||
_.extend Project.prototype, EventEmitter
|
||||
|
@ -2,8 +2,8 @@ ChildProcess = nodeRequire 'child_process'
|
||||
|
||||
module.exports =
|
||||
class BufferedProcess
|
||||
constructor: (options={}) ->
|
||||
process = ChildProcess.spawn(options.command, options.args)
|
||||
constructor: ({command, args, options, stdout, stderr, exit}={}) ->
|
||||
process = ChildProcess.spawn(command, args, options)
|
||||
|
||||
stdoutClosed = true
|
||||
stderrClosed = true
|
||||
@ -11,21 +11,21 @@ class BufferedProcess
|
||||
exitCode = 0
|
||||
triggerExitCallback = ->
|
||||
if stdoutClosed and stderrClosed and processExited
|
||||
options.exit?(exitCode)
|
||||
exit?(exitCode)
|
||||
|
||||
if options.stdout
|
||||
if stdout
|
||||
stdoutClosed = false
|
||||
@bufferStream process.stdout, options.stdout, ->
|
||||
@bufferStream process.stdout, stdout, ->
|
||||
stdoutClosed = true
|
||||
triggerExitCallback()
|
||||
|
||||
if options.stderr
|
||||
if stderr
|
||||
stderrClosed = false
|
||||
@bufferStream process.stderr, options.stderr, ->
|
||||
@bufferStream process.stderr, stderr, ->
|
||||
stderrClosed = true
|
||||
triggerExitCallback()
|
||||
|
||||
if options.exit
|
||||
if exit
|
||||
processExited = false
|
||||
process.on 'exit', (code) ->
|
||||
exitCode = code
|
||||
|
Loading…
Reference in New Issue
Block a user