Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Explicit assertions no longer considered implicit for code actions #6030

Merged
merged 8 commits into from
Jan 13, 2025
35 changes: 33 additions & 2 deletions Source/DafnyLanguageServer.Test/CodeActions/CodeActionsTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.Dafny.LanguageServer.IntegrationTest.Extensions;
using System;
using OmniSharp.Extensions.LanguageServer.Protocol.Document;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using System.Collections.Generic;
Expand All @@ -8,11 +8,10 @@
using Microsoft.Dafny.LanguageServer.IntegrationTest.Util;
using Xunit;
using Xunit.Abstractions;
using XunitAssertMessages;

namespace Microsoft.Dafny.LanguageServer.IntegrationTest.CodeActions {
public class CodeActionTest : ClientBasedLanguageServerTest {
private async Task<List<CommandOrCodeAction>> RequestCodeActionAsync(TextDocumentItem documentItem, Range range) {

Check failure on line 14 in Source/DafnyLanguageServer.Test/CodeActions/CodeActionsTest.cs

View workflow job for this annotation

GitHub Actions / build

'Range' is an ambiguous reference between 'OmniSharp.Extensions.LanguageServer.Protocol.Models.Range' and 'System.Range'

Check failure on line 14 in Source/DafnyLanguageServer.Test/CodeActions/CodeActionsTest.cs

View workflow job for this annotation

GitHub Actions / build

'Range' is an ambiguous reference between 'OmniSharp.Extensions.LanguageServer.Protocol.Models.Range' and 'System.Range'

Check failure on line 14 in Source/DafnyLanguageServer.Test/CodeActions/CodeActionsTest.cs

View workflow job for this annotation

GitHub Actions / doctests

'Range' is an ambiguous reference between 'OmniSharp.Extensions.LanguageServer.Protocol.Models.Range' and 'System.Range'

Check failure on line 14 in Source/DafnyLanguageServer.Test/CodeActions/CodeActionsTest.cs

View workflow job for this annotation

GitHub Actions / doctests

'Range' is an ambiguous reference between 'OmniSharp.Extensions.LanguageServer.Protocol.Models.Range' and 'System.Range'

Check failure on line 14 in Source/DafnyLanguageServer.Test/CodeActions/CodeActionsTest.cs

View workflow job for this annotation

GitHub Actions / build-refman (ubuntu-22.04)

'Range' is an ambiguous reference between 'OmniSharp.Extensions.LanguageServer.Protocol.Models.Range' and 'System.Range'

Check failure on line 14 in Source/DafnyLanguageServer.Test/CodeActions/CodeActionsTest.cs

View workflow job for this annotation

GitHub Actions / build-refman (ubuntu-22.04)

'Range' is an ambiguous reference between 'OmniSharp.Extensions.LanguageServer.Protocol.Models.Range' and 'System.Range'

Check failure on line 14 in Source/DafnyLanguageServer.Test/CodeActions/CodeActionsTest.cs

View workflow job for this annotation

GitHub Actions / singletons

'Range' is an ambiguous reference between 'OmniSharp.Extensions.LanguageServer.Protocol.Models.Range' and 'System.Range'

Check failure on line 14 in Source/DafnyLanguageServer.Test/CodeActions/CodeActionsTest.cs

View workflow job for this annotation

GitHub Actions / singletons

'Range' is an ambiguous reference between 'OmniSharp.Extensions.LanguageServer.Protocol.Models.Range' and 'System.Range'

Check failure on line 14 in Source/DafnyLanguageServer.Test/CodeActions/CodeActionsTest.cs

View workflow job for this annotation

GitHub Actions / xunit-tests / ubuntu-20.04 (1)

'Range' is an ambiguous reference between 'OmniSharp.Extensions.LanguageServer.Protocol.Models.Range' and 'System.Range'

Check failure on line 14 in Source/DafnyLanguageServer.Test/CodeActions/CodeActionsTest.cs

View workflow job for this annotation

GitHub Actions / xunit-tests / ubuntu-20.04 (1)

'Range' is an ambiguous reference between 'OmniSharp.Extensions.LanguageServer.Protocol.Models.Range' and 'System.Range'

Check failure on line 14 in Source/DafnyLanguageServer.Test/CodeActions/CodeActionsTest.cs

View workflow job for this annotation

GitHub Actions / xunit-tests / win (1)

'Range' is an ambiguous reference between 'OmniSharp.Extensions.LanguageServer.Protocol.Models.Range' and 'System.Range'

Check failure on line 14 in Source/DafnyLanguageServer.Test/CodeActions/CodeActionsTest.cs

View workflow job for this annotation

GitHub Actions / xunit-tests / win (1)

'Range' is an ambiguous reference between 'OmniSharp.Extensions.LanguageServer.Protocol.Models.Range' and 'System.Range'

Check failure on line 14 in Source/DafnyLanguageServer.Test/CodeActions/CodeActionsTest.cs

View workflow job for this annotation

GitHub Actions / xunit-tests / osx (1)

'Range' is an ambiguous reference between 'OmniSharp.Extensions.LanguageServer.Protocol.Models.Range' and 'System.Range'

Check failure on line 14 in Source/DafnyLanguageServer.Test/CodeActions/CodeActionsTest.cs

View workflow job for this annotation

GitHub Actions / xunit-tests / osx (1)

'Range' is an ambiguous reference between 'OmniSharp.Extensions.LanguageServer.Protocol.Models.Range' and 'System.Range'
var completionList = await client.RequestCodeAction(
new CodeActionParams {
TextDocument = documentItem.Uri.GetFileSystemPath(),
Expand Down Expand Up @@ -76,6 +75,21 @@
Assert.Empty(completionList);
}

[Fact]
public async Task TestAssertFalseNotSuggestingItself() {
await TestNoCodeAction(@"
method NoCodeAction() {
assert fal><se;
}");
}

[Fact]
public async Task TestEnsureFalseNotSuggestingItself() {
await TestNoCodeAction(@"
method NoCodeAction() ensures f><alse {
}", excepted: message => message == "Assert postcondition at return location where it fails");
}

[Fact]
public async Task TestInsertion() {
await TestCodeAction(@"
Expand Down Expand Up @@ -371,6 +385,23 @@

private static readonly Regex NewlineRegex = new Regex("\r?\n");

private async Task TestNoCodeAction(string source, Func<string, bool> excepted = null) {
await SetUp(o => o.Set(CommonOptionBag.RelaxDefiniteAssignment, true));
MarkupTestFile.GetPositionsAndAnnotatedRanges(source.TrimStart(), out var output, out var positions,
out var ranges);
var documentItem = await CreateOpenAndWaitForResolve(output);
var diagnostics = await GetLastDiagnostics(documentItem);
Assert.Equal(0, ranges.Count);
foreach (var position in positions) {
var completionList = await RequestCodeActionAsync(documentItem, new Range(position, position));
completionList = excepted == null
? completionList
: completionList.Where(completion =>
completion.CodeAction is not { Title: var title } || !excepted(title)).ToList();
Assert.Empty(completionList);
}
}

private async Task TestCodeAction(string source) {
await SetUp(o => o.Set(CommonOptionBag.RelaxDefiniteAssignment, true));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public override IEnumerable<DafnyCodeActionEdit> GetEdits() {
assertTree.Finished &&
assertTree.Range.Intersects(selection) &&
assertTree.StatusVerification is GutterVerificationStatus.Error or GutterVerificationStatus.Inconclusive &&
assertTree.GetAssertion()?.Description is ProofObligationDescription description &&
assertTree.GetAssertion()?.Description is ProofObligationDescription { IsImplicit: true } description &&
description.GetAssertedExpr(options) is { } assertedExpr) {
failingExpressions.Add(assertedExpr);
}
Expand Down
1 change: 1 addition & 0 deletions docs/dev/news/6025.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The code action for assertion no longer suggests asserting the same assertion.
Loading