-
Notifications
You must be signed in to change notification settings - Fork 1
/
Completion.clc
111 lines (85 loc) · 3.23 KB
/
Completion.clc
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
mixin class Command version 2
{
static Array<String> programNames = new Array<String>();
static bool initialize() {
if(Clover.argv[0] == "iclover") {
Self.get_program_name_from_path_env(Self.programNames);
}
return true;
}
static void get_program_name_from_path_env(Array<String> result) {
/// get program name from PATH environment variable ///
String env_path = System.getenv("PATH");
Path path = p"";
for(int offset = 0; offset<env_path.length(); offset++) {
if(env_path[offset] == ':') {
if(path.existance() && path.to_stat().S_ISDIR()) {
path.entries().each() {|Path program|
Path program_path = (path + "/" + program).toPath();
if(program_path.existance() && program_path.to_stat().S_IXUGO()) {
result.add(program.toString() + "()");
}
}
}
path = p"";
}
else {
path += env_path[offset].toString().toPath();
}
}
if(path.existance() && path.to_stat().S_ISDIR()) {
path.entries().each() { |Path program|
Path program_path = (path + "/" + program).toPath();
if(program_path.existance() && program_path.to_stat().S_IXUGO()) {
result.add(program.toString() + "()");
}
}
}
}
static Array<String> completion()
{
Array<String> result = new Array<String>();
/// get method name from Command class ///
Array<Method> methods = Command->toClass().methods();
for(int i=0; i<methods.length(); i++) {
if(!methods[i].isClassMethod()) {
String candidate = "";
candidate += methods[i].name() + "(";
Array<Type> params = methods[i].parametors();
for(int j=0; j<params.length(); j++) {
candidate += params[j].toString();
if(j != params.length()-1) {
candidate += ",";
}
}
candidate += ")";
result.add(candidate);
}
}
result.concat(Self.programNames);
return result;
}
static Array<String> completionOfClassMethod()
{
Array<String> result = new Array<String>();
/// get method name from Command class ///
Array<Method> methods = Command->toClass().methods();
for(int i=0; i<methods.length(); i++) {
if(methods[i].isClassMethod()) {
String candidate = "";
candidate += methods[i].name() + "(";
Array<Type> params = methods[i].parametors();
for(int j=0; j<params.length(); j++) {
candidate += params[j].toString();
if(j != params.length()-1) {
candidate += ",";
}
}
candidate += ")";
result.add(candidate);
}
}
result.concat(Self.programNames);
return result;
}
}