Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,14 @@ Below are the default key bindings for commonly used features supported in the e
- `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.

```json
{
"[motoko]": {
Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-motoko",
"displayName": "Motoko",
"description": "Motoko language support",
"version": "0.23.6",
"version": "0.24.0",
"publisher": "dfinity-foundation",
"repository": "https://github.com/caffeinelabs/vscode-motoko",
"engines": {
Expand Down Expand Up @@ -125,6 +125,12 @@
"type": "string",
"default": "",
"description": "Path to moc.js file for using a custom Motoko version (absolute, or relative to workspace root). Only load moc.js files from trusted sources."
},
"motoko.lite": {
"scope": "resource",
"type": "boolean",
"default": false,
"description": "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. Keeps syntax highlighting, snippets, and dfx.json schema validation. See the README 'motoko.lite' setting for details. Takes effect after reloading the window."
}
}
},
Expand Down
25 changes: 25 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,31 @@ import { ignoreGlobPatterns, watchGlob } from './common/watchConfig';
let client: LanguageClient;

export function activate(context: ExtensionContext) {
// Lite mode: skip the language server entirely (and everything that depends
// on it) to reduce memory and CPU usage. Keeps syntax highlighting,
// snippets, and dfx.json schema validation, since those don't come from
// the server. Formatting is also server-provided, so it's disabled too.
const lite = workspace.getConfiguration('motoko').get<boolean>('lite');
if (lite) {
// Log channel is only created in lite mode, so regular mode has zero
// footprint. Since there is no language server in lite mode, this
// single entry is the only place users can see that the setting is on.
const liteLogger = window.createOutputChannel('Motoko', {
log: true,
});
liteLogger.appendLine(
`Motoko lite mode is ON (motoko.lite): the language server is disabled, so type checking, completions, hover, go to definition, references/rename, code actions, signature help, workspace symbols, formatting, and the "Import Mops Package" command are unavailable. Syntax highlighting, snippets, and dfx.json schema validation keep working. Set "motoko.lite" to false and reload the window to re-enable the language server.`,
);
context.subscriptions.push(
liteLogger,
commands.registerCommand('motoko.startService', () =>
window.showInformationMessage(
'Motoko lite mode is on: the language server is disabled. Turn off "motoko.lite" to enable type checking, completions, hover, and navigation.',
),
),
);
return;
}
context.subscriptions.push(
commands.registerCommand('motoko.startService', () =>
startServer(context),
Expand Down