@@ -122,6 +122,106 @@ class LSPTests extends FunSuite {
122
122
}
123
123
}
124
124
125
+ // Diagnostics
126
+ //
127
+ //
128
+
129
+ test(" main function return type" ) {
130
+ withClientAndServer { (client, server) =>
131
+ val (textDoc, range) = raw """
132
+ |def main() = 1
133
+ |↑ ↑
134
+ | """ .stripMargin.textDocumentAndRange
135
+
136
+ val didOpenParams = new DidOpenTextDocumentParams ()
137
+ didOpenParams.setTextDocument(textDoc)
138
+ server.getTextDocumentService().didOpen(didOpenParams)
139
+
140
+ val diagnostic = new Diagnostic ()
141
+ diagnostic.setRange(range)
142
+ diagnostic.setSeverity(DiagnosticSeverity .Error )
143
+ diagnostic.setSource(" effekt" )
144
+ diagnostic.setMessage(" Main must return Unit, please use `exit(n)` to return an error code." )
145
+
146
+ val diagnosticsWithError = new util.ArrayList [Diagnostic ]()
147
+ diagnosticsWithError.add(diagnostic)
148
+
149
+ val expected = List (
150
+ new PublishDiagnosticsParams (" file://test.effekt" , new util.ArrayList [Diagnostic ]()),
151
+ new PublishDiagnosticsParams (" file://test.effekt" , diagnosticsWithError)
152
+ )
153
+
154
+ val diagnostics = client.receivedDiagnostics()
155
+ assertEquals(diagnostics, expected)
156
+ }
157
+ }
158
+
159
+ test(" exactly one main function" ) {
160
+ withClientAndServer { (client, server) =>
161
+ val (textDoc, range) = raw """
162
+ |def main() = println("hello")
163
+ |↑
164
+ |def main() = 42
165
+ | ↑
166
+ | """ .stripMargin.textDocumentAndRange
167
+
168
+ val didOpenParams = new DidOpenTextDocumentParams ()
169
+ didOpenParams.setTextDocument(textDoc)
170
+ server.getTextDocumentService().didOpen(didOpenParams)
171
+
172
+ val diagnostic = new Diagnostic ()
173
+ diagnostic.setRange(range)
174
+ diagnostic.setSeverity(DiagnosticSeverity .Error )
175
+ diagnostic.setSource(" effekt" )
176
+ diagnostic.setMessage(" Multiple main functions defined: test::main, test::main" )
177
+
178
+ val diagnosticsWithError = new util.ArrayList [Diagnostic ]()
179
+ diagnosticsWithError.add(diagnostic)
180
+
181
+ val expected = List (
182
+ new PublishDiagnosticsParams (" file://test.effekt" , new util.ArrayList [Diagnostic ]()),
183
+ new PublishDiagnosticsParams (" file://test.effekt" , diagnosticsWithError)
184
+ )
185
+
186
+ val diagnostics = client.receivedDiagnostics()
187
+ assertEquals(diagnostics, expected)
188
+ }
189
+ }
190
+
191
+ test(" no unhandled effects in main function" ) {
192
+ withClientAndServer { (client, server) =>
193
+ val (textDoc, range) = raw """
194
+ |effect Eff(): Unit
195
+ |def main() = {
196
+ |↑
197
+ | do Eff()
198
+ |}
199
+ |↑
200
+ | """ .stripMargin.textDocumentAndRange
201
+
202
+ val didOpenParams = new DidOpenTextDocumentParams ()
203
+ didOpenParams.setTextDocument(textDoc)
204
+ server.getTextDocumentService().didOpen(didOpenParams)
205
+
206
+ val diagnostic = new Diagnostic ()
207
+ diagnostic.setRange(range)
208
+ diagnostic.setSeverity(DiagnosticSeverity .Error )
209
+ diagnostic.setSource(" effekt" )
210
+ diagnostic.setMessage(" Main cannot have effects, but includes effects: { Eff }" )
211
+
212
+ val diagnosticsWithError = new util.ArrayList [Diagnostic ]()
213
+ diagnosticsWithError.add(diagnostic)
214
+
215
+ val expected = List (
216
+ new PublishDiagnosticsParams (" file://test.effekt" , new util.ArrayList [Diagnostic ]()),
217
+ new PublishDiagnosticsParams (" file://test.effekt" , diagnosticsWithError)
218
+ )
219
+
220
+ val diagnostics = client.receivedDiagnostics()
221
+ assertEquals(diagnostics, expected)
222
+ }
223
+ }
224
+
125
225
test(" setTrace is implemented" ) {
126
226
withClientAndServer { (client, server) =>
127
227
val didOpenParams = new DidOpenTextDocumentParams ()
0 commit comments