-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathCli.ml
147 lines (112 loc) · 5.43 KB
/
Cli.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
let help =
{|
**Private CLI For rescript-vscode usage only**
API examples:
./rescript-editor-analysis.exe completion src/MyFile.res 0 4 currentContent.res
./rescript-editor-analysis.exe definition src/MyFile.res 9 3
./rescript-editor-analysis.exe typeDefinition src/MyFile.res 9 3
./rescript-editor-analysis.exe documentSymbol src/Foo.res
./rescript-editor-analysis.exe workspaceSymbols src/
./rescript-editor-analysis.exe hover src/MyFile.res 10 2
./rescript-editor-analysis.exe references src/MyFile.res 10 2
./rescript-editor-analysis.exe rename src/MyFile.res 10 2 foo
./rescript-editor-analysis.exe diagnosticSyntax src/MyFile.res
./rescript-editor-analysis.exe inlayHint src/MyFile.res 0 3 25
./rescript-editor-analysis.exe codeLens src/MyFile.res
Dev-time examples:
./rescript-editor-analysis.exe dump src/MyFile.res src/MyFile2.res
./rescript-editor-analysis.exe test src/MyFile.res
Note: positions are zero-indexed (start at 0 0), following LSP.
https://microsoft.github.io/language-server-protocol/specification#position
Options:
completion: compute autocomplete for MyFile.res at line 0 and column 4,
where MyFile.res is being edited and the editor content is in file current.res.
./rescript-editor-analysis.exe completion src/MyFile.res 0 4 current.res
definition: get definition for item in MyFile.res at line 10 column 2:
./rescript-editor-analysis.exe definition src/MyFile.res 10 2
typeDefinition: get type definition for item in MyFile.res at line 10 column 2:
./rescript-editor-analysis.exe typeDefinition src/MyFile.res 10 2
documentSymbol: get all symbols declared in MyFile.res
./rescript-editor-analysis.exe documentSymbol src/MyFile.res
workspaceSymbols: get all symbols in directory src/
./rescript-editor-analysis.exe workspaceSymbols src/
hover: get inferred type for MyFile.res at line 10 column 2:
./rescript-editor-analysis.exe hover src/MyFile.res 10 2
references: get all references to item in MyFile.res at line 10 column 2:
./rescript-editor-analysis.exe references src/MyFile.res 10 2
rename: rename all appearances of item in MyFile.res at line 10 column 2 with foo:
./rescript-editor-analysis.exe rename src/MyFile.res 10 2 foo
semanticTokens: return token semantic highlighting info for MyFile.res
./rescript-editor-analysis.exe semanticTokens src/MyFile.res
createInterface: print to stdout the interface file for src/MyFile.res
./rescript-editor-analysis.exe createInterface src/MyFile.res lib/bs/src/MyFile.cmi
format: print to stdout the formatted version of the provided file
./rescript-editor-analysis.exe format src/MyFile.res
diagnosticSyntax: print to stdout diagnostic for syntax
./rescript-editor-analysis.exe diagnosticSyntax src/MyFile.res
inlayHint: get all inlay Hint between line 0 and 3 declared in MyFile.res. Last argument is maximum of character length for inlay hints
./rescript-editor-analysis.exe inlayHint src/MyFile.res 0 3 25
codeLens: get all code lens entries for file src/MyFile.res
./rescript-editor-analysis.exe codeLens src/MyFile.res
test: run tests specified by special comments in file src/MyFile.res
./rescript-editor-analysis.exe test src/src/MyFile.res
|}
let main () =
match Array.to_list Sys.argv with
| [_; "completion"; path; line; col; currentFile] ->
Commands.completion ~debug:false ~path
~pos:(int_of_string line, int_of_string col)
~currentFile
| [_; "definition"; path; line; col] ->
Commands.definition ~path
~pos:(int_of_string line, int_of_string col)
~debug:false
| [_; "typeDefinition"; path; line; col] ->
Commands.typeDefinition ~path
~pos:(int_of_string line, int_of_string col)
~debug:false
| [_; "documentSymbol"; path] -> Commands.documentSymbol ~path
| [_; "workspaceSymbols"; dir] -> Commands.workspaceSymbols ~dir
| [_; "hover"; path; line; col; currentFile] ->
Commands.hover ~path
~pos:(int_of_string line, int_of_string col)
~currentFile ~debug:false
| [_; "inlayHint"; path; line_start; line_end; maxLength] ->
Commands.inlayhint ~path
~pos:(int_of_string line_start, int_of_string line_end)
~maxLength ~debug:false
| [_; "codeLens"; path] -> Commands.codeLens ~path ~debug:false
| [_; "codeAction"; path; line; col; currentFile] ->
Commands.codeAction ~path
~pos:(int_of_string line, int_of_string col)
~currentFile ~debug:false
| [_; "diagnosticSyntax"; path] -> Commands.diagnosticSyntax ~path
| _ :: "reanalyze" :: _ ->
let len = Array.length Sys.argv in
for i = 1 to len - 2 do
Sys.argv.(i) <- Sys.argv.(i + 1)
done;
Sys.argv.(len - 1) <- "";
Reanalyze.cli ()
| [_; "references"; path; line; col] ->
Commands.references ~path
~pos:(int_of_string line, int_of_string col)
~debug:false
| [_; "rename"; path; line; col; newName] ->
Commands.rename ~path
~pos:(int_of_string line, int_of_string col)
~newName ~debug:false
| [_; "semanticTokens"; currentFile] ->
SemanticTokens.semanticTokens ~currentFile
| [_; "createInterface"; path; cmiFile] ->
Printf.printf "\"%s\""
(Json.escape (CreateInterface.command ~path ~cmiFile))
| [_; "format"; path] ->
Printf.printf "\"%s\"" (Json.escape (Commands.format ~path))
| [_; "test"; path] -> Commands.test ~path
| args when List.mem "-h" args || List.mem "--help" args -> prerr_endline help
| _ ->
prerr_endline help;
exit 1
;;
main ()