vscode-guides
vscode-guides copied to clipboard
Unindented comment lines break scope
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:
- Add comment line without any indentation to the middle of some scope, so that this comment split scope's code on two parts.
- Set cursor to the first (before comment) or second (after comment) part of the scope's code.
Actual Behaviour:
Expected Behaviour:
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. :)
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)...
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.
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!
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.
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.
Not yet. I just propose a solution so that you can check if it would work for your need or not.