A lightweight, fast, and cross-platform Language Server Protocol (LSP) implementation for MATLAB files.
Version: 0.3.2 | License: MIT | Python: 3.10+
📖 See INTEGRATION.md for detailed editor configuration guides and advanced options.
pip install matlab-lsp-serverThat's it! The server is now ready to use.
For detailed editor integration guides and advanced configuration, see INTEGRATION.md.
# Run in stdio mode (for LSP clients)
matlab-lsp --stdio
# Run in TCP mode (for debugging)
matlab-lsp --tcp --port 4389
# Enable verbose logging
matlab-lsp --stdio --verbose
# Disable automatic config creation
matlab-lsp --stdio --no-init-configOptions:
--stdio- Run in stdio mode (default for LSP clients)--tcp- Run in TCP mode (for debugging)--port PORT- Port for TCP mode (default: 4389)--host HOST- Host for TCP mode (default: 127.0.0.1)-v, --verbose- Enable verbose logging--no-init-config- Disable automatic.matlab-lsprc.jsoncreation--version- Show version information
You can configure the server in multiple ways (priority order):
- Editor Settings (highest) - Pass settings via LSP client
- Config File -
.matlab-lsprc.jsonin project root - Environment Variables -
MATLAB_PATH - Auto-Discovery - Automatically finds MATLAB in standard locations
VS Code (.vscode/settings.json):
{
"languageserver": {
"matlab": {
"command": "python",
"args": ["matlab-lsp", "--stdio"],
"filetypes": ["matlab", "m"],
"rootPatterns": [".git", ".matlab-lsprc.json"]
}
}
}Neovim (nvim-lspconfig):
require('lspconfig').matlab_lsp_server.setup({
cmd = {'matlab-lsp'},
filetypes = {'matlab', 'm'},
root_dir = require('lspconfig.util').root_pattern('.git', '.matlab-lsprc.json', 'project.m')
})Vim (vim-lsp):
" .vimrc
autocmd BufRead,BufNewFile *.m set filetype=matlab
if executable('python')
au User lsp_setup call lsp#register_server({
\ 'name': 'matlab-lsp',
\ 'cmd': {'matlab-lsp'},
\ 'whitelist': ['matlab', 'm']
\ })
endifEmacs (lsp-mode):
;; init.el
(use-package lsp-mode
:config
(lsp-register-client
(make-lsp-client
:new-connection (lsp-stdio-connection "matlab-lsp")
:major-modes '(matlab-mode)
:server-id 'matlab-lsp)))
(use-package matlab-mode
:config
(add-hook 'matlab-mode-hook #'lsp))TUI Crush (.crush.json):
{
"lsp": {
"matlab": {
"command": "matlab-lsp",
"args": ["--stdio"],
"filetypes": ["matlab", "m"],
"root_markers": [".git", ".matlab-lsprc.json", "project.m"]
}
}
}OpenCode CLI (.opencode.json):
{
"lsp": {
"matlab": {
"command": "matlab-lsp",
"args": ["--stdio"],
"extensions": [".m"]
}
}
}Claude Code LSP / cclsp (cclsp.json):
{
"servers": [
{
"extensions": ["m"],
"command": "matlab-lsp",
"args": ["--stdio"],
"rootDir": "."
}
]
}See INTEGRATION.md for detailed configuration and advanced options.
| Feature | This Server | MathWorks LSP |
|---|---|---|
| Lightweight | Pure Python, no Java required | Java-based, heavy |
| Startup Time | < 1 second | 5-10 seconds |
| Memory Usage | ~50MB | 500MB+ |
| MATLAB Required | Optional (standalone analyzer) | Required |
| Configuration | Simple JSON file | Complex JSON/registry |
| Cross-Platform | Windows, Linux, macOS | Windows only |
| Customization | Fully configurable | Limited |
- Fast & Lightweight - Starts instantly, uses minimal resources
- No MATLAB Dependency - Works with standalone analyzer when MATLAB isn't installed
- Cross-Platform - Works on Windows, Linux, and macOS
- Simple Setup - One
pip installand you're done - Flexible - Highly configurable with JSON config file
- Open Source - MIT licensed, community-driven
- Code Completion - Smart suggestions for functions, variables, and classes
- Hover Documentation - Show function signatures and documentation inline
- Go to Definition - Jump to function/class definitions instantly
- Find References - Locate all usages of symbols
- Document Symbols - Outline view of your code structure
- Workspace Symbols - Search symbols across entire project
- Code Formatting - Auto-format MATLAB code with configurable style
- Diagnostics - Real-time error and warning detection
- Quick Fixes - Automatic suggestions for common issues
- Regex Parser - Fast and robust MATLAB syntax parsing
- Function Extraction - Extract all function definitions
- Class Parsing - Support for
classdef, properties, methods - Nested Functions - Handle nested and local functions
- Variable Tracking - Track global and persistent variables
- Comment Extraction - Parse documentation from comments
- LRU Caching - Fast symbol lookups with O(1) complexity
- Debouncing - Optimized document analysis
- In-Memory Index - Quick project-wide symbol search
- Async Operations - Non-blocking diagnostics and analysis
For complete feature documentation and configuration options, see INTEGRATION.md.
# Using pip (recommended)
pip install matlab-lsp-server
# Or from source
git clone https://github.com/yourusername/matlab_lsp_server.git
cd matlab_lsp_server
pip install -e .Create or edit ~/.crush.json:
{
"lsp": {
"matlab": {
"command": "matlab-lsp",
"args": ["--stdio"],
"filetypes": ["m"],
"root_markers": [".git", ".matlab-lsprc.json"]
}
}
}Create .vscode/settings.json:
{
"languageserver": {
"matlab": {
"command": "python",
"args": ["-m", "matlab_lsp_server.server", "--stdio"],
"filetypes": ["matlab", "m"],
"rootPatterns": [".git", ".matlab-lsprc.json"]
}
}
}Or install the MATLAB extension and configure it to use this server.
Add to init.lua or init.vim:
require('lspconfig').matlab_lsp.setup({
cmd = {"matlab-lsp", "--stdio"},
filetypes = {"matlab", "m"},
root_dir = require('lspconfig.util').root_pattern(
".git", ".matlab-lsprc.json"
),
})Open any .m file in your editor. The LSP server will automatically start and provide:
- Syntax error highlighting
- Code completion
- Hover documentation
- Go-to-definition
- And more!
For more editor configurations (Emacs, Vim, OpenCode, cclsp), see INTEGRATION.md.
Copy the example configuration file to your project root:
cp .matlab-lsprc.json.example .matlab-lsprc.jsonNote: The server automatically creates .matlab-lsprc.json with default settings on first run if it doesn't exist. You can skip this step and edit the auto-generated file later.
Then edit .matlab-lsprc.json with your settings:
What happens if matlabPath stays empty?
- Server starts normally without errors
- Basic LSP features work (completion, hover, go to definition, etc.)
- Diagnostics from MATLAB's mlint analyzer will be unavailable
- Server tries to find MATLAB in standard locations
- Server logs a warning: "MlintAnalyzer is NOT available!"
Auto-Discovery on First Run: On first startup, the server automatically searches for MATLAB in:
- System PATH (recursive search, finds even in bin/win64/)
- Standard installation paths:
- Windows:
C:/Program Files/MATLAB,D:/Program Files/MATLAB, etc. - macOS:
/Applications/MATLAB_R*.app - Linux:
/usr/local/MATLAB,/opt/MATLAB,~/MATLAB
- Windows:
- If found,
matlabPathis auto-filled in.matlab-lsprc.json
To enable full diagnostics:
- Set
matlabPathin.matlab-lsprc.json - Or set
MATLAB_PATHenvironment variable - Or ensure MATLAB is in system PATH
Handling MATLAB Reinstallation: If you reinstall MATLAB to a different location:
- Server will detect the old path is invalid
- Automatically searches for new MATLAB location
- Falls back to basic LSP features if MATLAB not found
- Update
matlabPathin config to specify new location
{
"matlabPath": "C:/Program Files/MATLAB/R2023b"
}That's it! All other settings use sensible defaults. For more configuration options, see INTEGRATION.md.
You can also configure using environment variables:
# MATLAB installation path
export MATLAB_PATH="C:/Program Files/MATLAB/R2023b"pip install matlab-lsp-server
matlab-lsp --stdiogit clone https://github.com/yourusername/matlab_lsp_server.git
cd matlab_lsp_server
pip install -e .
python server.py --stdio- Download from Releases
- Extract the archive
- Run:
python server.py --stdio
- Requires Python 3.10+
- MATLAB R2020b or later recommended for mlint integration
- Works with PowerShell, Command Prompt, Git Bash
- Requires Python 3.10+
- Tested on Ubuntu, Debian, Fedora
- MATLAB R2020b or later recommended
- Works with Octave's mlint alternative (experimental)
- Requires Python 3.10+ (from python.org or Homebrew)
- MATLAB R2020b or later recommended
- Tested on macOS 11+ (Big Sur and later)
python server.py --stdio
# or
matlab-lsp --stdiopython server.py --tcp --port 4389
# Connect with telnet or nc
telnet localhost 4389python server.py --stdio --verbosepython server.py --version
# Output: MATLAB LSP Server v0.3.2- Install MATLAB R2020b or later
- Set
MATLAB_PATHenvironment variable - Or configure in
.matlab-lsprc.json - Server will use standalone analyzer (limited features)
- Check log level is set to INFO or DEBUG
- Verify MATLAB path is correct
- Try running server with
--verbose
- Enable caching (default: enabled)
- Reduce
maxSuggestionsin config - Close unused documents
- Use a fast disk (SSD recommended)
# Use the --verbose flag
matlab-lsp --stdio --verbose
# Or from source
python server.py --stdio --verboseFor more troubleshooting tips and configuration options, see INTEGRATION.md.
matlab_lsp_server/
├── server.py # Main entry point
├── requirements.txt # Dependencies
├── pyproject.toml # Package config
├── src/
│ ├── protocol/ # LSP lifecycle handlers
│ ├── handlers/ # LSP method handlers
│ ├── parser/ # MATLAB parser
│ ├── analyzer/ # Code analyzers
│ ├── features/ # Feature management
│ └── utils/ # Utilities
└── tests/ # Unit and integration tests
See CONTRIBUTING.md for guidelines.
# Install dev dependencies
pip install -r requirements-dev.txt
# Run all tests
pytest
# Run with coverage
pytest --cov=src --cov-report=html
# Run specific test
pytest tests/unit/test_parser.py::test_parse_function- Installation Guide - Detailed installation instructions
- Architecture - Design decisions and structure
- Development - Developer guide
- Contributing - How to contribute
- CHANGELOG - Version history
- FAQ - Common issues and solutions
- ✅ Full LSP implementation (9+ features)
- ✅ MATLAB parser (regex-based)
- ✅ Code completion with ranking
- ✅ Hover documentation
- ✅ Go-to-definition with cross-file support
- ✅ Find references
- ✅ Document symbols with hierarchy
- ✅ Workspace symbols with fuzzy search
- ✅ Code formatting with configurable style
- ✅ Diagnostics via mlint
- ✅ Quick fixes for common errors
- ✅ Cross-platform support (Windows, Linux, macOS)
- ✅ Standalone analyzer (no MATLAB required)
- ✅ LRU caching for performance
- ✅ Configurable via JSON or environment
- .mlx files (Live Scripts) not supported
- Octave compatibility is experimental
- Some advanced MATLAB features may not be parsed correctly
- mlint required for full diagnostics (standalone analyzer is limited)
- Python 3.10 or higher
- 50MB RAM
- 10MB disk space
- MATLAB R2020b or later
- 100MB RAM
- 50MB disk space
- SSD drive for better performance
- MATLAB R2023b (for latest features)
- Git (for installation from source)
MIT License - See LICENSE file for details.
Vladimir M. Funtikov
- GitHub: https://github.com/vmfu/matlab_lsp_server
- PyPI: https://pypi.org/project/matlab-lsp-server/
- Issues: https://github.com/vmfu/matlab_lsp_server/issues
LSP MATLAB Server v0.3.2 Fast. Lightweight. Cross-Platform.