Skip to content

Add motoko.lite setting to disable the language server - #474

Merged
Kamirus merged 4 commits into
masterfrom
motoko-lite-mode
Sep 9, 2026
Merged

Add motoko.lite setting to disable the language server#474
Kamirus merged 4 commits into
masterfrom
motoko-lite-mode

Conversation

@Kamirus

@Kamirus Kamirus commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes the "heavy compute + memory" experience of the Motoko extension by letting users opt out of the language server entirely via a new per-workspace motoko.lite setting (default false).

The extension currently boots a full language server that embeds the bundled moc.js WASM compiler (~8MB once bundled) and type-checks every open/entry-point .mo on each edit. We don't have time to slim that down, so this PR exposes the cheap alternative: skip the server at activation and keep only the features that don't depend on it.

Key insight

Syntax highlighting never came from the server — it's the TextMate grammar registered purely via contributes.grammars. So disabling the server keeps highlighting, snippets, and dfx.json schema validation (the built-in JSON validator) while dropping everything that needs the compiler/typed AST. Note that formatting is not kept: it is also server-provided (connection.onDocumentFormatting), so in lite mode format-on-save / Format Document is disabled along with the rest.

What changes in lite mode

Keeps working (client-side, ~zero cost):

  • Syntax highlighting (TextMate grammar)
  • Snippets
  • dfx.json schema validation (built-in JSON validator)

Disabled (all server-dependent):

  • Diagnostics / type checking
  • Completions (incl. contextual-dot)
  • Hover with types & docs
  • Go to definition, workspace symbols
  • Signature help
  • References / rename / prepare-rename
  • Code actions (organize imports, import quick-fixes)
  • Formatting (format-on-save / Format Document)
  • "Import Mops Package" command

Memory/compute win: the language server never starts, so the motoko npm package + moc.js WASM compiler never load into the extension host. No workspace scan for Mops/Vessel/dfx, no check queue, no typed-AST reparse loop.

Implementation

  • package.json: new motoko.lite setting (boolean, scope resource, default false); version bumped 0.23.6 → 0.24.0
  • src/extension.ts: early-return in activate() when lite is on; Motoko: Restart language server becomes a no-op with an explanatory message instead of silently failing
  • src/extension.ts: in lite mode, a single line is written to a Motoko log channel (Output → Extension Logs → Motoko, also persisted to disk) so users who set and forgot motoko.lite can find why features are missing. The channel is only created in the lite branch — zero footprint in normal mode.
  • README.md: documents lite mode, including the workspace/user scope semantics and that formatter settings only apply while the server runs

Takes effect on window reload (documented). No server-side changes.

Verification

  • npm run compile
  • npm run lint ✅ (zero warnings)
  • npm test ✅ 24 suites / 276 tests all pass
  • Reviewed via a fix-review loop; no critical or warning findings remain
  • Manual runtime check with the setting enabled is still needed from a dev window.

🤖 Generated with Claude Code

Kamirus and others added 4 commits September 9, 2026 15:44
The extension boots a full language server that embeds the moc.js WASM
compiler (~8MB bundled) and type-checks every open .mo file on each edit,
which is heavy in both compute and memory. While we can't slim that down,
we can let users opt out of it.

Add a per-workspace `motoko.lite` setting (default false) that skips the
language server entirely at activation: startup skips the eager compiler
context, the Mops/Vessel/dfx workspace scan, and the typed-AST reparse
loop, so the compiler never loads into the extension host. Lightweight
features that don't depend on the server keep working - syntax
highlighting (TextMate grammar), prettier formatting, snippets, and dfx.json
schema validation. The `Motoko: Restart language server` command becomes a
no-op with an explanatory message instead of silently failing.

Disables in lite mode: diagnostics/type checking, completions, hover,
go to definition, references/rename, code actions, signature help,
workspace symbols, and the Import Mops Package command.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Lite mode was completely silent: the "Motoko Language Server" output
channel never exists (the server never starts) and console output would
vanish into the shared Extension Host channel. A user who set
motoko.lite and forgot would have no signal why half the extension was
dead.

Add a Motoko log channel (created only in the lite branch) and write a
single line when lite mode activates. It appears under Output ->
Extension Logs -> Motoko and persists to the Extension Logs folder, so a
confused user can find it. Regular mode creates nothing, so there is no
footprint.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Review found that every 'formatting keeps working in lite mode' claim was
wrong: formatting is only provided via connection.onDocumentFormatting in
the language server (src/server/handlers.ts), and there is no client-side
document formatting provider. So with the server skipped, 'Format
Document' / format-on-save is disabled too.

Align the copy (package.json description, README setting docs, the lite
log line and code comment): formatting moves to the disabled list, and
the kept-working list is syntax highlighting, snippets, and dfx.json
schema validation. Also note in the README that motoko.lite is
workspace-scoped, so a user-level setting has no effect.

Co-Authored-By: Claude Code <noreply@anthropic.com>
The re-review flagged two doc issues:

- The note claiming a user/remote-level motoko.lite 'has no effect' was
  wrong: resource-scoped settings are settable at every level, so a
  user-level value takes effect globally. Reword to say how to opt in
  everywhere vs. per-workspace.
- Advanced Configuration's formatOnSave/defaultFormatter only works while
  the language server runs; cross-reference lite mode so users following
  both sections aren't surprised by a silent stop.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@Kamirus
Kamirus merged commit 6c5998b into master Sep 9, 2026
4 checks passed
@Kamirus
Kamirus deleted the motoko-lite-mode branch September 9, 2026 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant