shinyypig / matlab-in-vscode

A vscode extension for matlab.
MIT License
45 stars 5 forks source link

Windows Bringup Fix/Suggestion #2

Closed Veng97 closed 1 year ago

Veng97 commented 1 year ago

Hey!

This is a very nice tool to bring MatLab into VScode! Unfortunately, its not that straight forward to get working on Windows. The behavior of the MatLab bringup command 'matlab -nodesktop -nosplash' actually launches a new window on windows, instead of running directly in the terminal... I couldn't find any options for making this work natively in a console.

I found a different way to add this functionality, but it requires setting up the matlab python engine. The work-around i used was to install the: 'Matlab Interactive Terminal' plugin. The plugin has a python script (wrapper) around the MatLab python engine, which can be used to create an interactive terminal. This plugin will work as usual, by piping everything into the MatLab interactive terminal.

I did this by changing the bringup command in this plugin: From: matlab -nodesktop -nosplash To: python C:\Users\.vscode\extensions\apommel.matlab-interactive-terminal-0.4.0\interfaces\standard\ml_terminal.py (note: requires the 'matlab-interactive-terminal' plugin)

It uses the same backend as the Interactive terminal plugin. It is not as smooth to integrate it this way, but maybe this extension could take inspiration from the other plugin on how to handle support the windows platform better? The python script 'ml_terminal.py' that ships with the MatLab interactive terminal extension is quite simple!๐Ÿ‘

shinyypig commented 1 year ago

Working on it!

shinyypig commented 1 year ago

Add matlab engine for python support in 599b9115f914d1e8218607bf7f38f14944cfa2d0.

I have tested it in macOS, not sure whether it works in Windows.

Maybe you can help me? Just update the extension to 0.2.1. Thanks.

Veng97 commented 1 year ago

Iโ€™ll check it out as soon as i get time, thanks!๐Ÿ‘Œ

Veng97 commented 1 year ago

I have some updates to the extension, and I will try to make a PR later today. The way you handled multi-line commands with 'selection.selection(stdin...)' is apparently not available for Windows. I didn't notice that the original python script didn't catch that either! But i found a solution for windows that i think might be the preferred way to do this on all platforms!

I implemented the get_input() function a bit differently by handling multi-line statements like: for, if, while... explicitly. I think it might be a better approach as handling multi-line reading can be a bit weird when interacting with the console. The approach definitely feels good when using the console, as the engine wrapper understands that any control structure should be parsed as a multi-line statement: for i = 1:3 i end The old version would parse this line-by-line in the interactive console, the new version does not (on windows atleast). In MATLAB you can normally do shift+enter to goto a newline and continue writing, but apparently that doesn't work with python's Input() function.

Veng97 commented 1 year ago

Do you think we could integrate the matlab workspace in VSCode also? The Python engine gives us direct access to a dictionary of values. I don't know much about the amount of time it would take to write some scripting to style a vscode window with a table to allow this though, maybe you have an idea? It doesn't have to be interactive, but just to get an overview would be nice!

shinyypig commented 1 year ago

Do you think we could integrate the matlab workspace in VSCode also? The Python engine gives us direct access to a dictionary of values. I don't know much about the amount of time it would take to write some scripting to style a vscode window with a table to allow this though, maybe you have an idea? It doesn't have to be interactive, but just to get an overview would be nice!

I may not have time in the next few weeks, but once I am free, I will try to implement this feature.

Veng97 commented 1 year ago

The new python backend wrapper is not available when I download the extension, should the version number be updated to get the newest version?

shinyypig commented 1 year ago

The new python backend wrapper is not available when I download the extension, should the version number be updated to get the newest version?

0.3.0 published, thanks again!

Veng97 commented 1 year ago

Thanks! I'll be making another fix to enable the startup command when using Python :) If you can check that I didn't break the original functionality of the startup command when you get the opportunity, that would be much appreciated ๐Ÿ‘

shinyypig commented 1 year ago

Do you think we could integrate the matlab workspace in VSCode also? The Python engine gives us direct access to a dictionary of values. I don't know much about the amount of time it would take to write some scripting to style a vscode window with a table to allow this though, maybe you have an idea? It doesn't have to be interactive, but just to get an overview would be nice!

https://marketplace.visualstudio.com/items?itemName=devwright.vscode-terminal-capture

this extension may help

shinyypig commented 1 year ago

Do you think we could integrate the matlab workspace in VSCode also? The Python engine gives us direct access to a dictionary of values. I don't know much about the amount of time it would take to write some scripting to style a vscode window with a table to allow this though, maybe you have an idea? It doesn't have to be interactive, but just to get an overview would be nice!

In version 0.4.0, you can inspect the variables in vscode directly, including name, size, and type.