Code Monkey home page Code Monkey logo

ami's Introduction

aMi: alternative Matlab ide

What this extension is about

The "alternative Matlab ide" aims at providing a full fledged Matlab user experience directly from VSCode.

This extension is a work in progress and features will be added as described in the Feature section bellow.

This extension is intended for Linux users (so most should work on MacOS).

Current version 0.5.1.

What this extension is not about

... though it might be if it comes for free ...

There is no intent to provide integration for toolboxes, application packaging or Simulink. These Matlab extensions are available through the Matlab command window.

There is no immediate intent to provide compatibility to Windows... not that I want to preclude from using Windows, but I just don't own one...

Usage

To start Matlab

  • Open the command palette using Ctrl+Shift+P
  • Type aMi: Start Matlab in the command palette

To use Matlab

  • Use the command window as usual
  • Start scripts from either the file editor or file explorer using right click and then selecting Run Matlab file
  • Execute selected code in the file editor using right click and then selecting Run selection in Matlab command window

To stop Matlab

  • Open the command palette using Ctrl+Shift+P
  • Type aMi: Stop Matlab in the command palette

To start interactive debugging

  • Open the command palette using Ctrl+Shift+P
  • Type aMi: Start debug adaptor in the command palette

To stop interactive debugging

  • Use the stop button (red square) in the debug command widget.

Features

Basics (Version 0)

There is no intent to provide syntax higlighting or linter in version 0. Other extensions can be used for this (Gimly81.matlab for instance).

Integrated Matlab command window (Version 0.0)

Provide Matlab command window in a terminal.

Run script files (Version 0.1)

Run .m file from editors or from the file explorer window.

Run selected code (Version 0.2)

Run current selection in the integrated command window.

Add / remove breakpoints (Version 0.3)

Add remove breakpoints from editors (Matlab functions and scripts only).

Pause on error / warning (Version 0.4)

Debug mode catches error and warning and pauses execution to allow debugging.

Workspace explorer (Version 0.5)

Explore the current workspace variables. Go up and down the execution stack when debugging.

OS agnostic terminal (Version 0.6)

Works "out of the box" with Windows, MacOS and Linux. Matlab editor by-passed.

Workspace editor (Version 0.7)

Edit values from the workspace explorer.

Profile explorer (Version 0.8)

Drill down profiler results.

Advanced editing (Version 1)

Command window auto completion (Version 1.0)

Auto completion hints straight from the command window.

Integrated syntax highlighter (Version 1.2)

Stand alone syntax highlighter based on in situ Matlab installation.

Integrated linter (Version 1.3)

Stand alone linter based on situ Matlab installation.

Run current cell (Version 1.4)

Run cells in the current command window.

Requirements

Matlab must be installed on your computer and configured so that matlab command starts it. This extension is built and tested using Matlab R2019a. Backward compatibility is not granted though it should work smoothly as of R2014b.

Matlab Engine API for Python (min 3.6) must be installed (follow these instructions).

Extension Settings

None for now.

Release Notes Version 0.5.1

  • When debug adaptor is started, variables of the selected stack workspace are now displayed in the variables tab of the debug pane.
  • For release 0.5.1 arrays and cell arrays exploration support has been added. Structure and object support will be added in next release.

Known Issues

Major

  • Some error messages in the command window are printed incorrectly.
  • Debugging files not in path (run file in place) does not work. Workaround is to add them to the path.
  • Exception and warning catching can only be treated as an otherwise standard breakpoint. Error informations are only availble from the command window. There will probably not be any fix for this as this is linked to what information Matlab can programatically provide on the current debug state.

Annoying

  • Conda environments can preclude this extension to work properly. It will not work for instance if you have installed a recent Anaconda (using now Python3.7) and let the installer initialize your .bashrc file. To work this around, create an environment compatible with this extension and start VSCode from that one.
  • Command history is lost when VSCode is closed before using aMi: Stop Matlab or terminating Matlab manualy from its command window (using exit).
  • The debug stop button (red square) is misleading as it forces the debug adaptor to shut down. If you want to stop debugging and return to the command window, use debug restart button instead (green rotating arrow). If you stop the debug adaptor by mistake, just restarting it should restore previous state. Note: there will be no fix to this as this is the behaviour enforced by the debug protocol.
  • First undefined variable or function error in the command window catches Matlab internal errors if Caught Errors option is set.
  • Altering the class of the content of a cell (in a cell array) can break VSCode variable explorer if that cell is displayed when the change is done. Workaround is to stop and restart the debug adaptor.

Minor

  • Breakpoints remain set after the debug addaptor has been shut down (not sure yet if this is an issue or desirable feature - feedback welcome). To clear all breakpoints: re start debug adaptor and remove all breakpoints, or alternatively enter dbclear all in the Matlab command window.
  • Shared session of Matlab can not be stopped cleanly from the Python API. The error raised at exit is simply ignored.

ami's People

Contributors

marmottetranquille avatar

Stargazers

 avatar Andvari avatar Davi Mendes avatar Tci Gravifer Fang avatar  avatar David Devoogdt avatar sergey plotnikov avatar Robin Tournemenne avatar Yangyuanchen Liu avatar Jeffrey Erlich avatar

Watchers

sergey plotnikov avatar

ami's Issues

-nosplash option

Is your feature request related to a problem? Please describe.
MatLab splash screen is displayed when start matlab is run

Describe the solution you'd like
Add an option to add "-nosplash" to the start command

Layout validation test list

1 -
Start Matlab,
Start Debug adaptor,
Click on all debug buttons => nothing happens except on stop debug which should terminate the python subprocess.

2 -
From 1 last status
Start Debug adaptor,
Open testScript function,
Set a breakpoint and run the function (right click),
Verify breakpoint is hit,
Click on all buttons and verify expected behavior.
After restart button has been pressed, start testScript from the command window
Verify breakpoint is hit,
Step in str2double,
Click on stop button,
Restart Debug adaptor,
Verify debug status is restored.

Figure how to throw Matlab has stopped in vscode

Once we know Matlab is executing some code, it's fairly easy to catch when it stops by just spawning a dummy disp and wait for it to be executed.
The hard thing is that some processing can be triggered either from VSCode actions (run script) or directly from the command window in which case the debug addaptor is bypassed and therefore does not know Matlab is now running again...

The idea to solve this is to tee all terminal inputs to a temporary files on top of Matlab stdin, by simply monitoring if a line has been added in this file we know the user pressed enter and Matlab is executing some new code and we can use our dummy disp trick to wait for it to finish and send a stopped event back to vscode debug session.

Now to do this, the Python adaptor needs to monitor to input streams in parallel: the input log file that we just discussed, and its own stdin. => we make some use of asyncio:
https://tutorialedge.net/python/concurrency/asyncio-event-loops-tutorial/
That would be perfect and easy if sys.stdin.readline() was not blocking... but it is so there is an extra bit of complication to add in order to loop around it until it is really ready to spit some lines :
http://www.dsclose.com/linux/python/2016/04/26/non-blocking-reads-clearing-stdin-in-python.html

display variables in workspace even after the script is finished

Hi, first this is really amazing work!
I think displaying the variables in the workspace in real time is a great idea. The command who (matlab command) may be used recursively to get the variables in warkspace now. There, the variables will be shown even if they are assigned in the interactive matlab, or after the script is finished.

Trouble with setting up aMi

image

This seems like a great project! I have some trouble setting it up on Linux (manjaro).
The start Matlab works fine, but the other commands don't work for me (manual typing in the opened Matlab terminal works). For the debugger, the problem seems to related to the Matlab python engine, but in a separate python session it works (see screenshot)

How to proceed from here?

Error message on MacOS on "aMI: Start Matlab"

Describe the bug
VSC reports "Matlab remote control can not be initiated." as error message on MacOS, however all functionality seems to work.

which matlab, when run from terminal, returns

/Applications/MATLAB_R2018a.app/bin/matlab

This, however, seems not to be recognized as a valid path by the 'realpath' check on line 387 of extension.ts:

exec('realpath `which matlab`', (err: any, stdout: string, stderr: string) => {

create an extra page at the sidebar

As this extension aims to be the matlab IDE, I suggest creating an extra page at the sidebar to list the commands like "start matlab", stop matlab", "run script" or even display the waorkspace, some common used tools like image drawing, e.t.c
examples:

Figure how to track and merge Matlab and Vscode set breakpoints.

Not sure this is useful, setting breakpoints manually will lead to the VSCode UI correctly showing we are stopped at a breakpoint, only the red dot will be missing. Besides, one needs to be a bit tortured to set breakpoints manually when an interface is available....

For windows users

Since this extension uses Matlab Engine API for Python, I think it might work for windows users too. Similar functions have been facilitated in Matlab Interactive Terminal(Open a Matlab Terminal & Run current Matlab Script).

Stack trace returned in reverse order

Describe the bug
No focus on called function when 'stepping in'.

To Reproduce
Place a breakpoint.
Sep in a function.
=> focus remains on current file.
Select called function stack frame
=> focus on called function source file.
Step
=> focus returns to caller file

Expected behavior
Stepping in should focus on called function source file.
Stepping inside a called function should retain focus on its source file.

Additional context
V 0.3.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.