mathworks / MATLAB-extension-for-vscode

This extension provides support for editing MATLAB® code in Visual Studio® Code and includes features such as syntax highlighting, code analysis, navigation support, and more.
https://marketplace.visualstudio.com/items?itemName=MathWorks.language-matlab
MIT License
234 stars 15 forks source link

WSL Support #73

Open anatolicvs opened 11 months ago

anatolicvs commented 11 months ago

Dear Mathworks Team,

I'd like to use this extension in VS Code, which is installed on WSL Ubuntu. However, I'm unable to connect to MATLAB from WSL Ubuntu, even though I've set the MATLAB executable path correctly.

The Windows path for the MATLAB executable is C:\Program Files\MATLAB\R2022b\, which corresponds to /mnt/c/Program Files/MATLAB/R2022b/ in WSL.

Shouldn't it connect to the MATLAB instance already installed on the Windows machine?

Thanks for your response. Best.

hamidingit commented 11 months ago

Thanks for trying this extension. Can you give us more information on your setup?:

anatolicvs commented 11 months ago

Thank you so much for your swift response, here's the system spesification follow; Version of VS Code : 1.83.1 Version of Ubuntu : Ubuntu 22.04.3 LTS (GNU/Linux 5.15.123.1-microsoft-standard-WSL2 x86_64) Version of Windows : OS Name: Microsoft Windows 11 Pro OS Version: 10.0.22621 N/A Build 22621

Matlab Version : 2022b

I am utilizing Microsoft's WSL extension (https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-wsl) to run a VS Code instance on the Ubuntu WSL OS. I can seamlessly access and execute programs (use its APIs) like Docker (which is an executable) installed on the Windows OS, as well as access datasets stored within the Windows OS. This means there are no access issues to resources, and executables can be accessed bidirectionally.

So, in theory, I should be able to access and use the Matlab APIs from this path: /mnt/c/Program Files/MATLAB/R2022b/.

Regarding your suggestion to use 'remote SSH': while I primarily work locally and develop algorithms for Linux platforms, I might consider connecting to the WSL Ubuntu through remote SSH. However, I doubt it will make a significant difference.

It's out of scope this issue, however it's important, will you consider to brought Matlab's debuuger into this VS Code extension ?

Thank you for your answers.

Best.

dklilley commented 11 months ago

Thank you for sharing info about your workflow!

It looks like there are a number of different things going wrong in this environment which are preventing MATLAB from launching, being connected to, and running the language server's M code.

One specific issue - while I can get MATLAB to launch from WSL (by navigating to /mnt/c/Program Files/MATLAB/R202Xy/bin and running ./matlab.exe -nodesktop, this is very much a Windows installation of MATLAB. As such, running addpath attempts to prepend any path with C: and converts all forward slashes into backslashes.

dklilley commented 11 months ago

I was able to get this to work by installing MATLAB within the WSL. I did this by downloading the appropriate .zip from mathworks.com, copying it over into the Linux subsystem, and following these instructions. I had to mess around a bit to get the installer to work, so if you run into problems, I would recommend reaching out to MathWorks install support.

Once MATLAB was installed, I was able to specify the installPath in VS Code as /usr/local/MATLAB/R2023b. Once this was done, I was able to connect to MATLAB from the VS Code connected to the WSL.

anatolicvs commented 11 months ago

You've essentially installed a second instance of MATLAB into WSL, and there's no way to integrate it with the MATLAB installed on Windows. It's quite frustrating to have two identical MATLAB instances on my local machine. I thought that your VSCode extension would make API calls to any already-running MATLAB instance, regardless of where it's installed. Anyway, thanks for your kind and informative response Duncan !

dklilley commented 11 months ago

Currently, the MATLAB language server relies on launching its own instance of MATLAB and is unable to connect to another instance of MATLAB already running on the machine.

While having a second installation of MATLAB on your WSL definitely isn't an ideal solution, I wanted to propose it as a possible workaround for now.

Even with connecting to an existing instance of MATLAB, there are likely to be some hurdles we need to overcome stemming from VS Code and MATLAB living in different environments. I think the primary issue will be centered around file paths.

cuixing158 commented 11 months ago

hi, @anatolicvs Maybe you can workaround an option, I wanted to use MATLAB on WSL back in 2021, after a year which was last year 2022, Microsoft's win10 system started to support WSLg(Windows Subsystem for Linux GUI) to run matlab, see my question for a tutorial on how to install it!