Giter Site home page Giter Site logo

dafnyvscode / dafny-vscode Goto Github PK

View Code? Open in Web Editor NEW
18.0 18.0 12.0 8.64 MB

Dafny 2 for Visual Studio Code (Legacy)

Home Page: https://marketplace.visualstudio.com/items?itemName=correctnessLab.dafny-vscode-legacy

License: MIT License

TypeScript 92.92% Shell 3.11% Batchfile 0.20% Dockerfile 0.53% Dafny 3.20% Nix 0.04%
dafny visual-studio-code

dafny-vscode's Introduction

Dafny 2 VSCode (Legacy) Marketplace Downloads Count

โš  This plugin targets Dafny 2 and is deprecated. Consider switching to its successor that supports Dafny 3.0.0.

This repository contains the infrastructure necessary to support Dafny for Visual Studio Code.

To add Dafny 2 to VSCode, please go to the Visual Studio Marketplace.

master develop
Build Status
VSCode Marketplace
Build Status
Sounarcloud

Architecture

The infrastructure consists of a Dafny language server, which can be found in the server directory, and a VS Code extension, which in turn can be found in the client directory. These components communicate with each other using the Language Server Protocol (LSP).

Dafny VSode Architecture

Contribute

We welcome all contributions! Please create a pull request and we will take care of releasing a new version when appropriate.

How-To

Setup

It is pretty simple to contribute to this plugin. All it takes is having Visual Studio Code and npm installed. Simply clone this repository and switch into the new folder. On the command line, execute one of the following scripts:

  • Linux & macOS: scripts/dev-env.bash
  • Windows: scripts\dev-env.bat

These scripts install node dependencies and start code for both the server and client.

If all the commands succeeded, the language server part and the client part of the plugin are opened in two different Visual Studio Code editors and installs all the dependencies.

๐Ÿ›ˆ It is necessary that the code command is available in your PATH. On the Mac, this is usually not given. If it is missing, have a look at this tutorial.

โš ๏ธ Having the extension installed via the Visual Studio Marketplace (along with a Dafny installation via the extension), can lead to conflicts with your locally built extension. It is therefore recommended to uninstall all previous installations of the extension from Visual Studio Code.

Compile

In the server editor, press CTRL+Shift+b or โ‡ง+โŒ˜+B to compile. The task that is started also watches file changes and recompiles automatically after saving.

To try out the changes, go to the client editor and press F5. A new instance of Visual Studio Code will be started that has the Dafny plugin running and ready for testing. Sometimes, Visual Studio Code does not recognize changes and does not apply them to the running test instance. If this is the case, simply close and restart the test instance, the changes should then be applied.

Tests and Linting

Make sure that your changes don't break the existing tests in the client/test folder. You can run the tests with npm test while in the client folder. For this to work, you have to set environment variable DAFNY_PATH on your system to your Dafny release (without a "/" at the end of the path).

Alternatively, you can execute tests with docker (Linux & macOS only) using scripts/test-docker.bash.

If you add new features, please make sure to include unit tests to cover as much code as possible.

To get some code-consistency, we check against tslint in all automated builds. Please check that your client and server complies: tslint --project ..

Release

To release a new version of Dafny VSCode, follow the description in RELEASE.md.

License

Dafny VSCode is released under the MIT License. Note that by submitting a Pull Request, you agree to release your changes under this license.

Contributors

dafny-vscode's People

Contributors

camrein avatar dependabot[bot] avatar fabianhauser avatar gorymoon avatar jamesbornholt avatar kailingp avatar markusschaden avatar misto avatar nhweston avatar pyrolitic avatar robin-aws avatar rustanleino avatar saltiniroberto avatar ssaavedra avatar valisstigma avatar wilcoxjay avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

dafny-vscode's Issues

Error: starting dafny client failed

I had Dafny working nicely in VS Code (on Mac OS X). Today, VS Code seems to have installed itself an upgrade, and now Dafny is no longer working. Specifically, I get the following error message:

[Error - 7:13:46 AM] Starting client failed
Error: spawn /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper.app/Contents/MacOS/Code Helper ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:232:19)
at onErrorNT (internal/child_process.js:407:16)
at process._tickCallback (internal/process/next_tick.js:63:19)

I tried running ./dafny_server from the command line, as suggested here and it seemed to be working fine.

Could somebody advise on next steps? Thanks!

Version: 1.39.0
Commit: 9df03c6d6ce97c6645c5846f6dfa2a6a7d276515
Date: 2019-10-09T06:57:43.593Z
Electron: 4.2.10
Chrome: 69.0.3497.128
Node.js: 10.11.0
V8: 6.9.427.31-electron.0
OS: Darwin x64 18.7.0

DafnyServer process quit unexpectedly; attempting restart

at VSCode startup DafnyServer process quit unexpectedly; attempting restart. after some seconds it says DafnyServer restart succeeded but it actually does not work and verifies everything by proof obligations:0.
F5 key for compile also does not print anything in OUTPUT

Link a recommended Dafny Server version to one version of the Dafny-VSCode plugin

Currently, the latest version of the Dafny Server is installed by this plugin. In case there is a new version of the Dafny Server, the user is prompted to perform an update.

Risk: The newest version of the Dafny Server may not work well with the current version of the Dafny-VScode plugin.

Solution: Link a recommended Dafny Server version to one version of the Dafny-VSCode plugin. Installation of another version should also be possible (for early adopters or testers).

Dafny compiler warnings appear to prevent Dafny program from running in VSCode

My Dafny program verifies, but when I try to "Compile and Run", I still get an error in VSCode, namely, "Errors compiling program into basic-dafny.exe." I debugged this a little by running the compiler in a terminal window in VSCode. Here's the output. You can see that the program does verify, but the compiler nevertheless reports "Errors compiling program into basic-dafny.exe. The "errors" that it then reports are really only warnings. That said, they're very cryptic warnings that appear to be coming from deep in the bowels of Dafny. I haven't yet figured out what they mean. The main problem here is that the Dafny VSCode plugin is interpreting Dafny's misleading error message as an indication that it's not possible to run the compiled program. But the program does compile, and can be run using "mono Dafny.exe /compile:3" at the command line. Maybe this is an error for the Dafny team. But your plug-in team should at least be aware of the issue. Close this out if it doesn't belong here. Here are the reported compiler errors.

====

OS = OSX High Sierra (10.13)
Plugin version = 0.10.10
Dafny version = Hard to tell, no obvious -version compiler option, but current as of January 2018

====

Dafny program verifier finished with 9 verified, 0 errors
Errors compiling program into basic-dafny.exe
/var/folders/5n/6hml8q9s39300wsyb2kb89b00000gn/T/4bcad2d0/5e25f480.0.cs(1792,19) : warning CS1718: A comparison made to same variable. Did you mean to compare something else?
/var/folders/5n/6hml8q9s39300wsyb2kb89b00000gn/T/4bcad2d0/5e25f480.0.cs(1854,7) : warning CS0162: Unreachable code detected

assert fails to respond to !false in the same way as if !false

Hi with the code below

function method palin(a:seq<int>) :bool {
    forall i:int :: (0<=i && i<(|a|/2)) ==> a[i]==a[|a|-i -1]
}
method Main() { 
    var xe:seq<int> := [0,1,2,3,0];
    var se:seq<int> := [0,1,2,1,0];
    var ohb := palin(se);
    var ohx :bool := palin(xe);
    print "ohb= ",ohb,"\n";
    print "ohx= ",ohx,"\n";
    assert ohb;
    //assert !ohx;    
}

when run the output is:

    ohb= true
    ohx= false

But uncommenting the final assert and it will not verify.
As the if statement knows that ohx is false I assume that the assert should also know this?
regards david

Causing ligatures to render incorrectly

Using MS's cascadia code font with ligatures enabled, this extension being enabled appears to influence how the ligatures render in .dfy files.

e.g. extension disabled
image

vs extension enabled
image

This is on MacOS Catalina 10.15
VS Code 1.39.2
Extension 0.17.1
Cascadia Code 1910.04
(latest versions of everything)

References not counted correctly

The plug-in inserts references counts before method and related definitions, but they are not accurate. I haven't determined all the details, but there's no question that in some cases, the plug-in is showing zero references when there are clearly references from other files in the same folder.

Autocomplete doesn't work on new install

I installed Dafny and VSCode from scratch. While Dafny itself seems to be functioning fine, the auto-complete fails with the following message.

[Error - 6:59:36 AM] Request textDocument/completion failed.
  Message: Request textDocument/completion failed with message: Cannot read property 'getText' of undefined
  Code: -32603 

The error repeats whenever I type '.' How can I start debugging this?
screen shot 2018-07-19 at 7 03 01 am

Network Timeout / Extension crash on offline usage

When trying to install extension offline without network, always fails!
OUTPUT

{ Error: connect ETIMEDOUT 140.82.118.5:443
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1113:14)
errno: 'ETIMEDOUT',
code: 'ETIMEDOUT',
syscall: 'connect',
address: '140.82.118.5',
port: 443 }
{ Error: connect ETIMEDOUT 140.82.118.5:443
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1113:14)
errno: 'ETIMEDOUT',
code: 'ETIMEDOUT',
syscall: 'connect',
address: '140.82.118.5',
port: 443 }
errrroooorrr: Error: connect ETIMEDOUT 140.82.118.5:443

Cannot find test module

Running the client tests with npm test from the /client directory fails with the following output:

> [email protected] test /Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client
> node ./node_modules/vscode/bin/test

### VS Code Extension Test Run ###
Current working directory: /Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client
Running extension tests: /Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/.vscode-test/Visual Studio Code.app/Contents/MacOS/Electron /Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/out/test --extensionDevelopmentPath=/Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client --extensionTestsPath=/Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/out/test
[main 13:04:23] update#setState idle

Error: Error: Cannot find module '/Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/out/test'
	at t.handleExtensionTests (/Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/.vscode-test/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:743:811)
	at /Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/.vscode-test/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:740:130
	at Object.g [as _notify] (/Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/.vscode-test/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:69:572)
	at Object.enter (/Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/.vscode-test/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:72:924)
	at n.Class.derive._oncancel._run (/Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/.vscode-test/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:74:719)
	at n.Class.derive._oncancel._completed (/Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/.vscode-test/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:74:160)
	at c (/Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/.vscode-test/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:77:654)
	at K.then.o.(anonymous function) (/Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/.vscode-test/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:77:868)
	at Object.g [as _notify] (/Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/.vscode-test/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:69:572)
	at Object.enter (/Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/.vscode-test/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:72:924)
	at n.Class.derive._oncancel._run (/Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/.vscode-test/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:74:719)
	at n.Class.derive._oncancel._completed (/Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/.vscode-test/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:74:160)
	at c (/Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/.vscode-test/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:77:654)
	at K.then.o.(anonymous function) (/Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/.vscode-test/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:77:868)
	at Object.g [as _notify] (/Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/.vscode-test/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:69:572)
	at Object.enter (/Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/.vscode-test/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:72:924)
	at n.Class.derive._oncancel._run (/Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/.vscode-test/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:74:719)
	at n.Class.derive._oncancel._completed (/Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/.vscode-test/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:74:160)
	at c (/Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/.vscode-test/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:77:654)
	at K.then.o.(anonymous function) (/Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/.vscode-test/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:77:868)
	at Object.g [as _notify] (/Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/.vscode-test/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:69:572)
	at Object.enter (/Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/.vscode-test/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:72:924)
	at n.Class.derive._oncancel._run (/Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/.vscode-test/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:74:719)
	at n.Class.derive._oncancel._completed (/Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/.vscode-test/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:74:160)
	at u (/Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/.vscode-test/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:79:741)
	at s (/Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/.vscode-test/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:79:645)
	at Object.g [as _notify] (/Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/.vscode-test/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:69:572)
	at Object.enter (/Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/.vscode-test/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:72:924)
	at n.Class.derive._oncancel._run (/Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/.vscode-test/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:74:719)
	at n.Class.derive._oncancel._completed (/Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/.vscode-test/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:74:160)
	at Object.g [as _notify] (/Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/.vscode-test/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:69:572)
	at Object.enter (/Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/.vscode-test/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:72:924)
	at n.Class.derive._oncancel._run (/Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/.vscode-test/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:74:719)
	at n.Class.derive._oncancel._completed (/Users/mariomeili/Desktop/Temp/VS-Code-Language-Server-for-Dafny/client/.vscode-test/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:74:160)
	at FSReqWrap.cb [as oncomplete] (fs.js:260:19)

Tests exited with code: 1
npm ERR! Test failed.  See above for more details.

All components were successfully built using the documentation in README.md.

Environment: macOS High Sierra 10.13.4

Plugin fails silently when mono not installed on Linux, old versions of mono don't work either

If mono is not installed (recent version of Ubuntu), the compiler will appear to run when one executes the compile-and-run script. No error is generated but of course the program doesn't run, and the compiler isn't working. Solution is to install mono.

In a related vein, a student had a linux machine on which mono had apparently been installed by default, but it was an old version and failed when asked to run the Dafny compiler. Some assemblies were missing.

Solution in both cases was install latest version of mono from mono site.

Plug-in should perhaps check non-Windows platforms for presence of compatible version of mono and issue error if not present.

Vscode extension does not install dafny correctly

Hi All,

I just installed the vscode extension on Ubuntu 16.04, when prompted if I wanted to install Dafny I got the following error message:

Could not get Dafny Release assets from JSON response.
errrroooorrr: Could not get Dafny Release assets from JSON response.
[Error - 4:14:19 pm] Request textDocument/codeLens failed.
  Message: Request textDocument/codeLens failed unexpectedly without providing any details.
  Code: -32603

Furthermore, when I enter in a DafnyServer.exe path incorrectly, the extension asks me if I would like to install dafny (as opposed to showing an error that the path is invalid/doesn't contain the server).

I managed to install it by downloading the release zip and entering the path myself, but I was just wondering if the extension was broken or if it didn't work on my system?

Thanks!

The Dafny Language Server server crashed 5 times in the last 3 minutes. The server will not be restarted.

Got this error when editing the code below.

Running Up to date VSCode and Dafny VSCode plugin 0.10.10 on up to date OSX.

========

Here's the output:

Error: Verification request failed of task: ${request}
at good.serverProc.stdin.write (/Users/sullivan/.vscode/extensions/FunctionalCorrectness.dafny-vscode-0.10.10/server/process/process.js:56:27)
at afterWrite (_stream_writable.js:383:3)
at onwrite (_stream_writable.js:374:7)
at WriteWrap.afterWrite [as oncomplete] (net.js:825:12)
[Error - 10:41:20] Connection to server got closed. Server will not be restarted.

=====

Here's the code (for imperative.dfy)

include "functional.dfy"

module imperative
{
/*
Allow use of definitions in functional
module without prefixes.
*/
import opened functional

/*
Here's a typical imperative program for 
computing the factorial function. It 
documents the specification it implements
in a comment akin to the "doc strings" that
one uses in Python programs to document the
specifications that procedures implement.
The problem with this code is that there
are no check that it actually does what
it says it does. In fact, it contains an
error. Read the program to see if you can
find the error before you look at the next
program in this file, in which the error is
corrected. You can see that there's a major
erroy by just test-running this program and
checking the output. It's clearly wrong.
*/
method factorial(n: nat) returns (f: nat) 
// For any n, return the factorial of n
{
    if (n == 0) 
    { 
        return 1;
    }
    var t: nat := n;
    var a: nat := 1;
    while (t !=  0)
    {
        a := a * n;
        t := t - 1;
    }
    return a;
}

/*
Here's an imperative program for computing factorial.
*/
method verified_factorial(n: nat) returns (f: nat) 
    ensures f == fact(n)
{
    // If base case, return result without recursion
    if (n == 0) 
    { 
        return 1;
    }

    // The rest of the code handles recursive case
    assert n > 0;

    /*
       Strategy: use a while loop to compute the
       answer. We can do this by using a variable,
       a, to hold a "partial factorial value" in
       the form of a product of the numbers from 
       n down to a loop index, "i," that we start
       at n and decrement down, terminating the
       loop when n==0. At each point just before,
       during, and right after the loop, a is a
       product of the numbers from n down to i, 
       and the value of i represents how much of
       this product-computing work remains to be
       done. So, for example, if we're computing
       factorial(10) and a holds the value 10 * 9,
       then i must be 8 because multiplying a by
       the factors from 8 down to 1 remains to be
       done. A critical "invariant" then is that
       if you multiply a by the factorial of i 
       you get the final answer, which is to say
       the factorial of n.  
    */

    /* 
       Step 1. Set up state for the loop to work.

       We first initializie a := 1 and i := n and
       check that the invariant holds. Note that
       we are using our pure functional math-like
       definition of fact as a *specification* of
       the factorial function we're implementing.
    */
    var i: nat := n;    // nat type of i explicit
    var a := 1;         // can let Dafny infer it

    /*
       In Dafny, we can use matnematical logic to
       express what must be true at any given point
       in the execution of a program in the form of
       an "assertion." Here we assert that our loop
       invariant holds. The Dafny verifier tries to
       prove that the assertion is a true propsition
       about the state of the program when control
       reaches this point in the execution of this
       program.
    */
    assert a * fact(i) == fact(n); // "invariant"


    /*
        Step 2: Now evaluate the loop to get the
        answer.

       To evaluate a loop, first, evaluate the 
       loop condition (i > 0).Then , if the result 
       is false, terminate the loop. Otherwise, 
       evaluate the loop body, then iterate (run 
       the loop again, starting by evaluating the
       loop condition).     
    */

    /*
       Note that we can deduce that the loop body
       is going to execute at least once. It will 
       run if i > 0. What is i? We initialized it
       to n and haven't change it since then so it
       must still be equal to n. Do we know that 
       n is greater than 0? We do, because (1) it
       can't be negative owning to its type, and 
       (2) it can't be 0 because if it were 0 the
       program would already have returned. But we
       can now do better than just reasoning in our
       heads; we can use logic to express what we
       believe to be true and let Dafny try to 
       check it for us automatically.
    */
    assert i > 0;
    
    /*
    Let's just think briefly about cases. We know
    i can't be zero. It could be one. If it's one,
    then the loop body will run. The loop body will
    run. a, which starts at 1, will be multiplied 
    by i, which is 1, then i will be decremented.
    It will have the value 0 and the loop will not
    run again, leaving a with the value 1, which 
    is the right answer. So, okay, let's run the
    loop.
    */
    
    while (i >  0)
        invariant 0 <= i <= n
        invariant fact(n) == a * fact(i) 
    {
        a := a * i;
        i := i - 1;
    }

    /*
       At this point, we know that the loop 
       condition is false. In English, we'd
       say it is no longer true that i is greater
       than zero." We can do better that saying
       this in natural language then forgetting
       it. We can use formal logic to formalize 
       and document our belief and if we do this
       then Dafny pays us well for our effort 
       by checking that our assertion is true. 
    */
    assert !(i > 0);

    /*
        We can also have Dafny check that our
        loop invariant still holds. 
    */
    assert a * fact(i) == fact(n);

    /*
        And now comes the most crucial step of 
        all in our reasoning. We can deduce that
        a now holds the correct answer. That this
        is so follows from the conjunction of the
        two assertions we just made. First, that
        i is not greater than 0 and given that its
        type is nat, the only possible value it
        can have now is 0. And that's what we'd
        expect, because that's the condition on
        which the loop terminates, which is just
        did! But better than just saying it, let
        us also formalize, document, and check it.
    */
    assert i == 0;

    /*
       Now it's easy to see. No matter what value
       i has, a * fact(i) == fact(n), and i == 0, so
       we have a * fact(0) == fact(n), and we know
       that fact(0) is 1 because we see that in the
       very mathematical definition of fact, so it
       must be that a = fact(n). Dafny can check!
     */
    assert a == fact(n);

    /*
        We thus have the answer we need to return.
        Dafny verifies that our program satisfies
        its formal specification. We no longer have
        to pray. We *know* that our program is right
        and Dafny confirms our belief.
    */
    return a;

    /*
        Mathematical logic is to software as the 
        calculus is to physics and engineering.
        It's not just an academic curiosity. It is
        a critical intellectual tool, inceasingly
        being used for precise for specification 
        and verification of practical programs.
    */
}

/*
Similarly, here an imperative implementation 
of the fibonacci function, without a spec.
*/
method fibonacci(n: nat) returns (r: nat)
{
    /*
        Represent values for two base cases.
    */
    var fib0, fib1 := 0, 1; //parallel assmt

    /*
       Return base case result if appropriate
    */
    if (n == 0) { return fib0; }
    if (n == 1) { return fib1; }

    /*
       At this point, we know n (a nat) >= 2.
    */
    assert n >= 2;

    /*
       Our strategy for computing fib(n) is
       to use a while loop with an index i.
       Our design will be based on the idea
       that at the beginning and end of each 
       loop iteration, that we have computed
       fib(i) and that its value is stored in
       fib1. Then within the loop body we'll 
       compute fib(i+1) and then increment i.

       At this point, we've already computed
       fib(0), stored in fib0, and and fib(1), 
       in fib1, so we should initialize i to 
       be 1. 
       
       We'll want to terminate the loop when 
       i == n, at which point fib1 should
       have the value fib(i), where i ==n,
       so fib(i) will be fib(n). That is the
       strategy. So let's go.
    */
    var i := 1;

    /*
        We can state and Dafny can verify a
        number of conditions that we expect
        and require to hold at this point.
    */
    assert fib1 == fib(i);
    assert fib0 == fib(i-1);
    assert i <= n;


    /*
        Here's the loop. We can be sure it will
        run at least once, because at this point
        n must be greater than or equal to 2 ...
    */
    assert n >= 2;
    /*
        and we know that i is 1, and 1 < 2, which
        satisfies the loop condition. If n were to
        be equal to 2, the loop body would run, the
        value of fib2 would be set to the sum of 
        the current values of fib1 and fib0, giving
        us fib2; then fib0 will be set to the current
        value of fib1, fib1 will be set of the value
        of fib2, and i will be incremented, at which
        point the critical condition will be restored: 
        fib1 == fib(i), but where i is now equal to 2.
        We also know that i started off less than n,
        it gets incremented by only 1 each time the
        loop body executes, and the loop terminates
        when it is no longer true that i < n. So it
        remains true at all times that i <= n. For
        Dafny to be able to verify that a loop does
        what it's meant to do, we have to declare 
        the invariants that are required to hold.
    */
    while (i < n) 
        invariant i <= n;
        invariant fib0 == fib(i-1);
        invariant fib1 == fib(i);
    {
        var fib2 := fib0 + fib1;
        fib0 := fib1;
        fib1 := fib2;
        i := i + 1;
    }
    /*
        So we know that every iteration of the loop
        body has preserved the condition that fib1 is
        equal to fib(i). What else do we know? Well,
        a little bit of logical reasoning leads us to
        conclude that i == n. Combining these facts
        then leads to the final result: fib1==fib(n)
    */
    assert i <= n;      // invariant
    assert !(i < n);    // loop condition is false
    assert (i <= n) && !(i < n) ==> (i == n);
    assert i == n;      // deductive conclusion
    assert fib1 == fib(i); // invariant
    assert fib1 == fib(i) && (i==n) ==> fib1 == fib(n);
    assert fib1 == fib(n);

    /*
        We now have a proven-correct result!
    */
    return fib1;
}

method verified_fibonacci(n: nat) returns (r: nat)
    ensures r == fib(n)
/* a verified implementation goes here! */

}

====

Here's functional.dfy (which verifies separately)

module functional
{

/*
An "identity function" for values of type nat.
Returns whatever int value you pass to it. Note:
the body of a pure function is not sequential 
code operating on a memory, code but simply an 
expression that computes a desired return value. 

The "function method" declaration indicates two
things. First, the code will be written in a pure
functional style. Second, the code can be called
from imperative code. Dafny compiles "function 
methods" into executable code. Code declared to
be just a "function" in Dafny can be used in pre-
and post-conditions and in other specifications,
and so can be involved in verification, but such
functions are not compiled to executable code.
*/
function method id_int (x: int): int { x }


// Compute the successor of nat x. The type nat
// is the type of integers >= 0.
function method inc (x: int): int { x + 1 }


// Compute the square of a given int value
function method square (x: int): int { x * x }


/*
 Given an int x, compute square of its successor.
 This function is implemented as a *composition*
 of the inc and square functions. It works by first
 applying inc to its argument and then applying the
 square function to that result.
 */
function method h (x: int): int { square(inc(x)) }


/*
 Compute the factorial of any non-negative integer.
 While you might want to think of the factorial of a
 number n as the product of the numbers from 1 to n,
 that's not perfect because we want the function to be
 defined for all natural numbers, from 0 up; and you
 can't very well define it as the product of numbers
 from 0 to n, because that would always be just zero.
 A better definition is a recursive definition. It has
 two cases: factorial of zero is one, and factorial of
 any larger number, n, is n times the factorial of the
 next smaller number, n-1. When the next smaller number
 is zero, the result is 1 and the product is then the
 product of all numbers from 1 to n. Recursion gives
 us an extremely concise way of representing functions
 such as factorial. 
 */
function method fact(n: int): int 
    requires n >= 0
{ 
    if (n==0) then 1    // base case
    else n * fact(n-1)  // recursive case
}


/*
 The nat type is the type of non-negative
 integers. If we use this type, we can leave
 off the precondition, as it's already implicit
 in the nat type. We have to give our function
 a different name; and we're careful (now!) to
 make a recursive call to the new function, 
 fact', rather than to the old one!
 */

function method fact'(n: nat): nat
{
    if n == 0 then 1 
    else n * fact'(n-1)
}    


/*
This function computes the n'th Fibonacci
number, for any natural number, n. It directly
implements the recursive mathematical definition
of the function. The beauty of this code is 
that it's runnable math. The problem is that
it's terribly inefficient. In fact, it takes
time exponential in n. This program makes an
excellent specification, but a pretty lousy
implementation of the factorial function.
*/
function method fib(n: nat): nat
{
    if (n < 2) then n
    else fib(n-2) + fib(n-1)
}


/* 
Computes the sum of all of the integers from 
zero up to given non-negative integer, n. 
*/
function method sumto(n: nat): nat 
{
    if (n == 0) then 0 else n + sumto(n-1)
}

/*
Implements addition using recursive application
of increment-by-one. To add x and y, this function 
applies the increment (inc) function x times to y. 
The value of x is restricted to non-negative values 
so that the recursion is guaranteed to terminate.
Be sure you really understand this example.
*/
function method add(x:nat, y: nat): nat
{
    if (x==0) then y else inc(add(x-1, y))
}

/*
Implements exponentiation, computing m*n,
by recursive aplication of addition of n.
*/
function method mult(m: nat, n:nat): nat 
{
    if (m==0) then 0
    else add(n, mult(m-1,n))    
}

/*
Implements exponentiation, computing m^n,
by recursive application of our multiplation
function.
*/
function method exp(m: nat, n:nat): nat
{
if (n == 0) then 1
else mult(m, exp(m, n-1))
}

function method ev(n: nat): bool
{
    if n == 0 then true
    else if n == 1 then false 
    else ev (n-2)  
}

function method double(n: nat): nat{
    if n==0 then 0
    else 2 + double(n-1)
}

function method pred(n: nat): nat 
    requires n > 0
{
    n - 1
}

}

Dafny VSCode Plugin Uninstaller Hangs

Trying to narrow down the causes of the "Server Crashed 5 Times" bug (see other issue) I tried to uninstall the plug-in. What I got a was a hung uninstaller. Killing and restarting VSCode showed that the plugin is still installed. This is clearly a bug.

Dafny install fails on system with multiple volumes

My user directory is C:\users\jerick, but Dafny attempts to download to D:\users\jerick\

From the output console:

downloading:
 https://github.com/FunctionalCorrectness/dafny-microsoft/releases/download/v1.9.16/dafny-1.9.16-x64-win.zip
events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: ENOENT: no such file or directory, open 'd:\Users\jerick\dafny.zip'

When I manually downloaded that URL to "d:\Users\jerick\dafny.zip" the installation succeeded. However, the .dafny folder was also created at d:\Users\jerick.dafny, not c:\users\jerick.dafny

I think only HOMEPATH is being used, but HOMEDRIVE needs to be used as well.

$ set HOME
HOMEDRIVE=C:
HOMEPATH=\Users\jerick

Syntax highlighting different if predicate in parentheses.

It appears that syntax highlighting for "ensures" uses a different color if the predicate that follows is in parentheses.

Here is a screenshot:

Image

This behaviour is also observed for "requires", "invariant", and "decreases".

Best regards,
Farhad.

Attempting to verify any sufficiently long file causes VS Code to think the server has crashed

Opening any sufficiently large Dafny file causes the language server to believe DafnyServer has crashed. On my machine, files longer than about 12KB trigger the bug.

I believe this is due to incorrect processing of writeable.write's return value in the language server. When write returns false, it means that the internal buffer is full, not that a failure has occurred. So no exceptions should be thrown in this case.

Error highlighting state not updating correctly after fixes to code

I haven't ascertained all the details, but it's clear that in some cases, error indications (in the form of red squiggly underlines) in the IDE are not being updated properly when problems are fixed in code in other files. Even when the compiler runs successfully, error indicators sometimes remain. The one way I've found to clear them is to exit and restart the IDE.

TypeError: Cannot read property 'fileName' of undefined

As I work away in the Dafny VSCode extension, on pretty simple files, I repeatedly get the following error message. I am posting this issue now and will update it as I gain more insight into conditions that lead to this error.

OS = OSX High Sierra (10.13)
Plugin version = 0.10.10
Dafny version = Hard to tell, no obvious -version compiler option, but current as of January 2018

TypeError: Cannot read property 'fileName' of undefined
at symbolTables.find (/Users/sullivan/.vscode/extensions/FunctionalCorrectness.dafny-vscode-0.10.10/server/backend/features/baseCodeLensProvider.js:15:54)
at Array.find (native)
at server.symbolService.getSymbols.then (/Users/sullivan/.vscode/extensions/FunctionalCorrectness.dafny-vscode-0.10.10/server/backend/features/baseCodeLensProvider.js:15:33)
at

Automatic Counter Example Quits DafnyServer

Hi
Running Macos 10.14.6. Loaded VSCode and Dafny all worked well for some hours. Next day restarted VSCode and opened Dafny file. but server not found so I went to SETTINGs and added the _Absolute path to the DafnyServer.exe binary and then the file was automatically checked. But alas now two error messages keep flashing
DafnyServer process quit unexpectedly; ..
Restart succeeded
any ideas?

Not sure if its relevant but have a warning Please use a workspace (File or Folder) ..

Allow to customize parameters passed to verify in DafnyServer

It would be great to be able to configure at the editor's settings.json the parameters that are passed to DafnyServer on verify.

Currently this is implemented on server/backend/dafny/dafnyServer.js as:

    sendVerificationRequest(request) {
        if (request.verb === stringRessources_1.DafnyVerbs.CounterExample || request.verb === stringRessources_1.DafnyVerbs.Verify) {
            this.statusbar.changeServerStatus(stringRessources_1.StatusString.Verifying);
        }
        const task = {
            args: [],
            filename: vscode_uri_1.default.parse(request.document.uri).fsPath,
            source: request.source,
            sourceIsFile: false,
        };

I'm manually changing on the extension code the args: [], in my case to add args: ['/vcsLoad:1'], but it would be great if that was exported to be user-configurable.

Stale "has errors" status

The error reported here is actually due to the activation of a slight "design problem" in the language. Closing this issue and posting an issue for the root cause separately.

VSCode seems to think that a file that just verified (see bottom of screen) has errors (red underline where the file is included). Note: the "Request document text/completion" is a different VSCode problem reported under a different issue.

screen shot 2018-02-10 at 11 43 22

VSCode fix incorrectly inserts computed decreases

On the code below, Dafny extension for VSCode proposes a fix to insert the decreases es,unit on method OptimizeAndFilter, but it inserts it between List and instead of after List.

datatype List<T> = Nil | Cons(head: T, tail: List<T>)
datatype Op = Add | Mul
datatype Expr = Const(nat)
              | Var(string)
              | Node(op: Op, args: List<Expr>)

function method Unit(op: Op): nat {
    match op case Add => 0 case Mul => 1
}

function method Optimize(e : Expr): Expr decreases  e
 {
    if e.Node? then
        var args := OptimizeAndFilter(e.args, Unit(e.op));
        Shorten(e.op, args)
    else
        e
}

function method Shorten(op: Op, args: List<Expr>): Expr {
    match args
    case Nil => Const(Unit(op))
    case Cons(e, Nil) => e
    case Cons(_, Cons(_, _)) => Node(op, args)
}

function method OptimizeAndFilter(es: List<Expr>,
                                  unit: nat): List<Expr>
{
    match es
    case Nil => Nil
    case Cons(e, tail) =>
        var e', tail' := Optimize(e), OptimizeAndFilter(tail, unit);
        if e' == Const(unit) then tail' else Cons(e', tail')
}

Rename monoPath configuration option

Currently, the configuration option for a custom mono installation is called dafny.monoPath, which is confusing, as it requires the path and filename to mono and not only the path.

I suggest to rename it to dafny.monoExecutable and update the "README.md"-description.
Note that the old configuration option should still work as fallback.

Support multiple files in a project

Hi,

I'm trying to use the extension on a Dafny project with multiple files, but it appears that verification is only done on a single file and inter-file dependencies lead to errors.

Did I miss something or Dafny-VSCode doesn't support multiple file workspaces yet? Is it possible to add support for that?

This is a fork

Hi,
Original author of https://github.com/ferry-/dafny-vscode here. While you have expanded my work to include many more features, you did not start off from scratch. Your git log even shows my commits
https://github.com/DafnyVSCode/Dafny-VSCode/commits/develop?after=ad2bd9e62133cb619eda1879431104b748b0ca55+420 at the very beginning, which you included into this repository without my permission.
You are not crediting me anywhere. The MIT license on my repo explicitly sets out "The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software." This is largely a matter of principle but you should include my name at least in the copyright notice of this project.

VSCode plug-in shows incorrect server status after server crash

See previous issue about server crashing 5 times and not restarting. It appears that the server will not restart, even when commanded to. Even so, the VSCode status bar at the bottom of the screen shows a status of "Server Up." Fixing the problem requires a restart of VS Code, but if whatever problem in the code caused the crash hasn't been fixed, the thing will just crash again, continuing to show "Server up" status.

Uninstall script in 0.9.0 has illegal newline.

Hi

It looks like the uninstall script in 0.9.0 does not work under MacOSx due to a wrong new-line Character.

bash: /Users/fm/.vscode/extensions/FunctionalCorrectness.dafny-vscode-0.9.0/scripts/osx/uninstall.sh: /bin/bash^M: bad interpreter: No such file or directory

This error seems to crop up again and again. Would there be a way to eliminate it systematically? e.g. A script that does this conversion for the appropriate OS before an install?

Best regards,
Farhad Mehta

"Request textDocument/codeLens failed."

[Error - 4:36:48 PM] Request textDocument/codeLens failed.
Error: Connection got disposed.
    at Object.dispose (/Users/skainswo/.vscode-insiders/extensions/correctnesslab.dafny-vscode-0.16.0/node_modules/vscode-jsonrpc/lib/main.js:825:25)
    at Object.dispose (/Users/skainswo/.vscode-insiders/extensions/correctnesslab.dafny-vscode-0.16.0/node_modules/vscode-languageclient/lib/client.js:57:35)
    at DafnyLanguageClient.handleConnectionClosed (/Users/skainswo/.vscode-insiders/extensions/correctnesslab.dafny-vscode-0.16.0/node_modules/vscode-languageclient/lib/client.js:1864:38)
    at DafnyLanguageClient.handleConnectionClosed (/Users/skainswo/.vscode-insiders/extensions/correctnesslab.dafny-vscode-0.16.0/node_modules/vscode-languageclient/lib/main.js:106:15)
    at closeHandler (/Users/skainswo/.vscode-insiders/extensions/correctnesslab.dafny-vscode-0.16.0/node_modules/vscode-languageclient/lib/client.js:1852:18)
    at CallbackList.invoke (/Users/skainswo/.vscode-insiders/extensions/correctnesslab.dafny-vscode-0.16.0/node_modules/vscode-jsonrpc/lib/events.js:71:39)
    at Emitter.fire (/Users/skainswo/.vscode-insiders/extensions/correctnesslab.dafny-vscode-0.16.0/node_modules/vscode-jsonrpc/lib/events.js:135:36)
    at closeHandler (/Users/skainswo/.vscode-insiders/extensions/correctnesslab.dafny-vscode-0.16.0/node_modules/vscode-jsonrpc/lib/main.js:221:26)
    at CallbackList.invoke (/Users/skainswo/.vscode-insiders/extensions/correctnesslab.dafny-vscode-0.16.0/node_modules/vscode-jsonrpc/lib/events.js:71:39)
    at Emitter.fire (/Users/skainswo/.vscode-insiders/extensions/correctnesslab.dafny-vscode-0.16.0/node_modules/vscode-jsonrpc/lib/events.js:135:36)
    at IPCMessageReader.AbstractMessageReader.fireClose (/Users/skainswo/.vscode-insiders/extensions/correctnesslab.dafny-vscode-0.16.0/node_modules/vscode-jsonrpc/lib/messageReader.js:135:27)
    at ChildProcess.<anonymous> (/Users/skainswo/.vscode-insiders/extensions/correctnesslab.dafny-vscode-0.16.0/node_modules/vscode-jsonrpc/lib/messageReader.js:253:61)
    at ChildProcess.emit (events.js:187:15)
    at maybeClose (internal/child_process.js:961:16)
    at Socket.ChildProcess.spawn.stream.socket.on (internal/child_process.js:380:11)
    at Socket.emit (events.js:182:13)
    at Pipe.Socket._destroy._handle.close [as _onclose] (net.js:596:12)

I'm on macOS 10.14.2, VSCode Version 1.33.0-insider (1.33.0-insider), and correctnesslab.dafny-vscode 0.16.0.

Request textDocument/definition failed.

This shows up in the output of the Dafny Language Server:

[Error - 4:11:21 PM] Request textDocument/definition failed.
  Message: Request textDocument/definition failed with message: Cannot read property 'then' of null
  Code: -32603 

Sidebar status doesn't update

Hey,

cool extension.
However my sidebar state never changes to 'Verified' or 'Not Verified'. It remains 'Verifying'.

More informative warning in case a file, and not a workspace is opened.

Hello,

Currently, a user who opens a single file, and not a workspace gets the following warning:

"Warn: Please use a workspace (File - Open Folder). Otherwise some features aren't working properly"

Please modify this warning to be more informative. E.g.:

"Warn: Open a workspace (File - Open Folder) instead of single files in order to XXX. More details can be found in XXX"

Thanks,
Farhad

Extension deletes files irrecoverably

A student reported to me about a week ago that he had created a file of class notes and that it simply disappeared on him. I did't disbelieve him, but I also couldn't confirm that it was due to a fault in the plug-in. Now I can.

I just saw it myself. After working for several hours in the IDE (unfortunately without a commit), I got a "server failed 5 times and won't restart" error, which I've seen many times, but then immediately after that I got a "file not found, do you want to create it?" error. The file had been opened in a tab in the IDE. Now it was gone.

There's no question but that the IDE deleted the file, and it seems unrecoverable, as the file is not in my trashcan (on OSX). The file that was deleted was not the file I was working on at the moment the errors occurred.

This just cost me several hours of work. Clearly a bug like this is a "must fix" before this plug-in can be considered viable for broader use.

Standalone language server

I would like to have Dafny support in an editor that supports the LSP (Kakoune). The language server that is developed here seems to only work under VS Code. How can I have a standalone server executable from this codebase? Is it even possible? Thanks!

More relevant error message in case .Net environment not installed

At the moment, in case the user wishes to use the plugin on a computer without the .Net framework, an error message pops up to the effect of "Dafny server not installed". It would be a good idea to first check if the .Net framework is currently installed, and if not, display a message that reflects this and advises the user what to do.

Reported by Markus Stolze

Key not found

I get the following error message from the Dafny Language Server.

key not found 
[Error - 7:54:41 PM] Request codeLens/resolve failed.
  Message: Could not resolve CodeLens: Key not Found
  Code: 9903

image

I'm not sure if this is a bug or just noise.

This is happening on both Windows and Mac with version 0.17.1. My VSCode version on the Mac is 1.41.1 and on Windows it's also 1.41.1.

Dafny installation not working properly on MacOS

When installing the plugin in VSCode, a message indicates that in order for the plugin to work, Dafny has to be installed. When accepting the prompt to install, VSCode starts the installation. Then, after an apparently successful installation, the prompt reappears.

VSCode should report Dafny version and output

As a help to understanding/debugging problems with VSCode or Dafny, VSCode should make visible (1) the version of the Dafny executable being run and (2) the output that dafny produces (from which VSCode scrapes the problems/warnings/info). An easier and clearer mechanism to change the dafny executable would also be helpful.

Multi-line information not shown

The plug-in shows informational messages both in the "Problems" pane and as green underlines in the source text. However, when this information from Dafny has several lines, the actual multi-line message is replaced by "Dafny VSCode".

Repro:

class {:autocontracts} MyClass {
}

This highlight "MyClass", but each of the three messages just says "autocontracts: Dafny VSCode". When running Dafny on the command line, these tool tips show as follows:

$ dafny /printTooltips MyClass.dfy
Dafny 2.2.0.10923
MyClass.dfy(1,23): Info: autocontracts:
   ghost var Repr: set<object?>
MyClass.dfy(1,23): Info: autocontracts:
   predicate Valid()
     reads this, Repr
MyClass.dfy(1,23): Info: autocontracts:
   this in Repr && null !in Repr

Dafny program verifier finished with 1 verified, 0 errors

Rustan

Counterexamples not shown

The dafny.showCounterExample command seems to have no effect. This has been noticed after updating to version 0.11.1 of the plugin and version 2.1.1 of the Dafny server.

OS: MacOS 10.13.4

"& was unexpected at this time" error in compile and run (F5)

When I try to "Compile and Run" a Dafny program in VS Code (F5 button), there is an error in the run command.

The command that appears in the terminal is:
& "c:\Users\admin\short\d\a.exe"

The error following is:
& was unexpected at this time.

The code compiles fine and if I run the same command without & it executes properly.

How to recreate:

  1. Write a Dafny program that compiles
  2. Press F5 (scope needs to be in editor and not terminal)

Dafny Extension version: 0.17.0
VSCode info:

Version: 1.34.0 (system setup)
Commit: a622c65b2c713c890fcf4fbf07cf34049d5fe758
Date: 2019-05-15T21:59:37.030Z
Electron: 3.1.8
Chrome: 66.0.3359.181
Node.js: 10.2.0
V8: 6.6.346.32
OS: Windows_NT x64 6.1.7601

Fix Deprecated VSCode-API Calls

Currently, multiple deprecation messages are shown:

Extension 'correctnessLab.dafny-vscode' uses a document selector without scheme. Learn more about this: https://go.microsoft.com/fwlink/?linkid=872305
Extension 'correctnessLab.dafny-vscode' uses the 'vscode.previewHtml' command which is deprecated and will be removed. Please update your extension to use the Webview API: https://go.microsoft.com/fwlink/?linkid=2039309

These calls should be fixed according to the Microsoft documentation.

Dafny-VSCode doesn't connect to language server under Linux

I just tried the extension on Windows yesterday, and it installed a Dafny distribution and was up and running as soon as it finished downloading --- brilliant!

Under Linux today, I'm not having such luck. I installed the extension itself without issue, and was prompted to install Dafny upon opening a dfy file. I clicked yes, it seemed to download as expected... then asked me again if I wanted to install Dafny. (I can click Yes, it will download again, then ask again; I've repeated this process several times now since I first encountered the general issues below just to see if it would fix things, to no avail.)

If I try to compile a file, I get:

Can't compile: The Server was not ready to handle the client request

Waiting 10 minutes doesn't affect anything, so I assume this is not some weird slow-startup issue.

I've restarted Visual Studio Code, and attempted to restart the language server through the extension, several times each without success.

After installation it does set the Dafny Base Path to /home/csgordon/.vscode/extensions/correctnesslab.dafny-vscode-0.17.1/dafny/dafny, which appears to contain the expected contents of a Dafny distribution. For good measure I've tried with and without manually setting the path to mono (version 4.6.2), which seems to make no difference.

It doesn't appear that the language server itself is actually running:

/home/csgordon> ps aux | grep -i dafny
csgordon 23276  0.0  0.2 566804 68312 ?        Sl   09:33   0:00 /usr/share/code/code /home/csgordon/.vscode/extensions/correctnesslab.dafny-vscode-0.17.1/node_modules/vscode-languageclient/lib/utils/electronForkStart /home/csgordon/.vscode/extensions/correctnesslab.dafny-vscode-0.17.1/server/server.js --node-ipc --clientProcessId=23240
csgordon 24612  0.0  0.0  14428  1068 pts/1    S+   09:41   0:00 /bin/grep -i dafny

if I'm correctly interpreting process 23276 above as the extension itself.

The output in the Visual Studio Code UI for Dafny Language Server is just a periodically-updated string of:

[Error - 9:34:01 AM] Request textDocument/codeLens failed.
  Message: Request textDocument/codeLens failed unexpectedly without providing any details.
  Code: -32603 
[Error - 9:38:41 AM] Request textDocument/codeLens failed.
  Message: Request textDocument/codeLens failed unexpectedly without providing any details.
  Code: -32603 
[Error - 9:39:55 AM] Request textDocument/codeLens failed.
  Message: Request textDocument/codeLens failed unexpectedly without providing any details.
  Code: -32603 
[Error - 9:39:56 AM] Request textDocument/codeLens failed.
  Message: Request textDocument/codeLens failed unexpectedly without providing any details.
  Code: -32603 
[Error - 9:39:59 AM] Request textDocument/codeLens failed.
  Message: Request textDocument/codeLens failed unexpectedly without providing any details.
  Code: -32603 
[Error - 9:40:01 AM] Request textDocument/codeLens failed.
  Message: Request textDocument/codeLens failed unexpectedly without providing any details.
  Code: -32603 
[Error - 9:40:02 AM] Request textDocument/codeLens failed.
  Message: Request textDocument/codeLens failed unexpectedly without providing any details.
  Code: -32603 
[Error - 9:40:03 AM] Request textDocument/codeLens failed.
  Message: Request textDocument/codeLens failed unexpectedly without providing any details.
  Code: -32603 
[Error - 9:40:06 AM] Request textDocument/codeLens failed.
  Message: Request textDocument/codeLens failed unexpectedly without providing any details.
  Code: -32603 
[Error - 9:40:32 AM] Request textDocument/codeLens failed.
  Message: Request textDocument/codeLens failed unexpectedly without providing any details.
  Code: -32603 
[Error - 9:40:33 AM] Request textDocument/codeLens failed.
  Message: Request textDocument/codeLens failed unexpectedly without providing any details.
  Code: -32603 

I'm not aware of any other places to look for relevant logs, but I'm happy to provide them if there's somewhere I should look.

I'm running Linux Mint (an Ubuntu derivative) 19.1, with Visual Studio Code 1.36.1, and Mono 4.6.2 (technically an Ubuntu tweak on a Debian tweak, version 4.6.2.7+dfsg-1ubuntu1 in the Ubuntu derivative repositories).

The configuration for my machine is pretty much a stock install, with the exception of the default shell being PowerShell rather than bash, so if the default shell matters that could be an issue, though I haven't observed problems with other vscode extensions that launch external programs (e.g., LaTeX extensions). Bash is still available on my system, though, so the dafny and dafny-server scripts that start with #!/usr/bin/env bash should still run fine once invoked.

VS code Dafny broken - will no longer install

Dafny-VScode will no longer install. On MacOS at least, it stops at 4% "Extracting Dafny" with the following error - Seems related to #29. With no option to specify a different Dafny, there's no way to get a working system, or get back a working system after agreeing to an "upgrade".

Extracting files...
Error extracting /Users/kjx/.vscode/extensions/correctnesslab.dafny-vscode-0.17.2/dafny.zip: Error: Unsupported file type "undefined"
Error: Unsupported file type "undefined"
at DecompressZip.extractFile (/Users/kjx/.vscode/extensions/correctnesslab.dafny-vscode-0.17.2/server/node_modules/decompress-zip/lib/decompress-zip.js:320:11)
at /Users/kjx/.vscode/extensions/correctnesslab.dafny-vscode-0.17.2/server/node_modules/decompress-zip/lib/decompress-zip.js:253:28
at Array.forEach ()
at DecompressZip.extractFiles (/Users/kjx/.vscode/extensions/correctnesslab.dafny-vscode-0.17.2/server/node_modules/decompress-zip/lib/decompress-zip.js:252:11)
at /Users/kjx/.vscode/extensions/correctnesslab.dafny-vscode-0.17.2/server/node_modules/decompress-zip/lib/decompress-zip.js:132:21
at _fulfilled (/Users/kjx/.vscode/extensions/correctnesslab.dafny-vscode-0.17.2/server/node_modules/q/q.js:854:54)
at /Users/kjx/.vscode/extensions/correctnesslab.dafny-vscode-0.17.2/server/node_modules/q/q.js:883:30
at Promise.promise.promiseDispatch (/Users/kjx/.vscode/extensions/correctnesslab.dafny-vscode-0.17.2/server/node_modules/q/q.js:816:13)
at /Users/kjx/.vscode/extensions/correctnesslab.dafny-vscode-0.17.2/server/node_modules/q/q.js:624:44
at runSingle (/Users/kjx/.vscode/extensions/correctnesslab.dafny-vscode-0.17.2/server/node_modules/q/q.js:137:13)
errrroooorrr: Error: Unsupported file type "undefined"

Request textDocument/completion failed.

As I'm working along on a few pretty simple Dafny files in the VS Code extension, I repeatedly get the following error. I am posting here to document the issue, and will update this issue as I gain insight into the conditions that lead to this error.

OS = OSX High Sierra (10.13)
Plugin version = 0.10.10
Dafny version = Hard to tell, no obvious -version compiler option, but current as of January 2018

[Error - 13:14:26] Request textDocument/completion failed.
Message: Request textDocument/completion failed with message: Cannot read property 'getText' of undefined
Code: -32603

Dafny for VSCode times out as "idle" instead of failing verification

Per request from @RustanLeino, I am creating this issue in this repo.

The dafny-lang/dafny repo received the following issue: dafny-lang/dafny#415

Upon investigation, it appears the submitted code times out on the command line but goes from "Verifying" to "Idle" in VSCode without noting the timeout/failure.

Please see the linked issue for more information/ discussion.

The original request was as follows:

We are two students who are using Dafny for the first time and was trying to prove union-find when we ran into weird behavior. Dafny verified some very odd asserts and we could even assert false. We removed as much as possible from the code, but we can in this program, ensure false in main without any requires or assume. We wouldn't think this could happen no matter what code we wrote outside of main but couldn't find any errors either.

class Main {
  method main()
  ensures false;
  {
    var n := new Node;
    n.parent := 0;
    n.lengthToRoot := 0;
    n.root := 0;
    var G := new Node[1](_ => n);
    unite(G, 0, 0);
  }

  predicate graph(G: array<Node>)
    reads G, set i: nat | i < G.Length :: G[i]
  { (forall i: nat :: i < G.Length ==> (
      (G[i].parent < G.Length) &&
      (G[i].lengthToRoot == 0 <==> G[i].parent == i) &&
      (G[i].lengthToRoot > 0 ==> G[G[i].parent].lengthToRoot < G[i].lengthToRoot) &&
      (G[i].lengthToRoot == 0 <==> G[i].root == i) &&
      (G[i].root == G[G[i].parent].root)
    )) &&
    forall i: nat, j: nat :: i < j < G.Length ==> G[i] != G[j]
  }

  method Find(G: array<Node>, a: nat) returns (res: nat)
    requires a < G.Length
    requires graph(G)
    ensures graph(G)

    modifies G, set i: nat | i < G.Length :: G[i]
    decreases G[a].lengthToRoot

    ensures res == G[a].root

    ensures res < G.Length
    ensures G[res].lengthToRoot == 0
    ensures G[res].parent == res
    ensures forall i: nat :: i < G.Length ==> old(G[i].lengthToRoot) == G[i].lengthToRoot
    ensures forall i: nat :: i < G.Length ==> old(G[i]) == G[i]
    ensures forall i: nat :: i < G.Length ==> old(G[i].root) == G[i].root
  {
    if G[a].parent != a {
      G[a].parent := Find(G, G[a].parent);
    }
    return G[a].parent;
  }

  method unite(G: array<Node>, a: nat, b: nat) 
    requires a < G.Length
    requires b < G.Length
    requires graph(G)
    ensures G[a].root == G[b].root;
    ensures G[a].root != G[b].root;
    modifies G, set i: nat | i < G.Length :: G[i]
  {
    var rootA := Find(G, a);
    var rootB := Find(G, b);
  }
}

class Node {
  var parent: nat;
  ghost var lengthToRoot: nat;
  ghost var root: nat;
}

And investigation from @robin-aws showed:

I was able to produce the spurious verification in VSCode. The toolbar at the bottom goes from "Verifying" to "Idle" on this file, taking about 10-15 seconds, and only gives a couple of undecipherable warnings (copy and pasted below):

{
	"resource": "/Users/salkeldr/Documents/GitHub/dafny/Test/git-issues/git-issue-415.dfy",
	"owner": "_generated_diagnostic_collection_name_#0",
	"severity": 2,
	"message": "For expression \"(i < G.Length ==> G[i].parent < G.Length) && (i < G.Length ==> (G[i].lengthToRoot == 0 <==> G[i].parent == i)) && (i < G.Length ==> (G[i].lengthToRoot == 0 <==> G[i].root == i))\":",
	"source": "Dafny VSCode",
	"startLineNumber": 15,
	"startColumn": 5,
	"endLineNumber": 15,
	"endColumn": 1.7976931348623157e+308
}

{
	"resource": "/Users/salkeldr/Documents/GitHub/dafny/Test/git-issues/git-issue-415.dfy",
	"owner": "_generated_diagnostic_collection_name_#0",
	"severity": 2,
	"message": "For expression \"(i < G.Length ==> G[i].lengthToRoot > 0 ==> G[G[i].parent].lengthToRoot < G[i].lengthToRoot) && (i < G.Length ==> G[i].root == G[G[i].parent].root)\":",
	"source": "Dafny VSCode",
	"startLineNumber": 15,
	"startColumn": 5,
	"endLineNumber": 15,
	"endColumn": 1.7976931348623157e+308
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.