Skip to content

Commit d26c059

Browse files
committed
New completion test format.
1 parent 642d4f1 commit d26c059

24 files changed

+647
-548
lines changed

analysis/src/Commands.ml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,30 @@ let test ~path =
301301
close_out cout;
302302
completion ~debug:true ~path ~pos:(line, col) ~currentFile;
303303
Sys.remove currentFile
304+
| "co2" ->
305+
print_endline
306+
("Complete " ^ path ^ " " ^ string_of_int line ^ ":"
307+
^ string_of_int col);
308+
let currentFile, cout = Filename.open_temp_file "def" "txt" in
309+
lines
310+
|> List.iteri (fun j l ->
311+
let lineToOutput =
312+
if
313+
j == i - 1
314+
&& String.length l >= 2
315+
&& String.sub l 0 2 = "//"
316+
then " " ^ String.sub l 2 (String.length l - 2)
317+
else if
318+
j == i - 1
319+
&& String.length l >= 4
320+
&& String.sub l 0 4 = " //"
321+
then " " ^ String.sub l 4 (String.length l - 4)
322+
else l
323+
in
324+
Printf.fprintf cout "%s\n" lineToOutput);
325+
close_out cout;
326+
completion ~debug:true ~path ~pos:(line, col) ~currentFile;
327+
Sys.remove currentFile
304328
| "hig" ->
305329
print_endline ("Highlight " ^ path);
306330
SemanticTokens.command ~debug:true

analysis/tests/src/CompletePrioritize1.res

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ module Test = {
33
let add = (a: float) => a +. 1.0
44
}
55
let a: Test.t = {name: 4}
6-
//^com a->
7-
8-
6+
// a->
7+
// ^co2

analysis/tests/src/CompletePrioritize2.res

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ module Test = {
77
let add = (ax: t) => ax.name + 1
88
}
99
let ax: Test.t = {name: 4}
10-
//^com ax->
10+
// ax->
11+
// ^co2
1112

12-
//^com ax
13+
// ax
14+
// ^co2

analysis/tests/src/Completion.res

Lines changed: 108 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
module MyList = Belt.List
2-
//^com MyList.m
3-
//^com Array.
4-
//^com Array.m
5-
2+
// MyList.m
3+
// ^co2
4+
// Array.
5+
// ^co2
6+
// Array.m
7+
// ^co2
68

79
module Dep: {
810
@ocaml.doc("Some doc comment") @deprecated("Use customDouble instead")
@@ -11,95 +13,120 @@ module Dep: {
1113
let customDouble = foo => foo * 2
1214
}
1315

14-
//^com let cc = Dep.c
16+
// let cc = Dep.c
17+
// ^co2
1518

1619
module Lib = {
1720
let foo = (~age, ~name) => name ++ string_of_int(age)
1821
let next = (~number=0, ~year) => number + year
1922
}
2023

21-
//^com let x = Lib.foo(~
24+
// let x = Lib.foo(~
25+
// ^co2
2226

23-
//^com [1,2,3]->m
27+
// [1,2,3]->m
28+
// ^co2
2429

25-
//^com "abc"->toU
30+
// "abc"->toU
31+
// ^co2
2632

2733
let op = Some(3)
2834

29-
//^com op->e
35+
// op->e
36+
// ^co2
3037

3138
module ForAuto = {
3239
type t = int
33-
let abc = (x:t, _y:int) => x
34-
let abd = (x:t, _y:int) => x
40+
let abc = (x: t, _y: int) => x
41+
let abd = (x: t, _y: int) => x
3542
}
3643

37-
let fa:ForAuto.t = 34
38-
//^com fa->
44+
let fa: ForAuto.t = 34
45+
// fa->
46+
// ^co2
3947

40-
//^com "hello"->Js.Dict.u
48+
// "hello"->Js.Dict.u
49+
// ^co2
4150

4251
module O = {
4352
module Comp = {
4453
@react.component
45-
let make = (~first="", ~zoo=3, ~second) =>
46-
React.string(first ++ second ++ string_of_int(zoo))
54+
let make = (~first="", ~zoo=3, ~second) => React.string(first ++ second ++ string_of_int(zoo))
4755
}
4856
}
4957

5058
let zzz = 11
5159

52-
//^com let comp = <O.Comp second=z
60+
// let comp = <O.Comp second=z
61+
// ^co2
5362

54-
//^com let comp = <O.Comp z
63+
// let comp = <O.Comp z
64+
// ^co2
5565

5666
//^doc
5767

58-
//^com @reac
68+
// @reac
69+
// ^co2
5970

60-
//^com @react.
71+
// @react.
72+
// ^co2
6173

62-
//^com let x = Lib.foo(~name, ~
74+
// let x = Lib.foo(~name, ~
75+
// ^co2
6376

64-
//^com let x = Lib.foo(~age, ~
77+
// let x = Lib.foo(~age, ~
78+
// ^co2
6579

66-
//^com let x = Lib.foo(~age={3+4}, ~
80+
// let x = Lib.foo(~age={3+4}, ~
81+
// ^co2
6782

68-
let _ = Lib.foo(//~age,
69-
//^com ~
70-
~age=3, ~name="")
83+
let _ = Lib.foo(
84+
//~age,
85+
//~
86+
// ^co2
87+
~age=3,
88+
~name="",
89+
)
7190

7291
let someObj = {"name": "a", "age": 32}
7392

74-
//^com someObj["a
93+
// someObj["a
94+
// ^co2
7595

7696
let nestedObj = {"x": {"y": {"name": "a", "age": 32}}}
7797

78-
//^com nestedObj["x"]["y"]["
98+
// nestedObj["x"]["y"]["
99+
// ^co2
79100

80-
let o : Obj.objT = assert false
81-
//^com o["a
101+
let o: Obj.objT = assert false
102+
// o["a
103+
// ^co2
82104

83105
type nestedObjT = {"x": Obj.nestedObjT}
84-
let no : nestedObjT = assert false
85-
//^com no["x"]["y"]["
106+
let no: nestedObjT = assert false
107+
// no["x"]["y"]["
108+
// ^co2
86109

87-
type r = {x:int, y:string}
110+
type r = {x: int, y: string}
88111
type rAlias = r
89-
let r:rAlias = assert false
90-
// ^com r.
112+
let r: rAlias = assert false
113+
// r.
114+
// ^co2
91115

92-
// ^com Obj.Rec.recordVal.
116+
// Obj.Rec.recordVal.
117+
// ^co2
93118

94-
let myAmazingFunction = (x,y) => x+y
119+
let myAmazingFunction = (x, y) => x + y
95120

96121
@react.component
97122
let make = () => {
98-
// ^com my
123+
// my
124+
// ^co2
99125
<> </>
100126
}
101127

102-
// ^com Obj.object["
128+
// Obj.object["
129+
// ^co2
103130

104131
let foo = {
105132
let x = {
@@ -117,44 +144,54 @@ let foo = {
117144
type z = int
118145
let v = 44
119146
}
120-
exception MyException (int, string, float, array<Js.Json.t>)
147+
exception MyException(int, string, float, array<Js.Json.t>)
121148
let _ = raise(MyException(2, "", 1.0, []))
122149
add((x: Inner.z), Inner.v + y)
123150
}
124151

125152
exception MyOtherException
126153

127-
// ^com <O.
154+
// <O.
155+
// ^co2
128156

129-
type aa= {x:int, name:string}
130-
type bb = {aa:aa, w:int}
131-
let q:bb = assert false
132-
// ^com q.aa.
133-
// ^com q.aa.n
157+
type aa = {x: int, name: string}
158+
type bb = {aa: aa, w: int}
159+
let q: bb = assert false
160+
// q.aa.
161+
// ^co2
162+
// q.aa.n
163+
// ^co2
134164

135-
// ^com Lis
165+
// Lis
166+
// ^co2
136167

137168
module WithChildren = {
138169
@react.component
139170
let make = (~children, ~name as _: string) => <jsx> children </jsx>
140171
}
141-
// ^com <WithChildren
172+
// <WithChildren
173+
// ^co2
142174

143-
// ^com type t = Js.n
144-
// ^com type t = ForAuto.
175+
// type t = Js.n
176+
// ^co2
177+
// type t = ForAuto.
178+
// ^co2
145179

146-
type z = | Allo | Asterix | Baba
180+
type z = Allo | Asterix | Baba
147181

148-
// ^com let q = As
182+
// let q = As
183+
// ^co2
149184

150-
// ^com module M = For
185+
// module M = For
186+
// ^co2
151187

152188
module Private = {
153189
%%private(let awr = 3)
154190
let b = awr
155191
}
156192

157-
// ^com Private.
193+
// Private.
194+
// ^co2
158195

159196
module Shadow = {
160197
module A = {
@@ -165,11 +202,14 @@ module Shadow = {
165202
}
166203
}
167204

168-
// ^com sha
205+
// sha
206+
// ^co2
169207
open Shadow.A
170-
// ^com sha
208+
// sha
209+
// ^co2
171210
open Shadow.B
172-
// ^com sha
211+
// sha
212+
// ^co2
173213
let _ = shadowed
174214

175215
module FAR = {
@@ -181,7 +221,14 @@ module FAO = {
181221
let forAutoObject = {"forAutoLabel": FAR.forAutoRecord, "age": 32}
182222
}
183223

184-
// ^com FAO.forAutoObject["
185-
// ^com FAO.forAutoObject["forAutoLabel"].
186-
// ^com FAO.forAutoObject["forAutoLabel"].forAuto->
187-
// ^com FAO.forAutoObject["forAutoLabel"].forAuto->ForAuto.a
224+
// FAO.forAutoObject["
225+
// ^co2
226+
227+
// FAO.forAutoObject["forAutoLabel"].
228+
// ^co2
229+
230+
// FAO.forAutoObject["forAutoLabel"].forAuto->
231+
// ^co2
232+
233+
// FAO.forAutoObject["forAutoLabel"].forAuto->ForAuto.a
234+
// ^co2

analysis/tests/src/Cross.res

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ let crossRef = References.x
33

44
let crossRef2 = References.x
55

6-
76
module Ref = References
87

98
let crossRef3 = References.x
109

11-
1210
let crossRefWithInterface = ReferencesWithInterface.x
1311
// ^ref
1412

@@ -18,14 +16,12 @@ module RefWithInterface = ReferencesWithInterface
1816

1917
let crossRefWithInterface3 = ReferencesWithInterface.x
2018

21-
2219
let _ = RenameWithInterface.x
2320
// ^ren RenameWithInterfacePrime
2421

2522
let _ = RenameWithInterface.x
2623
// ^ren xPrime
2724

28-
2925
let typeDef = {TypeDefinition.item: "foobar"}
3026
// ^typ
3127

@@ -38,4 +34,5 @@ type defT = DefinitionWithInterface.t
3834
type defT2 = DefinitionWithInterface.t
3935
// ^typ
4036

41-
//^com DefinitionWithInterface.a
37+
// DefinitionWithInterface.a
38+
// ^co2

analysis/tests/src/Debug.res

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ module Before = {
1111
let _ = Id.getCmpInternal
1212
}
1313
module Inner = {
14-
// ^com eqN
14+
// eqN
15+
// ^co2
1516
open List
1617
let _ = map
1718
}

analysis/tests/src/Div.res

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
2-
let q = <div> </div>
1+
let q = <div />
32
// ^hov
43

5-
// ^com <div dangerous
4+
// <div dangerous
5+
// ^co2

0 commit comments

Comments
 (0)