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

Experiment: Viper integration #78

Draft
wants to merge 100 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
0c99de9
Viper integration progress
rvanasa Oct 17, 2022
e796c87
Progress
rvanasa Oct 17, 2022
2b0ac87
Merge branch 'master' into viper
rvanasa Oct 17, 2022
5e67dd6
Add Viper as an extension dependency
rvanasa Oct 17, 2022
7ca8087
Merge branch 'viper' of https://github.com/dfinity/vscode-motoko into…
rvanasa Oct 17, 2022
fe96390
Add '-viper' suffix to extension version
rvanasa Oct 17, 2022
1076303
Optimize and clarify type checking
rvanasa Oct 17, 2022
50820c3
Add generated 'moc.js' file to gitignore
rvanasa Oct 17, 2022
cbab556
Add boilerplate for Viper LSP errors + source mapping
rvanasa Oct 20, 2022
8342646
Implement verification RPC calls
rvanasa Oct 20, 2022
3058bb3
Checkpoint: receiving diagnostics from StateChange notifications
rvanasa Oct 20, 2022
3cfc5bc
Add basic Motoko diagnostics from Viper LSP
rvanasa Oct 21, 2022
e18a93d
Add 'View in context' link from Motoko -> Viper diagnostics
rvanasa Oct 21, 2022
f519db6
Adjust diagnostic source messages
rvanasa Oct 21, 2022
aa0cfec
Update build script to account for z3 dependency
rvanasa Oct 21, 2022
f027fca
Misc
rvanasa Oct 21, 2022
2a519f2
Add 'implies' and 'invariant' to syntax highlighting
rvanasa Oct 21, 2022
fab6719
Fix initial setup process in package.json
rvanasa Oct 21, 2022
5c2b5cf
Fix
rvanasa Oct 21, 2022
494c2ab
// @viper -> // @verify
rvanasa Oct 21, 2022
ca5fd04
Only insert Viper code into '*.vpr' files
rvanasa Oct 21, 2022
31720e0
Rewrite verification error messages
rvanasa Oct 21, 2022
b98d69e
Improve unknown range handling
rvanasa Oct 21, 2022
3e5beed
Hide unused Viper LS message types
rvanasa Oct 21, 2022
4734df0
Add provisional success diagnostic
rvanasa Oct 21, 2022
12a4ea9
Change error message (lifting error information from Viper)
rvanasa Oct 22, 2022
be5321f
Misc fixes from code review
rvanasa Oct 22, 2022
2a82fa2
Merge branch 'viper' of https://github.com/dfinity/vscode-motoko into…
rvanasa Oct 22, 2022
0a490b3
Run 'npm audit fix'
rvanasa Oct 22, 2022
ca64a28
Fix verification success corner case
rvanasa Oct 23, 2022
36c88ef
tweaks (#80)
ggreif Oct 23, 2022
09ab3a8
Use '*.mo.vpr' file endings
rvanasa Oct 23, 2022
f3020e4
Improve verification success diagnostic
rvanasa Oct 23, 2022
2b3a960
Merge branch 'viper' of https://github.com/dfinity/vscode-motoko into…
rvanasa Oct 23, 2022
10d7fdf
Improve verification success detection
rvanasa Oct 23, 2022
6d38483
Switch RPC 'Verify' request to notification
rvanasa Oct 23, 2022
05863c4
Merge branch 'master' of https://github.com/dfinity/vscode-motoko int…
rvanasa Oct 23, 2022
95f22ca
Add icon for Motoko files
rvanasa Oct 23, 2022
4115385
Merge branch 'master' into viper
rvanasa Oct 23, 2022
4fab05b
Merge branch 'master' into viper
rvanasa Oct 23, 2022
dee8a27
remove premature invalidation
ggreif Oct 27, 2022
ea81dab
Disable workspace type-checking
rvanasa Oct 27, 2022
cad3795
LSP: wait till port is up and parse it (#86)
ggreif Nov 9, 2022
ca084b3
Look up Java home directory using viper-ide logic (#91)
rvanasa Nov 9, 2022
d7ee213
Merge branch 'master' of https://github.com/dfinity/vscode-motoko int…
rvanasa Nov 15, 2022
3ae85c4
Update marketplace details in package.json
rvanasa Nov 15, 2022
35ffeeb
Update readme for VS Marketplace
rvanasa Nov 15, 2022
c67e11c
Add TM for Formal Motoko (#87)
aterga Nov 15, 2022
2a01b69
Merge branch 'viper' of https://github.com/dfinity/vscode-motoko into…
rvanasa Nov 15, 2022
a514d30
Remove custom 'Formal Motoko' theme in favor of using light/dark them…
rvanasa Nov 15, 2022
6c82368
Update package-lock.json
rvanasa Nov 15, 2022
14f5805
Set 'MOC_UNLOCK_VERIFICATION' environment variable for moc.js
rvanasa Nov 15, 2022
867e624
some version bumps (#97)
ggreif Nov 18, 2022
f6f1bc2
chore: set up a `motoko` submodule (#98)
ggreif Nov 18, 2022
fec8d16
Replace tsc with esbuild bundler
rvanasa Nov 18, 2022
f26d1a2
Fix missing Wasm file for 'prettier-plugin-motoko'
rvanasa Nov 18, 2022
0eaea58
Fix .vscodeignore
rvanasa Nov 18, 2022
2b63a3c
simplify instructions
ggreif Nov 18, 2022
82bc022
Merge branch 'bundle-esbuild' into viper
rvanasa Nov 18, 2022
4445f11
Add missing dev-dependency
rvanasa Nov 18, 2022
1816b9e
Add 'node_modules' back into .vscodeignore
rvanasa Nov 18, 2022
d8e6e89
fix
ggreif Nov 18, 2022
7f7441e
Replace 'mkdir -p' with 'mkdirp' for Windows build support
rvanasa Nov 18, 2022
2062102
Merge branch 'master' of https://github.com/dfinity/vscode-motoko int…
rvanasa Nov 21, 2022
8ea25ba
Update readme
rvanasa Nov 21, 2022
b653fac
Add incompatibility prompt
rvanasa Nov 21, 2022
ecb80e0
Use custom syntax highlighting provided by Viper
rvanasa Nov 21, 2022
80e48c4
Add 'Background' section to readme
rvanasa Nov 21, 2022
b4a6caa
Temporarily rename extension to 'Formal Motoko'
rvanasa Nov 21, 2022
12b0854
Track debug launch configuration
rvanasa Nov 23, 2022
7419e39
First (#102)
aterga Nov 25, 2022
8779b86
Rename 'Formal Motoko' -> 'Motoko-san'
rvanasa Nov 25, 2022
b8548c4
chore: Viper is on Motoko `master` (#103)
ggreif Nov 26, 2022
dec28b3
v0.0.2
rvanasa Nov 25, 2022
008a6cd
Merge branch 'master' into viper
rvanasa Jan 4, 2023
c6b1eba
Misc. fixes
rvanasa Jan 4, 2023
e187a16
Merge remote-tracking branch 'origin/master' into viper
rvanasa Jan 4, 2023
aec67b0
Improve diagnostic behavior when opening/closing files
rvanasa Jan 4, 2023
015f176
Apply suggestions from code review
aterga Jan 4, 2023
b9d40af
Fix typo
aterga Jan 4, 2023
0f1180e
Update CI
rvanasa Jan 4, 2023
ed04f5b
Drop Node.js 14.x in CI
rvanasa Jan 4, 2023
b21008f
Deactivate test workflow for now (requires Nix installation)
rvanasa Jan 4, 2023
5dcd477
Explain CI blocker in comment
rvanasa Jan 4, 2023
62a59f8
track `motoko` ToT
ggreif Jan 5, 2023
acb9265
explain how to track the Motoko repo
ggreif Jan 5, 2023
d6d0279
tweak section
ggreif Jan 5, 2023
ccd6cc4
Bump 'vsce' to new package name
rvanasa Jan 5, 2023
dd5dd5b
Merge branch 'viper' of https://github.com/dfinity/vscode-motoko into…
rvanasa Jan 5, 2023
3c3b284
Merge
rvanasa Jan 5, 2023
d04f8fd
Tentatively re-enable test CI with Nix
rvanasa Jan 5, 2023
21ef478
Use Cachix action in CI (without auth token)
rvanasa Jan 5, 2023
ba913e1
Deactivate CI (#145)
rvanasa Jan 6, 2023
563e565
Bump dependencies
rvanasa Mar 17, 2023
0e5c9fe
Run formatter; organize imports
rvanasa Apr 10, 2023
9639874
Fix 'Restart language server' command
rvanasa Apr 10, 2023
18e50a2
0.0.3
rvanasa Apr 10, 2023
7f38803
Refactor
rvanasa Apr 10, 2023
9dbb92e
Add support for WSL (#198)
rvanasa Apr 11, 2023
e45ff0d
Draft: Fix minor issues to enable Serokell to use the IDE for local t…
aterga Jul 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Publish
run: |
npm install
Expand Down
15 changes: 14 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,36 @@ on:
pull_request:
branches: [ "master" ]

concurrency:
group: ${{ github.head_ref }}
cancel-in-progress: true

jobs:
build:
if: ${{ false }} # Deactivate this workflow

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x, 16.x]
node-version: [16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- uses: cachix/install-nix-action@v18
- uses: cachix/cachix-action@v12
with:
name: ic-hs-test
# authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- run: npm ci
- run: npm run generate
- run: npm run compile
- run: npm test
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "motoko"]
path = motoko
url = https://github.com/dfinity/motoko.git
branch = master
28 changes: 15 additions & 13 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
"outFiles": ["${workspaceFolder}/out/**/*.js"],
"preLaunchTask": "npm: compile"
}
]
}
"version": "0.2.0",
"configurations": [{
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"name": "Launch Extension",
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "npm: compile",
"request": "launch",
"type": "extensionHost"
}],
"compounds": []
}
2 changes: 2 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.github/**
.gitmodules
.gitignore
.vscode/**
motoko/**
.vessel/**
node_modules/**

Expand Down
130 changes: 46 additions & 84 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,111 +1,73 @@
# Motoko - VS Code Extension
> **Important note:** This is an experimental fork of the official [Motoko VS Code extension](https://marketplace.visualstudio.com/items?itemName=dfinity-foundation.vscode-motoko). Please disable the official extension if you run into any unexpected behavior.

> #### Motoko language support for [Visual Studio Code](https://code.visualstudio.com/).
# _Motoko-san_

[![Visual Studio Marketplace](https://img.shields.io/visual-studio-marketplace/v/dfinity-foundation.vscode-motoko?color=brightgreen&logo=visual-studio-code)](https://marketplace.visualstudio.com/items?itemName=dfinity-foundation.vscode-motoko)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/dfinity/prettier-plugin-motoko/issues)

## Overview

[Motoko](https://github.com/dfinity/motoko) is a high-level smart contract language for the [Internet Computer](https://internetcomputer.org/).

This extension provides syntax highlighting, type checking, and code formatting for [Motoko canister development](https://internetcomputer.org/docs/current/developer-docs/build/cdks/motoko-dfinity/motoko/).

## Features
> #### Experimental formal verification support for [Motoko](https://internetcomputer.org/docs/current/developer-docs/build/cdks/motoko-dfinity/motoko/).

- Syntax highlighting
- Code formatter
- Error checking
- Automatic imports
- Snippets ([contributions welcome](https://github.com/dfinity/node-motoko/blob/main/contrib/snippets.json))
- Go-to-definition
- Organize imports
- Documentation tooltips
[![Visual Studio Marketplace](https://img.shields.io/visual-studio-marketplace/v/dfinity-foundation.motoko-viper?color=brightgreen&logo=visual-studio-code)](https://marketplace.visualstudio.com/items?itemName=dfinity-foundation.motoko-viper)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/dfinity/prettier-plugin-motoko/issues)

## Installation
### Background

Get this extension through the [VS Marketplace](https://marketplace.visualstudio.com/items?itemName=dfinity-foundation.vscode-motoko), or alternatively the [Extensions panel](https://code.visualstudio.com/docs/editor/extension-marketplace) in your VS Code project.
[Motoko](https://internetcomputer.org/docs/current/developer-docs/build/cdks/motoko-dfinity/motoko/) is a high-level smart contract language for the [Internet Computer](https://internetcomputer.org/).

## Integrations
This extension makes it possible to write code specifications (such as actor-level invariants) for Motoko programs. The assertions are automatically checked, at compile time, by Viper [Viper](https://www.pm.inf.ethz.ch/research/viper.html), a formal verifier developed at ETH Zurich.

- [`dfx`](https://internetcomputer.org/docs/current/developer-docs/build/install-upgrade-remove/) (autocompletion, error checking, go-to-definition)
- [`prettier-plugin-motoko`](https://npmjs.com/package/prettier-plugin-motoko) (code formatter)
### Usage

## Extension Commands
To enable formal verification, insert `// @verify` at the top of your Motoko file.

- `Motoko: Restart language server`: Starts (or restarts) the language server
### Example

## Extension Settings
```motoko
// @verify

- `motoko.dfx`: The location of the `dfx` binary
- `motoko.canister`: The default canister name to use in multi-canister projects
- `motoko.formatter`: The formatter used by the extension
- `motoko.legacyDfxSupport`: Uses legacy `dfx`-dependent features when a relevant `dfx.json` file is available
actor {

## Advanced Configuration
var claimed = false;

If you want VS Code to automatically format Motoko files on save, consider adding the following to your `settings.json` configuration:
var count = 0 : Int;

```json
{
"[motoko]": {
"editor.defaultFormatter": "dfinity-foundation.vscode-motoko",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
}
}
```
assert:invariant count == 0 or count == 1;
assert:invariant not claimed implies count == 0;

## Recent Changes
public shared func claim() : async () {
if (not claimed) {
claimed := true;

Projects using `dfx >= 0.11.1` use a new, experimental language server.
await async {
assert:1:async (claimed and count == 0);
count += 1;
};
};
};

To continue using the original language server, you can modify your `dfx.json` file to use version `0.11.0` or earlier:

```json
{
"dfx": "0.11.0"
}
```

If you encounter any bugs, please [open a GitHub issue](https://github.com/dfinity/vscode-motoko/issues) with steps to reproduce so that we can fix the problem for everyone.

## Contributing

### Set up your local development environment:

Ensure that [Node.js >= 14.x](https://nodejs.org/en/) and [Cargo](https://doc.rust-lang.org/cargo/getting-started/installation.html) are installed on your system.

```bash
git clone https://github.com/dfinity/vscode-motoko
cd vscode-motoko
npm install
```

### Run unit tests:
### Building from Source

```bash
npm test
```

### Build the extension:
- Clone [vscode-motoko](https://github.com/dfinity/vscode-motoko/tree/viper) with
following command: `git clone https://github.com/dfinity/vscode-motoko -b viper --recurse-submodules`
- In your terminal, run `cd vscode-motoko`
- Install the `npm` modules needed as dependencies: `npm install`
- Run `npm run package` (this will rebuild the compiler bindings)
- Right-click the generated `/motoko-viper-*.vsix` file and select "Install extension VSIX"

```bash
npm run package
```
#### Tracking `dfinity/motoko`

This generates a file named `vscode-motoko-*.*.*.vsix` in the project root.
The submodule `motoko` usually tracks the `master` branch of the official Motoko repo
and needs periodical updates here to adjust the pin in order to absorb features and bugfixes.
Execute the following commands from toplevel to obtain updates:

### Install in VS Code:

```bash
code --install-extension vscode-motoko-*.*.*.vsix
``` shell
git branch --show-current
git submodule update --remote
git diff
git commit -am 'track `motoko` ToT'
git push
```

Alternatively, right-click the `.vsix` file and then select the "Install Extension VSIX" option.

---
### Further reading

Community [PRs](https://github.com/dfinity/vscode-motoko/pulls) are welcome! Be sure to check the list of [open issues](https://github.com/dfinity/vscode-motoko/issues) in case anything catches your eye.
A more detailed overview of _Motoko-san_ is available [here](https://github.com/dfinity/motoko/tree/master/src/viper).
1 change: 1 addition & 0 deletions motoko
Submodule motoko added at 2ff7dc
Loading