Skip to content

Commit 5cd765a

Browse files
Fix angry module LSP diagnostic (#6086)
### What was changed? Improve LSP diagnostics, so instead of <img width="278" alt="image" src="https://github.com/user-attachments/assets/36977d46-a9e0-406c-af33-7a317426a767" /> the IDE shows <img width="250" alt="image" src="https://github.com/user-attachments/assets/87c9c5df-89a4-49ea-8882-8322881dad19" /> For the errors: `not resolving module '_module' because there were errors in resolving its nested module 'A'"` `boolean literal used as if it had type int"` ### How has this been tested? - Added an LSP test <small>By submitting this pull request, I confirm that my contribution is made under the terms of the [MIT license](https://github.com/dafny-lang/dafny/blob/master/LICENSE.txt).</small>
1 parent 7db1e5f commit 5cd765a

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

Source/DafnyCore/AST/Modules/ModuleDefinition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ public bool Resolve(ModuleSignature sig, ModuleResolver resolver, string exportS
467467
if (!nestedModuleDecl.ModuleDef.SuccessfullyResolved) {
468468
if (!IsEssentiallyEmptyModuleBody()) {
469469
// say something only if this will cause any testing to be omitted
470-
resolver.reporter.Error(MessageSource.Resolver, nestedModuleDecl,
470+
resolver.reporter.Error(MessageSource.Resolver, nestedModuleDecl.NameNode,
471471
"not resolving module '{0}' because there were errors in resolving its nested module '{1}'", Name,
472472
nestedModuleDecl.Name);
473473
}

Source/DafnyLanguageServer.Test/Diagnostics/DiagnosticsTest.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,26 @@ namespace Microsoft.Dafny.LanguageServer.IntegrationTest.Synchronization {
1818
public class DiagnosticsTest : ClientBasedLanguageServerTest {
1919
private readonly string testFilesDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Synchronization/TestFiles");
2020

21+
[Fact]
22+
public async Task NestedModuleRange() {
23+
var source = @"
24+
module A {
25+
function A(x: int): int {
26+
true
27+
}
28+
function B(x: int): int {
29+
1
30+
}
31+
}
32+
method Main() {
33+
}".TrimStart();
34+
var documentItem = CreateAndOpenTestDocument(source);
35+
var diagnostics1 = await GetLastDiagnostics(documentItem);
36+
var startOrdered = diagnostics1.OrderBy(r => r.Range.Start).ToList();
37+
Assert.Equal(new Range(0, 7, 0, 8), startOrdered[0].Range);
38+
Assert.Equal(new Range(1, 2, 3, 3), startOrdered[1].Range);
39+
}
40+
2141
[Fact]
2242
public async Task ResolutionErrorMigration() {
2343
var source = @"module ResolutionError {

0 commit comments

Comments
 (0)