Overview
EmmyLua Analyzer provides a powerful language server for Lua development in VS Code through the official EmmyLua extension. Get intelligent code completion, type checking, and advanced analysis features.Prerequisites:
- Visual Studio Code version 1.60 or higher
- EmmyLua Analyzer installed (
cargo install emmylua_ls)
Installation
Install EmmyLua Extension
Install the EmmyLua Extension from the VS Code Marketplace:
Configure Language Server Path
If you installed To find the installation path:
emmylua_ls via cargo, the extension should automatically detect it. Otherwise, specify the path in your settings:settings.json
Configuration
Workspace Settings
Configure EmmyLua in your workspace settings (.vscode/settings.json):
Runtime Version
Specify the Lua version for your project:Lua5.1, Lua5.2, Lua5.3, Lua5.4, LuaJIT, LuaLatest
Diagnostics Configuration
Customize diagnostic behavior:Code Formatting
Enable and configure the built-in formatter:Keyboard Shortcuts
Default Keybindings
| Action | Windows/Linux | macOS |
|---|---|---|
| Go to Definition | F12 | F12 |
| Peek Definition | Alt+F12 | Option+F12 |
| Find References | Shift+F12 | Shift+F12 |
| Rename Symbol | F2 | F2 |
| Format Document | Shift+Alt+F | Shift+Option+F |
| Show Hover | Ctrl+K Ctrl+I | Cmd+K Cmd+I |
| Trigger Completion | Ctrl+Space | Cmd+Space |
Custom Keybindings
Add custom keybindings inkeybindings.json:
Features
Intelligent Code Completion
- Context-aware completions with type information
- Auto-import suggestions
- Function signature hints
- Snippet support
Type Checking
- Real-time type inference
- EmmyLua and Luacats annotation support
- Type mismatch detection
- Nil safety checks
Navigation
- Go to definition across files
- Find all references
- Workspace symbol search
- Document outline
Code Actions
- Quick fixes for common issues
- Add missing annotations
- Disable diagnostics for specific lines
- Extract to function/variable
Troubleshooting
Language server not starting
Language server not starting
Solution:
-
Check if
emmylua_lsis installed: -
Verify the language server path in settings:
- Check the Output panel (View > Output) and select “EmmyLua” from the dropdown
-
Restart the language server:
- Press
Ctrl+Shift+P(Cmd+Shift+P on macOS) - Run command:
EmmyLua: Restart Language Server
- Press
Completions not working
Completions not working
Solution:
-
Ensure completion is enabled:
- Check if the file is recognized as Lua (bottom-right corner of VS Code)
- Verify workspace indexing is complete (check status bar)
-
Try reindexing the workspace:
- Command:
EmmyLua: Reindex Workspace
- Command:
False diagnostics/errors
False diagnostics/errors
Solution:
-
Add global variables to the whitelist:
-
Disable specific diagnostics:
-
Use inline diagnostic control:
-
Configure library paths:
Slow performance with large projects
Slow performance with large projects
Solution:
-
Ignore unnecessary directories:
-
Use glob patterns to exclude files:
-
Adjust preload file size limit:
-
Disable features you don’t need:
Formatting not working
Formatting not working
Solution:
-
Set EmmyLua as the default formatter:
-
Enable formatting:
- Check for conflicting formatters (disable other Lua formatters)
-
Try formatting manually:
Shift+Alt+F(Windows/Linux) orShift+Option+F(macOS)
Multi-root Workspaces
For multi-root workspaces, configure each workspace folder separately:workspace.code-workspace
Next Steps
Configuration
Learn about all available configuration options
Annotations
Add type annotations to your code
Features
Explore all language server features
Troubleshooting
Optimize performance for large projects
