This repository has been archived by the owner on Jun 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 204
/
ui_search.ml
118 lines (108 loc) · 2.96 KB
/
ui_search.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
(*s: ui_search.ml *)
(*s: Facebook copyright *)
(* Yoann Padioleau
*
* Copyright (C) 2010-2012 Facebook
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation, with the
* special exception on linking described in file license.txt.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the file
* license.txt for more details.
*)
(*e: Facebook copyright *)
open Common
module G = Gui
module M = Model2
(*****************************************************************************)
(* Prelude *)
(*****************************************************************************)
(*
* todo:
* - integrate lfs at some point!
* - integrate pof at some point!
*)
(* ---------------------------------------------------------------------- *)
(* Search *)
(* ---------------------------------------------------------------------- *)
(*s: dialog_search_def *)
let dialog_search_def model =
let idx = (fun () ->
let model = Async.async_get model in
model.Model2.big_grep_idx
)
in
let entry =
Completion2.my_entry_completion_eff
~callback_selected:(fun _entry _str _file _e ->
true
)
~callback_changed:(fun _str ->
()
)
idx
in
let res =
G.dialog_ask_generic ~title:""
(fun vbox ->
vbox#pack (G.with_label "search:" entry#coerce);
)
(fun () ->
let text = entry#text in
pr2 text;
text
)
in
res +> Common.do_option (fun s ->
pr2 ("selected: " ^ s);
);
res
(*e: dialog_search_def *)
(*s: run_grep_query *)
let run_grep_query ~root s =
(* --cached so faster ? use -w ?
* -I means no search for binary files
* -n to show also line number
*)
let git_grep_options =
"-I -n"
in
let cmd =
spf "cd %s; git grep %s %s" root git_grep_options s
in
let xs = Common.cmd_to_list cmd in
let xs = xs +> List.map (fun s ->
if s =~ "\\([^:]*\\):\\([0-9]+\\):.*"
then
let (filename, lineno) = Common.matched2 s in
let lineno = s_to_i lineno in
let fullpath = Filename.concat root filename in
fullpath, (M.Line (lineno - 1))
else
failwith ("wrong git grep line: " ^ s)
) in
xs
(*e: run_grep_query *)
(*s: run_tbgs_query *)
let run_tbgs_query ~root s =
let cmd =
spf "cd %s; tbgs --stripdir %s" root s
in
let xs = Common.cmd_to_list cmd in
let xs = xs +> List.map (fun s ->
if s =~ "\\([^:]*\\):\\([0-9]+\\):.*"
then
let (filename, lineno) = Common.matched2 s in
let lineno = s_to_i lineno in
let fullpath = Filename.concat root filename in
fullpath, (M.Line (lineno - 1))
else
failwith ("wrong tbgs line: " ^ s)
) in
xs
(*e: run_tbgs_query *)
(*e: ui_search.ml *)