简单提供个matlab的lsp-bridge支持

过去一个月“叛逃”去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: 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 :smiley:

5 个赞

欢迎给lsp-bridge发补丁呀

1 个赞

好的啊

待我用段时间感受下,主要看看别的功能怎么样,要是不错就提pr哇。
因为这个langserver是mathworks公司才做不久,写matlab库函数补全没啥用,其它功能用用看咋样。

1 个赞

更新:最新release版本1.2.7是有问题的,neovim及官方支持的vscode都有问题,退回前面版本可以正常工作,比如1.2.6等(vscode测试okay,emacs上述配置亲测ok)。

经测试,1.2.7 版本 npm run compile 都通不过,提示有个json文件有语法错误,具体没有深入。等下个版本或修复吧。


更新:从matlab-language-server 1.1.8 还是支持的(我Emacs在用的)。情况不清楚,最新的ls在neovim上似乎也不行。


注:今天试了下MATLAB-language-server 目前HEAD(bb6f79e)的langserver,使用有点问题,定义、引用跳转什么的都不工作,不清楚是不是要修改json配置还是有bug。

上面工作的matlab ls是下面commit:

commit e05673ab0e9190bc0a6428c0071ecd5abc1a4d67
Author: dlilley <[email protected]>
Date:   Wed Dec 6 16:09:10 2023 -0500

    Update package-lock to include `bin` path
1 个赞