Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
CelsoReyes opened this issue Jan 3, 2018 · 6 comments
Labels

Comments

@CelsoReyes
Copy link

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

@Gimly Gimly added the bug label Jan 10, 2018
@sco1
Copy link
Contributor

sco1 commented Feb 22, 2018

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 added a commit that referenced this issue Apr 17, 2018
Before, adding block comments was not adding the comments correctly. It
was adding block comments that were not in a correct format for Matlab.

As proposed by @CelsoReyes in #31, I've added line breaks before and
after the %{ and %} characters. This makes the block comments be
recognized correctly by Matlab, but has the unfortunate drawback that we
cannot remove them correctly.

Unfortunately that's all we can do for now.
@Gimly
Copy link
Owner

Gimly commented Apr 17, 2018

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: microsoft/vscode#48074

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

@CelsoReyes
Copy link
Author

Thanks @Gimly tackling this!

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

@Gimly
Copy link
Owner

Gimly commented Apr 18, 2018 via email

@Gimly
Copy link
Owner

Gimly commented Mar 28, 2019

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
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants