This extension adds support for an older version of Lean, Lean 3. It is succeeded by vscode-lean4 (also called Lean 4
in the extensions menu) for Lean 4. If you want to use Lean 4, you cannot use this extension and must instead use vscode-lean4.
We currently support a variety of features. For basic VS Code editor features, see the VS Code User Interface docs.
- Automatic installation of Lean 3 via elan
- Incremental compilation and checking via the Lean 3 server
- Hover shows documentation, types, and Unicode input help:
-
Here's an example from the Lean 3 tutorials project:
-
Holding down ctrl will display the declaration as well:
-
- Auto-completion based on context and type via the Lean 3 server
- Error messages / diagnostics
- Batch file execution
- Tasks for
leanpkg
(ctrl+shift+p and select "Tasks: Configure Task") - Search for declarations in open files (ctrl+t or ctrl+p
#
) - Region of interest checking (i.e. control how much of the project is checked automatically by Lean 3)
- Customizable Unicode input support (e.g. type
\la
+tab to inputλ
) - Fill in
{! !}
holes (also_
holes in Lean 3.16.0c and later) with the code actions menu (ctrl+.) - Tactic suggestions (tactics which suggest edits with a "Try this:" message) can be applied either with a keyboard shortcut (alt+v), by clicking on the info view message, or via code actions (ctrl+.)
The info view panel is essential to working interactively with Lean 3. It shows:
- tactic state widgets, with context information (hypotheses, goals) at each point in a proof / definition,
- (in Lean 3.15.0c and newer) "expected type" widgets display the context for subterms.
- (in Lean 3.15.0c and newer) the types of subterms in the context can be inspected interactively.
- the "All Messages" widget, which shows all info, warning, and error messages from the Lean 3 server, and
- (in Lean 3.15.0c and newer) other custom widgets can be rendered in the info view.
(1) - (9) below refer to the labels in the screenshot above.
The icons labeled (2) - (6) and (9) - (10) appear at the top of each tactic state widget.
-
The info view will activate automatically when a Lean 3 file is opened, but you can also click at the top right of the editor window or hit the keybind for the
lean.displayGoal
(ctrl+shift+enter by default) to reopen it. -
Copy-to-comment: click to copy the contents of the widget to a comment in the editor:
-
Pin / unpin: click to split off a "pinned" tactic state widget, which tracks the tactic state at a fixed position, even if you move your cursor away:
Some new icons appear:
-
Pause / continue: clicking will prevent the tactic state widget from updating when the file is edited. Click to resume updates.
-
Update: clicking will refresh the tactic state of the pinned widget.
-
Suggest: clicking will activate api-based suggestions. The API url and key for these suggestions can be configured through options
lean.suggestionURL
andlean.suggestionAPIKey
. -
(Lean 3.15.0c and newer) Types in the context can be examined in the tactic state widget by clicking on the subterms:
The subterms that appear in the popup are buttons; click on them to inspect their types:
-
The "All Messages" widget can be expanded by clicking on it (or hitting the keybind for
lean.displayList
, ctrl+alt+shift+enter by default) -
Widget / plain text selection: For Lean 3 versions older than Lean 3.15.0c, the tactic state is displayed as a non-interactive string. For newer versions of Lean 3, the widget mode (with features described in (6)) is used by default. This dropdown menu allows selecting between the two.
-
Tactic state filter: the hypotheses in the tactic state can be filtered, with options on whether the tactic state is being displayed as a widget or in plain text (see (8)).
-
In widget mode, the allowed filters are built into Lean 3. Currently you can choose to filter out instances or data, by selecting "no instances" or "only props", respectively.
-
In plain text mode, you can add or edit the regex-based filters by using the option
lean.infoViewTacticStateFilters
. See the description below. The two filters included by default are:- "hide
/^_/
", which filters out all hypotheses which begin with an underscore_
(typically, instances) and - "goals only", which hides all hypotheses and only displays the goal lines.
- "hide
The book "Theorem Proving in Lean" can be read by hitting ctrl+shift+p and searching for "Lean: Open Documentation View".
Any Lean 3 project with an html/
folder can be displayed in this panel. For example, try out the book Mathematics in Lean.
This extension requires an installation of Lean 3. As of version 0.12.1, the extension can install Lean 3 for you using elan.
On Windows, if you installed Lean 3 using MSYS2, you need to add both C:\msys64\mingw64\bin
(or wherever you installed MSYS2) and C:\projects\lean\bin
(or wherever you installed Lean 3) to the system PATH
environment variable. To do this, press Win+Pause > go to Advanced System Settings > go to Environment variables. Under system variables (not user variables) find the Path
variable, and add these two folders.
This extension contributes the following settings (for a complete list, open the VS Code Settings and scroll to "Lean configuration"):
-
lean.executablePath
: controls which Lean 3 executable is used when starting the server. Most users (i.e. those usingelan
) should not ever need to change this. If you are bundling Lean 3 andvscode-lean
with Portable mode VS Code, you might find it useful to specify a relative path to Lean 3. This can be done by starting this setting string with%extensionPath%
; the extension will replace this with the absolute path of the extension folder. For example, with the default directory setup in Portable mode,%extensionPath%/../../../lean
will point tolean
in the same folder as the VS Code executable / application. -
lean.leanpkgPath
: controls which leanpkg executable is used forleanpkg
task integration. The%extensionPath%
token can be used here as well. As above, if you are usingelan
, this should never need to be changed. -
lean.extraOptions
: an array of additional command-line options to pass tolean
(e.g.--old
in Lean 3.10.0c or later, which allows Lean 3 to use out-of-date.olean
s.) -
lean.timeLimit
: controls the-T
flag passed to the Lean 3 executable -
lean.memoryLimit
: controls the-M
flag passed to the Lean 3 executable -
lean.roiModeDefault
: controls the default region of interest, the options are:nothing
: check nothingvisible
: check only visible fileslinesAndAbove
: check visible lines and aboveopen
: check all open filesproject
: check the entire project's files
-
lean.input.eagerReplacementEnabled
: enables/disables eager replacement as soon as the abbreviation is unique (true
by default) -
lean.input.leader
: character to type to trigger Unicode input mode (\
by default) -
lean.input.languages
: allows the Unicode input functionality to be used in other languages -
lean.input.customTranslations
: add additional input Unicode translations. Example:{"foo": "☺"}
will correct\foo
to☺
(assuming thelean.input.leader
has its default value\
). -
lean.typesInCompletionList
: controls whether the types of all items in the list of completions are displayed. By default, only the type of the highlighted item is shown.
-
lean.infoViewAutoOpen
: controls whether the info view is automatically displayed when the Lean 3 extension is activated (true
by default). -
lean.infoViewTacticStateFilters
: An array of objects containing regular expression strings that can be used to filter (positively or negatively) the plain text tactic state in the info view. Set to an empty array[]
to hide the filter select dropdown. Each object must contain the following keys:regex
is a properly-escaped regex string,match
is a boolean, wheretrue
(false
) means blocks in the tactic state matchingregex
will be included (excluded) in the info view,flags
are additional flags passed to the JavaScript RegExp constructor.- The
name
key is optional and may contain a string that is displayed in the dropdown instead of the full regex details.
-
lean.suggestionURL
URL to the API endpoint, accepting POST JSON requests containing a dictionary with two fields:tactic_state
andprefix
. The answer is expected to be a JSON dictionary containing a fieldtactic_infos
with a list of dictionaries containing a keytactic
. -
lean.suggestionAPIKey
The API key passed through to the API via the x-api-key header in the request.
This extension also contributes the following commands, which can be bound to keys if desired.
The format below is: "lean.commandName
(command name): description", where lean.commandName
represents the name used in settings.json
and "command name" is the name found in the command palette (accessed by hitting ctrl+shift+p).
-
lean.restartServer
(Lean: Restart): restart the Language Server. Useful if the server crashes or if you fetched new.olean
files using leanproject. -
lean.roiMode.select
(Lean: Select Region-of-interest): select the region of interest (files to be checked by the Lean 3 server).The choices can also be made directly:
-
lean.roiMode.nothing
(Lean: Check Nothing): disable automatic checking of Lean code. -
lean.roiMode.visibleFiles
(Lean: Check Visible Files): automatically check all files that are visible. -
lean.roiMode.linesAndAbove
(Lean: Check visible lines and above): automatically check all visible lines and lines above them. -
lean.roiMode.openFiles
(Lean: Check Open Files): automatically check all opened files. -
lean.roiMode.projectFiles
(Lean: Check Project Files): automatically check all files in the workspace.
-
-
lean.batchExecute
(Lean: Batch Execute File): execute the current file using Lean (bound to ctrl+shift+r by default)
-
lean.input.convert
(Lean: Input: Convert Current Abbreviation): converts the current Unicode abbreviation (bound to tab by default) -
lean.pasteTacticSuggestion
: if any tactic suggestions (i.e. tactics which return a "Try this:" in their output) are active for the code under the cursor, apply the first suggested edit. (bound to alt+v by defaullt)
-
lean.displayGoal
(Lean: Info View: Display Goal): open the info view panel (bound to ctrl+shift+enter by default) -
lean.displayList
(Lean: Info View: Toggle "All Messages"): toggles the "All messages" widget in the info view (bound to ctrl+alt+shift+enter by default) -
lean.infoView.copyToComment
(Lean: Info View: Copy Contents to Comment): copy the contents of the currently active tactic state widget into a new comment on the previous line (same as clicking on the icon) -
lean.infoView.toggleStickyPosition
(Lean: Info View: Toggle Pin): enable / disable "sticky" mode. On enable, a tactic state widget will be created and pinned to this position, reporting the goal from this point even as the cursor moves and edits are made to the file. On disable the pinned widget will be removed. (same as clicking on the or icon on the tactic state widget closest to the cursor.) -
lean.infoView.toggleUpdating
(Lean: Info View: Toggle Updating): pause / continue live updates of the main (unpinned) tactic state widget (same as clicking on the or icon on the main tactic state widget.)
lean.openDocView
(Lean: Open Documentation View): open documentation panel. See above.
-
Fonts with good Unicode support:
"editor.fontFamily": "Source Code Pro Medium, DejaVu Sans Mono"
. Note that for this configuration to work properly, both fonts must be specified in this order (so that characters that are not available in Source Code Pro are rendered using DejaVu Sans Mono). -
By default, VS Code will complete
then
tohas_bind.and_then
when you press enter. To disable this behavior, set"editor.acceptSuggestionOnEnter": false
. -
VSCode now colors bracket pairs by default. If you don't like that, untick the "Bracket Pair Colorization" checkbox in the settings (or equivalently set
"editor.bracketPairColorization.enabled": false
).
- Install
npm
(and for Ubuntu 17.04nodejs-legacy
) - Install
code
from http://code.visualstudio.com - Run
git clone https://github.com/leanprover/vscode-lean
- Run
npm install
in thevscode-lean
directory - Install the ESLint extension for vscode
- Install the Webpack Problem Matcher extension for vscode
- Open the
vscode-lean
directory in VS Code and start developing (F5 starts the debugger)
- Improved Lean input mode. The
lean.input.convertWithNewline
command has been removed. Abbreviations are now converted eagerly; this can be disabled with thelean.input.eagerReplacementEnabled
option. - Both the Lean 3 and Lean 4 extension can be installed at the same time now.
- Info view redesign: tactic state and messages are now combined in one window. Multiple positions can be pinned. Types in the tactic state widget can be expanded by clicking on them (when using Lean 3.15.0c and newer)!
- "sticky" mode for the infoview position
- Command to apply tactic suggestions such as from
library_search
(using alt+v or clicking "Try this:" in the info view)
- Show type of term under cursor in status bar
- Info view opens automatically
- Dropdown to filter tactic states
- Dropped support for Lean versions older than 3.1.0.
- Automated
elan
installation
- Tactic state highlighting
- Support for
visibleRanges
API in vscode. Per default, only the currently visible lines and the rest of the file above are checked.
- Updated syntax highlighting.
- New configuration option for extra command-line arguments. (
lean.extraOptions
) - Integration with
leanpkg
.
- Extremely improved info view (ctrl+shift+enter)
- Only show commands acting on Lean files when a Lean file is open in the current editor
- Hole support
- Info view showing the current goal and error messages.
- Search command (ctrl+p
#
) - Improved Unicode input.
- New input mode for Unicode symbols.
- Internally uses new client library to interact with the Lean server.
- Fixes issue with highlighting commands beginning with
#
.
- Support for controlling the "region of interest", i.e. which files are considered by the Lean server for checking and recompilation.
- Miscellaneous improvements to the grammar, and syntax highlighting
- Initial support for recording Lean server errors, and an option for displaying them upon crash.
- Support for more bracket pairs including many Unicode options.
- Properly set working directory when executing in batch mode.
- Configuration for controlling default region of interest.
- Use
semver
for detecting and comparing versions. - Fix issue where diagnostics were not cleared on server restart.
Add support for detecting Lean server versions.
Add support for time and memory limits.
Consider angle brackets and parenthesis when completing Unicode symbols.
Bug fixes, stability, and a handful of feature improvements
Implement many features implemented by the EMACS mode. We now support:
- Hovering over names for type information
- Go-to-definition & peeking for constants
- Goal support, with the ability to display the goal at the current position.
- Basic auto-completion support
- Diagnostics support, displaying errors, information & warnings.
Add basic integration with the Lean server.
Initial release of the package.
Please report issues on Github. Questions can also be asked on the Lean prover community Zulip chat.