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

feat: Better LSP related location error messages #2434

Merged
merged 7 commits into from
Jul 18, 2022

Conversation

MikaelMayer
Copy link
Member

Improvement: instead of "Related location", explicit what these related locations are about:
image

Fixes dafny-lang/ide-vscode#211
On hovering a postcondition, the main message is now "This postcondition might not hold on a return path". #2433 takes cares of changing "related location" to "return path".

Fixes dafny-lang/ide-vscode#197 by changing all Uri to string conversion to the standard Uri.toString() / DocumentUri.Parse() so that there is no loss of conversion, and we don't assume a valid file name. Except for includes.

Fixes dafny-lang/ide-vscode#193 by providing which postconditions are failing explicitely

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

Copy link
Member

@atomb atomb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a very useful feature! The main thing I'd change is to make it clearer in the changelog that it's a very useful feature. ;)

RELEASE_NOTES.md Outdated
@@ -1,3 +1,7 @@
# Upcoming

- feat: Snippet in the error messages of the language server. (https://github.com/dafny-lang/dafny/pull/2434)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This description isn't entirely clear to me, and could probably do more to show how nice this is to have.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the new description?

if (tokenForMessage is RangeToken range) {
var rangeLength = range.EndToken.pos + range.EndToken.val.Length - range.StartToken.pos;
if (message == PostConditionFailingMessage) {
var postcondition = entryDocumentsource.Substring(range.StartToken.pos, rangeLength);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, nice, so you get the exact text from the document!

var postcondition = entryDocumentsource.Substring(range.StartToken.pos, rangeLength);
message = $"This postcondition might not hold: {postcondition}";
} else if (message == "Related location") {
// We can do better than that.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. :)

var (tokenForMessage, inner) = token is NestedToken nestedToken ? (nestedToken.Outer, nestedToken.Inner) : (token, null);
if (tokenForMessage is RangeToken range) {
var rangeLength = range.EndToken.pos + range.EndToken.val.Length - range.StartToken.pos;
if (message == PostConditionFailingMessage) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not thrilled with this way of detecting the type of message, but I suspect it may be necessary for now, and that we'd have to do a lot of refactoring to be able to do it in a nicer way.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had the same feeling.

var tokenUriSystemPath = tokenUri.GetFileSystemPath();
var entryDocumentUriSystemPath = entryDocumentUri.GetFileSystemPath();
if (tokenUri == entryDocumentUri || tokenUriSystemPath == entryDocumentUriSystemPath ||
tokenUriSystemPath == "/" + entryDocumentUriSystemPath) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof. Is there a way we can normalize the system path to avoid having to check all of these cases?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right. I had been fighting to enable a simpler code but I forgot this case. Let me fix it.

Copy link
Member

@atomb atomb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

var entryDocumentUriSystemPath = entryDocumentUri.GetFileSystemPath();
if (tokenUri == entryDocumentUri || tokenUriSystemPath == entryDocumentUriSystemPath ||
tokenUriSystemPath == "/" + entryDocumentUriSystemPath) {
if (tokenUri == entryDocumentUri) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@@ -1,6 +1,6 @@
# Upcoming

- feat: Snippet in the error messages of the language server. (https://github.com/dafny-lang/dafny/pull/2434)
- feat: *Less code navigation when verifying code*: In the IDE, failing postconditions and preconditions error messages now immediately display the sub-conditions that Dafny could not prove. Both on hover and in the Problems window. (https://github.com/dafny-lang/dafny/pull/2434)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonderful. :)

@MikaelMayer MikaelMayer enabled auto-merge (squash) July 18, 2022 21:56
@MikaelMayer MikaelMayer merged commit f83beb0 into master Jul 18, 2022
@MikaelMayer MikaelMayer deleted the feat-better-related-location-error-messages branch July 18, 2022 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants