@@ -4,10 +4,11 @@ open FSharp.Compiler.Service.Tests.Common
4
4
open FSharp.Compiler .EditorServices
5
5
open Xunit
6
6
7
- let getCompletionInfo lineText ( line , column ) source =
7
+ let getCompletionInfo source =
8
+ let source , lineText , pos = getCursorPosAndPrepareSource source
8
9
let parseResults , checkResults = getParseAndCheckResultsPreview source
9
- let plid = QuickParse.GetPartialLongNameEx( lineText, column )
10
- checkResults.GetDeclarationListInfo( Some parseResults, line , lineText, plid)
10
+ let plid = QuickParse.GetPartialLongNameEx( lineText, pos.Column )
11
+ checkResults.GetDeclarationListInfo( Some parseResults, pos.Line , lineText, plid)
11
12
12
13
let getCompletionItemNames ( completionInfo : DeclarationListInfo ) =
13
14
completionInfo.Items |> Array.map ( fun item -> item.NameInCode)
@@ -19,92 +20,100 @@ let assertHasItemWithNames names (completionInfo: DeclarationListInfo) =
19
20
Assert.True( Set.contains name itemNames, $" {name} not found in {itemNames}" )
20
21
21
22
[<Fact>]
22
- let ``Expr - After record decl`` () =
23
- let info = getCompletionInfo " { Fi } " ( 4 , 0 ) " ""
23
+ let ``Expr - After record decl 01 `` () =
24
+ let info = getCompletionInfo """
24
25
type Record = { Field: int }
25
26
27
+ { Fi{caret} }
28
+ """
29
+ assertHasItemWithNames [ " ignore" ] info
26
30
31
+ [<Fact>]
32
+ let ``Expr - After record decl 02`` () =
33
+ let info = getCompletionInfo """
34
+ type Record = { Field: int }
35
+
36
+ {caret}
27
37
"""
28
38
assertHasItemWithNames [ " ignore" ] info
29
39
30
40
[<Fact>]
31
41
let ``Expr - record - field 01 - anon module`` () =
32
- let info = getCompletionInfo " { Fi } " ( 4 , 3 ) " ""
42
+ let info = getCompletionInfo """
33
43
type Record = { Field: int }
34
44
35
- { Fi }
45
+ { Fi{caret} }
36
46
"""
37
47
assertHasItemWithNames [ " Field" ] info
38
48
39
49
[<Fact>]
40
50
let ``Expr - record - field 02 - anon module`` () =
41
- let info = getCompletionInfo " { Fi } " ( 6 , 3 ) " ""
51
+ let info = getCompletionInfo """
42
52
type Record = { Field: int }
43
53
44
54
let record = { Field = 1 }
45
55
46
- { Fi }
56
+ { Fi{caret} }
47
57
"""
48
58
assertHasItemWithNames [ " Field" ] info
49
59
50
60
[<Fact>]
51
61
let ``Expr - record - empty 01`` () =
52
- let info = getCompletionInfo " { } " ( 4 , 2 ) " ""
62
+ let info = getCompletionInfo """
53
63
type Record = { Field: int }
54
64
55
- { }
65
+ { {caret} }
56
66
"""
57
67
assertHasItemWithNames [ " Field" ] info
58
68
59
69
[<Fact>]
60
70
let ``Expr - record - empty 02`` () =
61
- let info = getCompletionInfo " { } " ( 6 , 2 ) " ""
71
+ let info = getCompletionInfo """
62
72
type Record = { Field: int }
63
73
64
74
let record = { Field = 1 }
65
75
66
- { }
76
+ { {caret} }
67
77
"""
68
78
assertHasItemWithNames [ " Field" ; " record" ] info
69
79
70
80
[<Fact>]
71
81
let ``Underscore dot lambda - completion`` () =
72
- let info = getCompletionInfo " |> _.Len " ( 4 , 11 ) " ""
82
+ let info = getCompletionInfo """
73
83
let myFancyFunc (x:string) =
74
84
x
75
- |> _.Len"""
85
+ |> _.Len{caret} """
76
86
assertHasItemWithNames [ " Length" ] info
77
87
78
88
[<Fact>]
79
89
let ``Underscore dot lambda - method completion`` () =
80
- let info = getCompletionInfo " |> _.ToL " ( 4 , 11 ) " ""
90
+ let info = getCompletionInfo """
81
91
let myFancyFunc (x:string) =
82
92
x
83
- |> _.ToL"""
93
+ |> _.ToL{caret} """
84
94
assertHasItemWithNames [ " ToLower" ] info
85
95
86
96
[<Fact>]
87
97
let ``Underscore dot lambda - No prefix`` () =
88
- let info = getCompletionInfo " [s] |> List.map _. " ( 3 , 18 ) " ""
98
+ let info = getCompletionInfo """
89
99
let s = ""
90
- [s] |> List.map _.
100
+ [s] |> List.map _.{caret}
91
101
"""
92
102
assertHasItemWithNames [ " Length" ] info
93
103
94
104
[<Fact>]
95
105
let ``Type decl - Record - Field type 01`` () =
96
- let info = getCompletionInfo " type Record = { Field: } " ( 2 , 23 ) " ""
97
- type Record = { Field: }
106
+ let info = getCompletionInfo """
107
+ type Record = { Field: {caret} }
98
108
"""
99
109
assertHasItemWithNames [ " string" ] info
100
110
101
111
102
112
[<Fact>]
103
113
let ``Expr - Qualifier 01`` () =
104
- let info =
105
- getCompletionInfo " s.Trim(). " ( 3 , 13 ) """
114
+ let info = getCompletionInfo """
106
115
let f (s: string) =
107
- s.Trim().
116
+ s.Trim().{caret}
108
117
s.Trim()
109
118
s.Trim()
110
119
()
@@ -114,10 +123,10 @@ let f (s: string) =
114
123
[<Fact>]
115
124
let ``Expr - Qualifier 02`` () =
116
125
let info =
117
- getCompletionInfo " s.Trim(). " ( 4 , 13 ) " ""
126
+ getCompletionInfo """
118
127
let f (s: string) =
119
128
s.Trim()
120
- s.Trim().
129
+ s.Trim().{caret}
121
130
s.Trim()
122
131
()
123
132
"""
@@ -126,20 +135,56 @@ let f (s: string) =
126
135
[<Fact>]
127
136
let ``Expr - Qualifier 03`` () =
128
137
let info =
129
- getCompletionInfo " s.Trim(). " ( 5 , 13 ) " ""
138
+ getCompletionInfo """
130
139
let f (s: string) =
131
140
s.Trim()
132
141
s.Trim()
133
- s.Trim().
142
+ s.Trim().{caret}
134
143
()
135
144
"""
136
145
assertHasItemWithNames [ " Length" ] info
137
146
147
+ [<Fact>]
148
+ let ``Expr - Qualifier 04`` () =
149
+ let info =
150
+ getCompletionInfo """
151
+ type T() =
152
+ do
153
+ System.String.Empty.ToString().L{caret}
154
+ """
155
+ assertHasItemWithNames [ " Length" ] info
156
+
157
+ [<Fact>]
158
+ let ``Expr - Qualifier 05`` () =
159
+ let info =
160
+ getCompletionInfo """
161
+ System.String.Empty.ToString().{caret}
162
+ """
163
+ assertHasItemWithNames [ " Length" ] info
164
+
165
+ [<Fact>]
166
+ let ``Expr - Qualifier 06`` () =
167
+ let info =
168
+ getCompletionInfo """
169
+ System.String.Empty.ToString().L{caret}
170
+ """
171
+ assertHasItemWithNames [ " Length" ] info
172
+
173
+ [<Fact>]
174
+ let ``Expr - Qualifier 07`` () =
175
+ let info =
176
+ getCompletionInfo """
177
+ type T() =
178
+ do
179
+ System.String.Empty.ToString().L{caret}
180
+ ()
181
+ """
182
+ assertHasItemWithNames [ " Length" ] info
138
183
139
184
[<Fact>]
140
185
let ``Import - Ns 01`` () =
141
186
let info =
142
- getCompletionInfo " let _: R " ( 14 , 12 ) " ""
187
+ getCompletionInfo """
143
188
namespace Ns
144
189
145
190
type Rec1 = { F: int }
@@ -153,14 +198,14 @@ module M =
153
198
154
199
type Rec3 = { F: int }
155
200
156
- let _: R = ()
201
+ let _: R{caret} = ()
157
202
"""
158
203
assertHasItemWithNames [ " Rec1" ; " Rec2" ; " Rec3" ] info
159
204
160
205
[<Fact>]
161
206
let ``Import - Ns 02 - Rec`` () =
162
207
let info =
163
- getCompletionInfo " let _: R " ( 14 , 12 ) " ""
208
+ getCompletionInfo """
164
209
namespace Ns
165
210
166
211
type Rec1 = { F: int }
@@ -174,14 +219,14 @@ module M =
174
219
175
220
type Rec3 = { F: int }
176
221
177
- let _: R = ()
222
+ let _: R{caret} = ()
178
223
"""
179
224
assertHasItemWithNames [ " Rec1" ; " Rec2" ; " Rec3" ] info
180
225
181
226
[<Fact>]
182
227
let ``Import - Ns 03 - Rec`` () =
183
228
let info =
184
- getCompletionInfo " let _: R " ( 14 , 12 ) " ""
229
+ getCompletionInfo """
185
230
namespace Ns
186
231
187
232
type Rec1 = { F: int }
@@ -195,6 +240,6 @@ module rec M =
195
240
196
241
type Rec3 = { F: int }
197
242
198
- let _: R = ()
243
+ let _: R{caret} = ()
199
244
"""
200
245
assertHasItemWithNames [ " Rec1" ; " Rec2" ; " Rec3" ] info
0 commit comments