vscode-guides icon indicating copy to clipboard operation
vscode-guides copied to clipboard

Unindented comment lines break scope

Open Eugenii10 opened this issue 7 years ago • 6 comments

Unindented comment lines break code scope recognition. It is actual for different languages, e.g. Python or Java.

  • [x] I have search open issues for duplicate issues
  • [x] I have search close issues for potential fixes
  • Guides Version: 0.9.1
  • VSCode Version: 1.20.1
  • OS Version: Windows 7 and 10

Steps to Reproduce:

  1. Add comment line without any indentation to the middle of some scope, so that this comment split scope's code on two parts.
  2. Set cursor to the first (before comment) or second (after comment) part of the scope's code.

Actual Behaviour: actual

Expected Behaviour: expected

Eugenii10 avatar Mar 03 '18 08:03 Eugenii10

Huh, nice catch. I might need to take a look on this though. It might or might not affect how the extension calculate the indentations, if it is, this would take some time. Anyway, I will update once the fix is up. :)

spywhere avatar Mar 03 '18 08:03 spywhere

As Guides does not know any language feature (such as determine if the current line is a comment), this issue might not get resolved due to "unusual" indentation. However, if the RegExp pattern is provided through an extension's setting, this might be possible as it can check for certain patterns and keep the active area intact.

If this issue get resolved, instead of highlighting the scope for current if, it would highlight all the if... (the images below is a partial implementation to solve this issue)... screen shot 2561-03-05 at 17 34 38 screen shot 2561-03-05 at 17 34 50 screen shot 2561-03-05 at 17 35 08

I'll close this issue after a period of inactivity though, unless you happy to provide the RegExp patterns in the extension's settings for your needs.

spywhere avatar Mar 05 '18 10:03 spywhere

I'm not sure that such RegExp is possible since there are too many cases in different languages. I'm not sure that we can detect scopes with RegExp (JS version) even in one language, e.g. in Java.

Anyway your extension is the best solution at the market nowdays. Indenticator and Scoper goes mad on some code examples, which made them not usable at all. While your extension has only this non-critical disadvantage. The only extension I have seen, which detects scopes right, was Bracket Pair Colorizer. But I don't think it uses RegExp for it's purposes.

Thanks for your time and work!

Eugenii10 avatar Mar 06 '18 11:03 Eugenii10

Sure, there are a lot of patterns required in order to make it work for every language, but that is up to the user themselves. The intention is to let user customised their own RegExp pattern for their needs.

This extension only looking (though roughly) at the text as a whole line, not individual characters, in which the extension has to figure out which lines are breaking the indentation and which one are not. By providing a RegExp, the extension can simply take a look at the pattern and judge if that line should considered break the indentation or not.

For Bracket Pair Colorizer, the extension does not needed for the languages that are "bracket-less" such as Python hence it detects the scopes right.

Hope this make the explanation clearer to you for why RegExp pattern is needed in order to implement this small feature.

spywhere avatar Mar 07 '18 09:03 spywhere

Hm, for Java language the RegEx for "lines which are not breaking the indentation" coud be next: But where could I insert that RegEx? I didn't find such option in the Extension group of settings.json file. Thanks. regex_java

Eugenii10 avatar Mar 08 '18 15:03 Eugenii10

Not yet. I just propose a solution so that you can check if it would work for your need or not.

spywhere avatar Mar 09 '18 02:03 spywhere