pschanely / crosshair-vscode

Use crosshair to statically analyze Python code from within VS Code.
MIT License
6 stars 0 forks source link
contract contract-testing hacktoberfest python vscode vscode-extension

crosshair-vscode

Crosshair-vscode is an extension for Visual Studio Code (VS Code) that allows you to statically test your Python code using CrossHair.

Installation

Crosshair-vscode has two dependencies:

ms-python.python. Use the Visual Studio marketplace to install the extension ms-python.python by following this link.

crosshair-tool. The easiest way to install the crosshair-tool and pygls packages is to open the terminal tab and run pip3:

pip3 install crosshair-tool pygls

These packages must be installed in each Python environment that you wish to use. (the environment is displayed and can be changed in the status bar)

crosshair-vscode. Use the Visual Studio marketplace to install the extension by following this link.

Usage

The extension can be accessed from the status bar. When editing Python files, you'll see a new item labeled "CH off" (or "CH on" if the background watcher is already running).

status bar item

Click on this item to open a menu and perform various commands.

crosshair menu

Most importantly, you'll want to start the background watcher; by default, it does not auto-start. Once started, CrossHair will attempt to detect contract counterexamples in the background. When it finds something, you'll see it highlighted like this:

example crosshair error

NOTE: To reduce wasteful computation, the background watcher only checks contracts in files that are open. You may decide to leave some files open to ensure some contracts continue to be checked as you work.

If you want to be even more targeted by just checking an individual file, use the "watch in terminal" command.

Commands

The extension defines the following commands:

Settings

Search your VSCode settings for "crosshair" to see the options that you can configure. Here, you can do things like set project-specific contract types (icontract vs asserts) and change whether the background watcher automatically starts.

Known Issues

It is hard to control terminals in VS Code (see this issue). We wait for a short delay (~1 second) till we send commands to the terminal. This might cause racing conditions in some rare cases.

Contributing

Please see [CONTRIBUTING.md] for how to help us with development of the extension.

Credits

This plugin was authored by Marko Ristin and is now maintained by Phillip Schanely.

Versioning

We follow a bit unusual semantic versioning schema:

Release Notes

0.0.1

Initial release of crosshair-vscode.

0.0.2

CrossHair now runs transparently in the background and highlights counterexamples directly in your code, just like a typechecker or linter would. You can stop or start CrossHair in the status bar. Some of the more specialized check commands have been removed, as background execution is the recommended way to use CrossHair.

0.2.0

A non-pre-release release of 0.0.2; there are no changes. (We're moving to the VSCode recommendation of using even minor version numbers for release versions)

0.2.1

Removes the possibility for leaked CrossHair workers when closing the editor window without explicitly stopping the background runner.