File tree Expand file tree Collapse file tree 3 files changed +83
-39
lines changed
Expand file tree Collapse file tree 3 files changed +83
-39
lines changed Original file line number Diff line number Diff line change 1+ var os = require ( "os" ) ;
2+ var path = require ( "path" ) ;
3+ var _ = require ( "lodash" ) ;
4+ var Q = require ( "q" ) ;
5+ var spawn = require ( 'child_process' ) . spawn ;
6+
7+ var search = function ( root , args ) {
8+ var d = Q . defer ( ) ;
9+ var results = { } ;
10+
11+ var proc = spawn ( 'ack' , [ '"' + args . query + '"' , '--nocolor' ] , {
12+ cwd : root ,
13+ env : process . env
14+ } ) ;
15+ proc . stdout . on ( 'data' , function ( data ) {
16+ data = data . toString ( ) ;
17+
18+ _ . each ( data . toString ( ) . split ( "\n" ) , function ( line ) {
19+ var parts = line . split ( ":" ) ;
20+ if ( parts . length < 3 ) return ;
21+
22+ results [ parts [ 0 ] ] = results [ parts [ 0 ] ] || [ ] ;
23+ results [ parts [ 0 ] ] . push ( {
24+ 'line' : parts [ 1 ] ,
25+ 'content' : parts [ 2 ]
26+ } ) ;
27+ } ) ;
28+ } ) ;
29+
30+ proc . on ( 'error' , function ( err ) {
31+ d . reject ( err )
32+ } ) ;
33+ proc . on ( 'exit' , function ( code ) {
34+ d . resolve ( results )
35+ } ) ;
36+
37+ return d . promise ;
38+ } ;
39+
40+ module . exports = search ;
Original file line number Diff line number Diff line change 1+ var _ = require ( 'lodash' ) ;
2+ var glob = require ( "glob" ) ;
3+ var Q = require ( 'q' ) ;
4+
5+ var search = function ( root , args ) {
6+ var d = Q . defer ( ) ;
7+
8+ args = _ . defaults ( { } , args || { } , {
9+ 'start' : 0 ,
10+ 'limit' : 30
11+ } ) ;
12+
13+ glob ( "**/*" + args . query + "*" , {
14+ 'cwd' : root ,
15+ 'mark' : true
16+ } , function ( err , files ) {
17+ if ( err ) {
18+ d . reject ( err ) ;
19+ } else {
20+ var results = _ . chain ( files )
21+ . filter ( function ( path ) {
22+ return ! ( ! path . length || path [ path . length - 1 ] == "/" ) ;
23+ } )
24+ . map ( function ( path ) {
25+ return "/" + path ;
26+ } )
27+ . value ( ) ;
28+
29+ d . resolve ( {
30+ 'files' : results . slice ( args . start , args . start + args . limit ) ,
31+ 'n' : _ . size ( results )
32+ } ) ;
33+ }
34+ } ) ;
35+
36+ return d . promise ;
37+ } ;
38+
39+ module . exports = search ;
Original file line number Diff line number Diff line change 1- // Requires
21var _ = require ( 'lodash' ) ;
3- var glob = require ( "glob" ) ;
4- var Q = require ( 'q' ) ;
52
3+ var filesSearch = require ( "./files" ) ;
4+ var codeSearch = require ( "./code" ) ;
65
76function setup ( options , imports , register ) {
87 // Import
98 var vfs = imports . vfs ;
109 var workspace = imports . workspace ;
1110
12- // Construct
13- var filesSearch = function ( args ) {
14- var d = Q . defer ( ) ;
15-
16- args = _ . defaults ( { } , args || { } , {
17- 'start' : 0 ,
18- 'limit' : 30
19- } ) ;
20-
21- glob ( "**/*" + args . query + "*" , {
22- 'cwd' : workspace . root ,
23- 'mark' : true
24- } , function ( err , files ) {
25- if ( err ) {
26- d . reject ( err ) ;
27- } else {
28- var results = _ . chain ( files )
29- . filter ( function ( path ) {
30- return ! ( ! path . length || path [ path . length - 1 ] == "/" ) ;
31- } )
32- . map ( function ( path ) {
33- return "/" + path ;
34- } )
35- . value ( ) ;
36-
37- d . resolve ( {
38- 'files' : results . slice ( args . start , args . start + args . limit ) ,
39- 'n' : _ . size ( results )
40- } ) ;
41- }
42- } ) ;
43-
44- return d . promise ;
45- } ;
46-
4711 // Register
4812 register ( null , {
4913 "search" : {
50- files : filesSearch
14+ files : _ . partial ( filesSearch , workspace . root ) ,
15+ code : _ . partial ( codeSearch , workspace . root )
5116 }
5217 } ) ;
5318}
You can’t perform that action at this time.
0 commit comments