@@ -77,6 +77,13 @@ spec = describe "Context of different cursor positions" $ do
77
77
78
78
actual `shouldBe` res
79
79
80
+ it " import hiding context" $ withCurrentDirectory " ./test/testdata/context" $ do
81
+ fp_ <- makeAbsolute " ./ExampleContext.hs"
82
+ let res = IdeResultOk (Just (ImportHidingContext " Control.Monad" ))
83
+ actual <- getContextAt fp_ (toPos (4 , 32 ))
84
+
85
+ actual `shouldBe` res
86
+
80
87
it " function declaration context"
81
88
$ withCurrentDirectory " ./test/testdata/context"
82
89
$ do
@@ -85,6 +92,14 @@ spec = describe "Context of different cursor positions" $ do
85
92
actual <- getContextAt fp_ (toPos (6 , 1 ))
86
93
87
94
actual `shouldBe` res
95
+
96
+ it " function signature context"
97
+ $ withCurrentDirectory " ./test/testdata/context"
98
+ $ do
99
+ fp_ <- makeAbsolute " ./ExampleContext.hs"
100
+ let res = IdeResultOk (Just TypeContext )
101
+ actual <- getContextAt fp_ (toPos (6 , 8 ))
102
+ actual `shouldBe` res
88
103
89
104
90
105
it " function definition context"
@@ -95,70 +110,126 @@ spec = describe "Context of different cursor positions" $ do
95
110
actual <- getContextAt fp_ (toPos (7 , 1 ))
96
111
actual `shouldBe` res
97
112
98
- it " function signature context"
113
+ -- This is interesting, the context for this is assumed to be ValueContext
114
+ -- although the cursor is at the signature of a function in a where clause.
115
+ -- Reason is probably that we only traverse the AST until we know that
116
+ -- that we are in a ValueContext, however, within a ValueContext, another
117
+ -- TypeContext may arise, like in this case.
118
+ it " inner function declaration context"
99
119
$ withCurrentDirectory " ./test/testdata/context"
100
120
$ do
101
- fp_ <- makeAbsolute " ./ExampleContext.hs"
102
- let res = IdeResultOk (Just TypeContext )
103
- actual <- getContextAt fp_ (toPos (6 , 8 ))
104
- actual `shouldBe` res
121
+ fp_ <- makeAbsolute " ./ExampleContext.hs"
122
+ let res = IdeResultOk (Just ValueContext )
123
+ actual <- getContextAt fp_ (toPos (9 , 10 ))
124
+ actual `shouldBe` res
125
+
126
+ it " inner function value context"
127
+ $ withCurrentDirectory " ./test/testdata/context"
128
+ $ do
129
+ fp_ <- makeAbsolute " ./ExampleContext.hs"
130
+ let res = IdeResultOk (Just ValueContext )
131
+ actual <- getContextAt fp_ (toPos (10 , 10 ))
132
+ actual `shouldBe` res
105
133
134
+
135
+ -- Declare a datatype, is Nothing, could be DataContext
106
136
it " data declaration context"
107
137
$ withCurrentDirectory " ./test/testdata/context"
108
138
$ do
109
139
fp_ <- makeAbsolute " ./ExampleContext.hs"
110
140
let res = IdeResultOk Nothing
111
- actual <- getContextAt fp_ (toPos (9 , 8 ))
141
+ actual <- getContextAt fp_ (toPos (12 , 8 ))
142
+ actual `shouldBe` res
143
+
144
+ -- Define a datatype.
145
+ it " data definition context"
146
+ $ withCurrentDirectory " ./test/testdata/context"
147
+ $ do
148
+ fp_ <- makeAbsolute " ./ExampleContext.hs"
149
+ let res = IdeResultOk (Just TypeContext )
150
+ actual <- getContextAt fp_ (toPos (12 , 18 ))
112
151
actual `shouldBe` res
113
152
114
153
it " class declaration context"
115
154
$ withCurrentDirectory " ./test/testdata/context"
116
155
$ do
117
156
fp_ <- makeAbsolute " ./ExampleContext.hs"
118
157
let res = IdeResultOk (Just ClassContext )
119
- actual <- getContextAt fp_ (toPos (12 , 8 ))
158
+ actual <- getContextAt fp_ (toPos (15 , 8 ))
120
159
actual `shouldBe` res
121
160
122
161
it " class declaration function sig context"
123
162
$ withCurrentDirectory " ./test/testdata/context"
124
163
$ do
125
164
fp_ <- makeAbsolute " ./ExampleContext.hs"
126
165
let res = IdeResultOk (Just ClassContext )
127
- actual <- getContextAt fp_ (toPos (13 , 7 ))
166
+ actual <- getContextAt fp_ (toPos (16 , 7 ))
128
167
actual `shouldBe` res
129
168
130
169
it " instance declaration context"
131
170
$ withCurrentDirectory " ./test/testdata/context"
132
171
$ do
133
172
fp_ <- makeAbsolute " ./ExampleContext.hs"
134
173
let res = IdeResultOk (Just InstanceContext )
135
- actual <- getContextAt fp_ (toPos (15 , 7 ))
174
+ actual <- getContextAt fp_ (toPos (18 , 7 ))
136
175
actual `shouldBe` res
137
176
177
+ -- Function definition
138
178
it " instance declaration function def context"
139
179
$ withCurrentDirectory " ./test/testdata/context"
140
180
$ do
141
181
fp_ <- makeAbsolute " ./ExampleContext.hs"
142
182
let res = IdeResultOk (Just InstanceContext )
143
- actual <- getContextAt fp_ (toPos (16 , 6 ))
183
+ actual <- getContextAt fp_ (toPos (19 , 6 ))
144
184
actual `shouldBe` res
145
185
186
+ -- This seems plain wrong, if the cursor is on the String "deriving",
187
+ -- we would expect the context to be DerivingContext, but it is not.
188
+ -- May require investigation if this is important.
146
189
it " deriving context"
147
190
$ withCurrentDirectory " ./test/testdata/context"
148
191
$ do
149
192
fp_ <- makeAbsolute " ./ExampleContext.hs"
150
193
let res = IdeResultOk Nothing
151
- actual <- getContextAt fp_ (toPos (10 , 9 ))
194
+ actual <- getContextAt fp_ (toPos (13 , 9 ))
195
+ actual `shouldBe` res
196
+
197
+ -- Cursor is directly before the open parenthesis of a deriving clause.
198
+ -- E.g. deriving (...)
199
+ -- ^ ---- cursor is here
200
+ -- Context is still Nothing.
201
+ it " deriving parenthesis context"
202
+ $ withCurrentDirectory " ./test/testdata/context"
203
+ $ do
204
+ fp_ <- makeAbsolute " ./ExampleContext.hs"
205
+ let res = IdeResultOk Nothing
206
+ actual <- getContextAt fp_ (toPos (13 , 14 ))
207
+ actual `shouldBe` res
208
+
209
+ -- Cursor is directly after the open parenthesis of a deriving clause.
210
+ -- E.g. deriving (...)
211
+ -- ^ ---- cursor is here
212
+ -- Context is now Type. This makes sense, but an extension may be to be
213
+ -- aware of the context of a deriving clause, thus offering only Type Classes
214
+ -- as a completion.
215
+ it " deriving parenthesis context"
216
+ $ withCurrentDirectory " ./test/testdata/context"
217
+ $ do
218
+ fp_ <- makeAbsolute " ./ExampleContext.hs"
219
+ let res = IdeResultOk (Just TypeContext )
220
+ actual <- getContextAt fp_ (toPos (13 , 15 ))
152
221
actual `shouldBe` res
153
222
154
223
it " deriving typeclass context"
155
224
$ withCurrentDirectory " ./test/testdata/context"
156
225
$ do
157
226
fp_ <- makeAbsolute " ./ExampleContext.hs"
158
227
let res = IdeResultOk (Just TypeContext )
159
- actual <- getContextAt fp_ (toPos (10 , 18 ))
228
+ actual <- getContextAt fp_ (toPos (13 , 18 ))
160
229
actual `shouldBe` res
161
230
231
+ -- Point at an empty line.
232
+ -- There is no context
162
233
it " nothing" $ withCurrentDirectory " ./test/testdata/context" $ do
163
234
fp_ <- makeAbsolute " ./ExampleContext.hs"
164
235
let res = IdeResultOk Nothing
0 commit comments