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.

Home Page:https://marketplace.visualstudio.com/items?itemName=MathWorks.language-matlab

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Line continuation using ellipses does not handle indentation correctly

goldrik opened this issue · comments

On the MATLAB IDE, any line continuation using ellipses (...) automatically indents the next line.

On VS Code, this occurs when the continuation occurs after some operator ('=', '+', etc), or if a function is being defined.
Screenshot 2024-01-12 at 11 59 11 AM 3

However, (as far as I can tell) VS Code does not automatically indent in all other cases.
Screenshot 2024-01-12 at 11 59 11 AM 3 2

Here, lines 55, as well as lines 58-61, should have indented automatically.


When doing multiple line continuations using ellipses, each subsequent line should be indented. Once the line is finished, the indentation should go back to its original position. This occurs on the MATLAB IDE automatically. On VS Code, the indentation does not reset after a line is terminated, and you have to manually tab backwards.

Here, when I don't press 'tab' myself, line 56 is indented when it shouldnt be.
Screenshot 2024-01-12 at 12 07 02 PM 3


Suggestion: Something that would be nice is if VS Code could detect if a line is continuing and automatically add ellipses (when the user presses 'enter' while typing out a line). The MATLAB IDE currently does this.

Thanks for identifying this and including your suggestion! I have copied the suggestion over into a separate feature request (#86) to track it separately.

It looks like the root of the issue here isn't what character precedes the ellipses (operator or not), but whether there is any text after the ellipses.

For example, the following works when pressing enter (the | indicates where the cursor is):

foo...|

But the following does not:

foo...|+

Ahh, I see now. The editor auto-inserted the closing parent / bracket in those lines in front of the cursor, which caused the newline to not indent. When I manually delete the closing bracket before pressing enter, the new line gets indented correctly.

I was also able to test the issue out with a multi-line (> 2 lines) statement. Since the editor does not reset indentation after an indented newline (within a statement), we see things like this happen.

Screenshot 2024-01-17 at 11 12 17 AM 3

Here, I just typed out this line as I would on the MATLAB editor, never pressing "tab" manually (though I did have to delete the closing bracket when it was automatically inserted, as mentioned above). The editor also moved the final closing bracket (on the last line) after I inserted it, which I would say is the correct behavior. This only occurs if the closing bracket / paren is on its own line though.

The fix for this issue should address #90 as well.