eclipse-platform / eclipse.platform.ui

Eclipse Platform
https://projects.eclipse.org/projects/eclipse.platform
Eclipse Public License 2.0
77 stars 162 forks source link

[Sticky scrolling] Commented-out code is being incorrectly recognized #2128

Open jakub-suliga opened 1 month ago

jakub-suliga commented 1 month ago

When code is commented out, sticky scrolling incorrectly detects the line.

To reproduce this issue: Under org.eclipse.jdt.ui.text.folding.DefaultJavaFoldingStructureProvider.CommentPosition.findFirstContent(CharSequence, int), some code is commented out.

image

In the method org.eclipse.jdt.ui.text.folding.DefaultJavaFoldingStructureProvider.CommentPosition.computeProjectionRegions(IDocument), there is some commented-out code. Before the the commented out line:

image

And after:

image

tomaswolf commented 1 month ago

Related to https://github.com/eclipse-platform/eclipse.platform.ui/issues/2115 and https://github.com/eclipse-platform/eclipse.platform.ui/issues/1950 . Sticky scrolling would need to be able to know what a comment is, which is different in different languages. AFAIK the current implementation is based purely on indentation?

Perhaps it could consider document partitions, if any. Though I'm not sure there is any platform-wide "standard" to identify comment partitions, and not every editor might use partitions for comments...

Christopher-Hermann commented 1 month ago

Correct, sticky scrolling is based purely on indentation. It is planned to provide a extension point so that every language can define a own implementation for the sticky scrolling calculation. For java we can then provide a implementation that is able to handle this kind of comments, annotations which are currently a problem or unusual code styles. If no specific implementation is provided, the default will still be based on indentation.

Unfortunately I had no time to look into this yet, but definitely want to pick this one up as soon as I have some time.