VS Code Integration (LSP)
Midwest ships a Language Server (LSP) that provides autocomplete and hover documentation for every component helper directly in your editor.
Features:
- Helper name completion — type
midwest_to see all available helpers - Option name completion — inside a call, get a list of every declared option with its type and default
- Option value completion — for options with enum values (e.g.
position:,size:,state:), values are completed automatically - Icon name completion —
:iconoptions are completed from the full icon list - Hover documentation — hover over any
midwest_*call to see a table of its options and slots
Prerequisites
- Node.js 18+
- VS Code 1.75+
- A Ruby/ERB extension installed in VS Code (e.g.
Ruby LSP
or vscode-ruby)
so that
.html.erbfiles are recognised with theerubylanguage ID.
Build the extension
The extension lives in the lsp/ directory of the Midwest gem repo.
cd path/to/midwest/lspnpm installnpm run compileThis compiles the TypeScript sources to lsp/out/.
Option A — Extension Development Host (recommended for development)
This opens a sandboxed VS Code window with the extension loaded. Changes to the source are picked up after a recompile.
- Open the
lsp/folder in VS Code:
code path/to/midwest/lsp- Press F5 (or Run → Start Debugging → Launch Extension).
A new Extension Development Host window opens.
In that window, open your Rails project (or the Midwest gem repo itself).
Open any
.rbor.html.erbfile and start typingmidwest_— completions will appear.
Tip: Run the "watch" build task (⇧⌘B → watch) so the server rebuilds automatically as you edit source files. The extension development host will pick up the new build on the next activation.
Option B — Permanent local install via symlink
This installs the extension into VS Code proper so it loads for every project without needing the development host.
# Build first (see above)cd path/to/midwest/lspnpm run compile# Symlink into the VS Code extensions directoryln -sf "$(pwd)" ~/.vscode/extensions/unabridged.midwest-lspRestart VS Code. The extension will activate automatically whenever you open a Ruby or ERB file.
To uninstall, delete the symlink:
rm ~/.vscode/extensions/unabridged.midwest-lspOption C — Install the pre-built VSIX from the repo
Every release includes a pre-built lsp/midwest-language-server.vsix committed
directly to the repo. You can install it without a build step:
code --install-extension path/to/midwest/lsp/midwest-language-server.vsixOr via the VS Code GUI: Extensions → ⋯ → Install from VSIX…
Restart VS Code after installing.
Option D — Build and install your own VSIX
Use this when you want to package a local, in-progress version of the extension.
cd path/to/midwest/lspnpm installnpm run package # compiles TypeScript, produces midwest-language-server.vsixInstall it:
code --install-extension midwest-language-server.vsixConfiguration
Open VS Code Settings (⌘,) and search for Midwest LSP.
| Setting | Default | Description |
|---|---|---|
midwestLsp.gemRoot |
"" |
Absolute path to the Midwest gem root. Leave empty to auto-detect from the workspace root. Useful when the gem is vendored or when working in a consuming Rails app. |
Example — explicitly point to a vendored gem:
{ "midwestLsp.gemRoot": "/Users/you/code/midwest"}Verifying it works
- Open a
.html.erbfile. - Type
<%= midwest_— an autocomplete list of all helpers should appear. - Select
midwest_bannerand continue typing(— option names should appear. - Hover over an existing
midwest_bannercall — a table of options and slots should appear.
If nothing appears, check the Output panel (⇧⌘U) and select Midwest ViewComponent from the dropdown to see server logs.
Debugging the server
The lsp/.vscode/launch.json includes a "Extension + Server" compound
launch configuration. This starts the extension and attaches the Node.js
debugger to port 6009 so you can set breakpoints in server.ts.