Use bundled ack instead of grep

Our ack is slightly modified to use `'\0'` characters instead of `':'` in the --nogroup listing. This makes it easier to handle both `':'` characters and newlines in filenames, but we aren't really doing that yet.
This commit is contained in:
Nathan Sobo
2012-07-19 08:54:08 -06:00
parent 8534df28d5
commit f5e46e57fc
10 changed files with 2801 additions and 21 deletions

View File

@@ -138,20 +138,14 @@ class Project
scan: (regex, iterator) ->
regex = new RegExp(regex.source, 'g')
command = [
"find \"#{@getPath()}\" -type f -print0" # find all paths in the project's working directory
"grep --text --perl-regexp --invert-match --regexp=\"#{@ignorePathRegex()}\"" # accept only non-ignored paths, separated by \0 (find doesn't support pcre)
"perl -0pi -e 's/\\n\\z\//'" # delete grep's trailing newline because it screws up xargs
"xargs -0 grep --null --perl-regexp --with-filename --line-number --recursive --regexp=\"#{regex.source}\"" # run grep on each filtered file
].join(" | ")
ChildProcess.exec command, bufferLines: true, stdout: (data) ->
command = "#{require.resolve('ack')} --all-types --match \"#{regex.source}\" \"#{@getPath()}\""
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)
pathEndIndex = grepLine.indexOf('\0')
lineNumberEndIndex = grepLine.indexOf('\0', pathEndIndex + 1)
path = grepLine.substring(0, pathEndIndex)
row = parseInt(grepLine.substring(pathEndIndex + 1, lineNumberEndIndex)) - 1
line = grepLine.substring(lineNumberEndIndex + 1)
while match = regex.exec(line)
range = new Range([row, match.index], [row, match.index + match[0].length])
iterator({path, match, range})