Gimly / vscode-matlab

MATLAB support for Visual Studio Code
MIT License
181 stars 35 forks source link

Block Comments should force a new line, else they're treated as line comments #31

Open CelsoReyes opened 6 years ago

CelsoReyes commented 6 years ago

Hi, I really enjoy your Matlab Extension. I find VSCode's editing capabilities far outpace Matlab's editor.
I noticed this anomaly while checking out various VSCode keyboard shortcuts.

How to reproduce:

% here follows code, the first line of which I'd like to block comment
disp(a)
disp(b)
disp(c)

select the first two disp(...) commands Toggle block comment (on mac, shift-alt-A)

Result:

%{ disp(a)
disp(b) %}
disp(c)

Expected:

%{ 
disp(a)
disp(b)
%}
disp(c)

Reasoning MATLAB only understands block comments when they're alone on a line (with the exception of whitespace) In this particular case, the first line is treated as though it had the typical line comment. The second line is interpreted by MATLAB as though it ends with a commented-out closing brace.

What I tried: By modifying the matlab.configuration.json file, I could add the line feeds, but then the line comment no longer toggled back off. Still, this behavior might be preferable to the existing behavior.

"blockComment": [ "\n%{\n", "\n%}\n" ]

side note: even MATLAB (r2017a) doesn't seem to have a shortcut key combo for this feature

sco1 commented 6 years ago

I'm not sure this can be done outside of the extension without an enhancement from the core. Per some similar issues like this one:

The command is currently implemented by adding or removing / and / from the selection edges. The actual text to be added/removed is configured via language configuration.

In theory this should also be able to handle block comment openings/closures defined with line breaks, as in your example, but as currently implemented it's not handling it properly and I'm not literate enough in the language to figure out where it's going wrong. I think it's worth an issue on the VSCode repo.

This can be implemented at the extension level but it would end up being a separate command from VSCode's.

Gimly commented 6 years ago

I've updated the extension with your proposal @CelsoReyes, I find it better than the previous behavior.

I'm keeping the issue open for now, since it's not completely fixed. I'm putting it on hold though, because as @sco1 has explained, it's an issue related to how VSCode is managing those block comments.

I've opened an issue on VSCode's repository: https://github.com/Microsoft/vscode/issues/48074

I'm putting this issue on hold until we know if that will be fixed.

CelsoReyes commented 6 years ago

Thanks @Gimly tackling this!

side note: Thanks for the acknowledgement, though my last name is misspelled in the release notes. Reyes (not Reys).

Gimly commented 6 years ago

Oops, sorry about the misspelling, will fix that in the next release.

Le mer. 18 avr. 2018 à 09:40, Celso notifications@github.com a écrit :

Thanks @Gimly https://github.com/Gimly tackling this!

side note: Thanks for the acknowledgement, though my last name is misspelled in the release notes. Reyes (not Reys).

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Gimly/vscode-matlab/issues/31#issuecomment-382294032, or mute the thread https://github.com/notifications/unsubscribe-auth/AAKS3bGmqZmLIn2wmySL0n4TT-dY2abTks5tpu3qgaJpZM4RReGy .

Gimly commented 5 years ago

With version 1.0 we've updated the syntax highlighting syntax which might have been the cause of the issue. Could you please tell me if you still experience the issue with that version?

AnnyCaroline commented 5 years ago

It seems to work fine.

But it adds 2 blank lines and doesn't indent the comments (except for the first one). I tested on vs-code for Windows.

Result:

% here follows code, the first line of which I'd like to block comment

%{
 disp(a)
disp(b) 
%}

disp(c)

Expected:

% here follows code, the first line of which I'd like to block comment
%{
 disp(a)
 disp(b) 
%}
disp(c)