Skip to content

Latest commit

 

History

450 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Motoko · VS Code Extension

Motoko language support for Visual Studio Code.

Visual Studio Marketplace PRs Welcome

Overview

Motoko is a high-level smart contract language for the Internet Computer.

This IDE extension provides type checking, formatting, snippets, and more for Motoko canister development.

Showcase

Installation

Get this extension through the VS Marketplace, or alternatively the Extensions panel in your VS Code project.

VSCodium users can download the extension through Open VSX or the GitHub releases page.

Keyboard Shortcuts

Below are the default key bindings for commonly used features supported in the extension:

  • Code formatter (Shift + Alt + F): format a Motoko file using prettier-plugin-motoko.
  • Organize imports (Shift + Alt + O): group and sort imports at the top of your Motoko file.
  • Import code action (Ctrl/Cmd + . while hovering over an unresolved variable): show quick-fix options.
  • Go to definition (F12): jump to the definition of a local or imported identifier.
  • IntelliSense (Ctrl + Space): view all available autocompletions and code snippets.

Snippets

Other Features

  • Deploy to the Internet Computer mainnet using a right-click context menu action.
  • Mops and Vessel (the two most popular Motoko package managers) are supported out-of-the-box in this extension.
  • Quickly convert between Motoko types using code snippets such as array-2-buffer or principal-2-text.
  • In case you're hoping to learn Motoko without installing dfx, the Motoko VS Code extension works standalone on all major operating systems (including Windows).
  • This extension also provides schema validation and autocompletion for dfx.json config files.
  • View type information and documentation by hovering over function names, imports, and other expressions.

Tooltips

Commands

  • Motoko: Restart language server: Starts (or restarts) the language server
  • Motoko: Deploy (20 minutes): Temporarily deploys the currently open file to the Internet Computer
  • Motoko: Import Mops Package...: Search, install and import a package from Mops

Temporary deployment

Settings

  • 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 language server
  • motoko.mocJsPath: Path to moc.js file for using a custom Motoko version
  • motoko.lite: Light mode. Disables the language server (type checking, completions, hover, go to definition, references/rename, code actions, signature help, workspace symbols, format on save / format document, and the "Import Mops Package" command) to reduce memory and CPU usage. Syntax highlighting, snippets, and dfx.json schema validation keep working — those come from the TextMate grammar, the snippets contribution, and the built-in JSON validator, not from the language server. Set this (e.g. "motoko.lite": true) when you want a minimal, lightweight Motoko editing experience. It is resource-scoped, so you can set it in your user/remote settings to enable lite mode everywhere, or in a workspace/folder's .vscode/settings.json to enable it only for that project. It takes effect after reloading the window.

Advanced Configuration

If you want VS Code to automatically format Motoko files on save, consider adding the following to your settings.json configuration:

Note: these formatter settings only take effect when the language server is running. With motoko.lite enabled (see the motoko.lite setting above), format-on-save is disabled, since formatting is provided by the language server.

{
  "[motoko]": {
    "editor.defaultFormatter": "dfinity-foundation.vscode-motoko",
    "editor.formatOnSave": true,
    "editor.codeActionsOnSave": {
        "source.organizeImports": true
    }
  }
}

Contributing

Set up your local development environment:

Ensure that Node.js >= 24.x and Cargo are installed on your system.

git clone https://github.com/caffeinelabs/vscode-motoko
cd vscode-motoko
npm install

Run unit tests:

npm test

Build the extension:

npm run package

This generates a file named vscode-motoko-*.*.*.vsix in the project root.

Install in VS Code:

code --install-extension vscode-motoko-*.*.*.vsix

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


Community PRs are welcome! Be sure to check the list of open issues in case anything catches your eye.