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.
Here's an example from the Lean 3 tutorials project:
Holding down ctrl will display the declaration as well:
leanpkg (ctrl+shift+p and select "Tasks: Configure Task")#)\la+tab to input λ){! !} holes (also _ holes in Lean 3.16.0c and later) with the code actions menu (ctrl+.)The info view panel is essential to working interactively with Lean 3. It shows:
(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:
will move the cursor in the editor to the pinned location in the file.
will remove the pinned widget from the info view.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 and lean.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:
/^_/", which filters out all hypotheses which begin with an underscore _ (typically, instances) andThe 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 using elan) should not ever need to change this. If you are bundling Lean 3 and vscode-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 to lean in the same folder as the VS Code executable / application.
lean.leanpkgPath: controls which leanpkg executable is used for leanpkg task integration. The %extensionPath% token can be used here as well. As above, if you are using elan, this should never need to be changed.
lean.extraOptions: an array of additional command-line options to pass to lean (e.g. --old in Lean 3.10.0c or later, which allows Lean 3 to use out-of-date .oleans.)
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 fileslean.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 the lean.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, where true (false) means blocks in the tactic state matching regex will be included (excluded) in the info view,flags are additional flags passed to the JavaScript RegExp constructor.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 and prefix. The answer is expected to be a JSON dictionary containing a field tactic_infos with a list of dictionaries containing a key tactic.
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).
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 to has_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).
npm (and for Ubuntu 17.04 nodejs-legacy)code from http://code.visualstudio.comgit clone https://github.com/leanprover/vscode-leannpm install in the vscode-lean directoryvscode-lean directory in VS Code and start developing (F5 starts the debugger)lean.input.convertWithNewline command has been removed. Abbreviations are now converted eagerly; this can be disabled with the lean.input.eagerReplacementEnabled option.library_search (using alt+v or clicking "Try this:" in the info view)elan installationvisibleRanges API in vscode. Per default, only the currently visible lines and the rest of the file above are checked.lean.extraOptions)leanpkg.#)#.semver for detecting and comparing versions.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:
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.
(top 30 of 37)
TypeScript
58.8%
CSS
38.5%
JavaScript
2.4%
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.
Here's an example from the Lean 3 tutorials project:
Holding down ctrl will display the declaration as well:
leanpkg (ctrl+shift+p and select "Tasks: Configure Task")#)\la+tab to input λ){! !} holes (also _ holes in Lean 3.16.0c and later) with the code actions menu (ctrl+.)The info view panel is essential to working interactively with Lean 3. It shows:
(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:
will move the cursor in the editor to the pinned location in the file.
will remove the pinned widget from the info view.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 and lean.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:
/^_/", which filters out all hypotheses which begin with an underscore _ (typically, instances) andThe 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 using elan) should not ever need to change this. If you are bundling Lean 3 and vscode-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 to lean in the same folder as the VS Code executable / application.
lean.leanpkgPath: controls which leanpkg executable is used for leanpkg task integration. The %extensionPath% token can be used here as well. As above, if you are using elan, this should never need to be changed.
lean.extraOptions: an array of additional command-line options to pass to lean (e.g. --old in Lean 3.10.0c or later, which allows Lean 3 to use out-of-date .oleans.)
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 fileslean.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 the lean.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, where true (false) means blocks in the tactic state matching regex will be included (excluded) in the info view,flags are additional flags passed to the JavaScript RegExp constructor.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 and prefix. The answer is expected to be a JSON dictionary containing a field tactic_infos with a list of dictionaries containing a key tactic.
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).
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 to has_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).
npm (and for Ubuntu 17.04 nodejs-legacy)code from http://code.visualstudio.comgit clone https://github.com/leanprover/vscode-leannpm install in the vscode-lean directoryvscode-lean directory in VS Code and start developing (F5 starts the debugger)lean.input.convertWithNewline command has been removed. Abbreviations are now converted eagerly; this can be disabled with the lean.input.eagerReplacementEnabled option.library_search (using alt+v or clicking "Try this:" in the info view)elan installationvisibleRanges API in vscode. Per default, only the currently visible lines and the rest of the file above are checked.lean.extraOptions)leanpkg.#)#.semver for detecting and comparing versions.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:
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.
(top 30 of 37)
TypeScript
58.8%
CSS
38.5%
JavaScript
2.4%