Install server

If you don’t have node and npm installed, install them first. Then, build the matlab LSP language server as follows:

1
2
3
git clone https://github.com/mathworks/MATLAB-language-server
cd MATLAB-language-server/
npm install && npm run compile && npm run package

After your installation, you need to keep this MATLAB-language-server/ for you use of LSP langserver in Emacs.

MATLAB langserver json config

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
{
    "name": "matlab-ls",
    "languageId": "matlab",
    "command": [
        "/usr/local/bin/node",
        "/Users/zyue/Programs/LSP/MATLAB-language-server/out/index.js",
        "--stdio"
    ],
    "single_file_support": true,
    "settings": {
        "MATLAB": {
            "indexWorkspace": true,
            "installPath": "/Applications/MATLAB_R2022b.app",
            "matlabConnectionTiming": "onStart",
            "telemetry": true
        }
    }
}

⚠️ Warning: As stated in the gitrepo, this language server requires MATLAB version R2021a or later to work!

Configure lsp-bridge mode to load langserver

Add the following configures in your Emacs init files for lsp-bridge:

1
2
3
(add-to-list 'lsp-bridge-single-lang-server-mode-list '(octave-mode . "matlab-ls"))
(add-to-list 'lsp-bridge-default-mode-hooks 'octave-mode-hook)
(add-to-list 'lsp-bridge-formatting-indent-alist '(octave-mode . octave-block-offset))

I use octave-mode to edit MATLAB files. If you use matlab-mode, remember to replace octave-mode with matlab-mode.

Enjoy :D