过去一个月“叛逃”去neovim娱乐了一把(用的Astronvim开箱即用配置,体验了把果冻光标爽感),发现有matlab的lsp支持,于是整了个用用,分享给一样常用MATLAB的桶子们。
配置比较简单,主要是这个matlab language server的安装(官方没给流程,对于我这种没用过node的人实在不友好)、抄个json文件就搞定啦~
我写的blog在这里,用来快速记录下防忘;为避免github访问问题原文我也直接贴下面:
Install server
If you don’t have node
and npm
installed, install them first. Then, build the matlab LSP language server as follows:
git clone https://github.com/mathworks/MATLAB-language-server
cd MATLAB-language-server/
npm install && npm run compile && npm run package
After installation, you need to keep this MATLAB-language-server/
for the use of LSP langserver in Emacs.
MATLAB langserver json config
{
"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 configurations in your Emacs init files for lsp-bridge
:
(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