Skip to content

Ensure the last line is included in projection-based visible regions#3585

Merged
vogella merged 1 commit into
eclipse-platform:masterfrom
danthe1st:visible-region-missing-last-line
Jan 12, 2026
Merged

Ensure the last line is included in projection-based visible regions#3585
vogella merged 1 commit into
eclipse-platform:masterfrom
danthe1st:visible-region-missing-last-line

Conversation

@danthe1st

Copy link
Copy Markdown
Contributor

As noticed in #3074 (comment) by @totomomo18, there are situations where the projection-based folding introduced in #3074 hides the last line where it should be shown. In that example, it was due to Windows line endings (\r\n) where the last line was missing and it only moved past the \r but not the \n (it didn't account for the second character).

However, there is another situation where this can happen which is the case if there is additional (non-whitespace) text in the last line after the visible region. In the following example, assume that the visible region starts with { and ends with }:

{
    // ...
} // additional text here

Here, the } would be hidden.

An example where this could happen with JDT is enum constants (because of the , after the constants):

enum ABC {
    SOME_CONSTANT,
    OTHER_CONSTANT
}

The problem with these situations is that projections/folding cannot hide partial lines at the end so it has to show the entire last line. When I implemented #3074, I was assuming that this was an issue with whitespace at the end but I didn't account for further text (it worked perfectly fine with comments and other things in JDT because comments at the end seem to be included in the visible regions set by JDT).

This change ensures that setting the visible region with projections enabled does not hide the last line in case there is additional text at the end of the line or the file is using Windows line endings by fixing the logic for computing the end of the visible region.

@github-actions

github-actions Bot commented Dec 15, 2025

Copy link
Copy Markdown
Contributor

Test Results

 3 015 files  ± 0   3 015 suites  ±0   2h 15m 47s ⏱️ + 8m 41s
 8 262 tests + 4   8 014 ✅ + 4  248 💤 ±0  0 ❌ ±0 
23 610 runs  +12  22 819 ✅ +12  791 💤 ±0  0 ❌ ±0 

Results for commit c2650ca. ± Comparison against base commit e81ba1c.

♻️ This comment has been updated with latest results.

@danthe1st

danthe1st commented Dec 19, 2025

Copy link
Copy Markdown
Contributor Author

@akurtakov Would you like to review that since it seems like this also impacts lsp4e?

Other than that, I think it would be good to get a review on #3456 if possible.

@danthe1st

Copy link
Copy Markdown
Contributor Author

@iloveeclipse @akurtakov Could this (and also #3456) please be reviewed?

(The recent changes are just rebasing and updating copyright headers)

@danthe1st

danthe1st commented Jan 10, 2026

Copy link
Copy Markdown
Contributor Author

@vogella Since others don't really seem to be interested in reviewing these regression fixes, would you like to take a look at this and #3456?

P.S. Sorry if I'm a bit annoying but I would like to get this done before M2 if possible.

@vogella

vogella commented Jan 11, 2026

Copy link
Copy Markdown
Contributor

I try to check this tomorrow.

This change ensures that setting the visible region with projections
enabled does not hide the last line in case there is additional text at
the end of the line or the file is using Windows line endings.
@vogella vogella force-pushed the visible-region-missing-last-line branch from 2767a44 to c2650ca Compare January 12, 2026 09:20
@vogella

vogella commented Jan 12, 2026

Copy link
Copy Markdown
Contributor

The Pull Request PR #3585 ("Ensure the last line is included in projection-based visible regions") addresses a bug where the last line of a
visible region is incorrectly hidden under specific conditions (e.g., Windows line endings, trailing non-whitespace text).

Analysis

  1. Problem Identification: The PR author clearly explains that the previous logic for calculating computeEndOfVisibleRegion failed to account for:

    • Windows line endings (\r\n), where it might only skip the \r but not the \n.
    • Non-whitespace content appearing after the designated "end" of the visible region on the same line (e.g., } // comment).
    • Since projection folding works on a line-by-line basis, it cannot hide part of a line; it must show the entire line. The original logic was too aggressive in excluding the end of the line.
  2. Implementation:

    • ProjectionViewer.java: The updated computeEndOfVisibleRegion logic is much more robust.
      • It now iterates forward from the proposed end index until it hits a line break (\n or \r) or the end of the document. This ensures any trailing content on that line (whitespace or not) is
        included.
      • It explicitly checks for and consumes the newline characters (\n or \r, and specifically \r\n pairs).
      • This effectively snaps the "end" of the visible region to the end of the line containing the requested end offset, which is the correct behavior for line-based folding.
  3. Testing:

    • ProjectionViewerTest.java: The PR adds excellent test coverage.
      • testDifferentLineEndings: parameterized to test both \n and \r\n (Windows) line endings.
      • testIncludesLastLineIfAdditionalTextPresent: Specifically tests the } // ... scenario where the suffix was previously causing the line to be hidden.
      • testSetVisibleRegionUntilEOF: Edge case coverage for when the region ends at the very end of the file.
  4. Conventions: The changes adhere to the project's coding style and copyright headers are updated.

Conclusion

Opinion: The PR is valid and the fix is implemented correctly. It addresses a real edge case in the text editor's projection/folding logic that users on Windows or with specific coding styles (trailing
comments) would encounter. The logic change is simple and well-reasoned, and the tests cover the failure cases comprehensively. It is ready to be merged.

@vogella vogella merged commit 59dbd43 into eclipse-platform:master Jan 12, 2026
18 checks passed
@vogella

vogella commented Jan 12, 2026

Copy link
Copy Markdown
Contributor

Thanks @danthe1st

@danthe1st danthe1st deleted the visible-region-missing-last-line branch January 12, 2026 11:44
@totomomo18

Copy link
Copy Markdown

Thank you very much @danthe1st and everyone else helping him I really appreciate it. This combination of show only select element and the folding feature make Eclipse even better by having another killer unique feature which the other ides (Vscode and all his forks, Intellij and all other Jetbrains Ides) don't have.
So do I have to wait for the next Eclipse release to use this new killer feature
or can I simply use check for updates to get it today ?

@danthe1st

danthe1st commented Jan 13, 2026

Copy link
Copy Markdown
Contributor Author

@totomomo18 You can download the last SDK/I-build at https://download.eclipse.org/eclipse/downloads/. At "Latest Downloads", select the integration build (starting with I2026) and you'll get to https://download.eclipse.org/eclipse/downloads/drops4/I20260112-1800/.
There, select the appropriate Eclipse SDK download (don't download the unit test results).

Please note that this is a daily build that may contain bugs. If you find any, please report them accordingly and include the exact build you used in your report.

If those bugs seem to be related to folding/visible regions, you can also add a ping so I see it (and hopefully I'm able to take a look at it)

@iloveeclipse

Copy link
Copy Markdown
Member

There is a new test fail coming from this PR, see #3667

@totomomo18

Copy link
Copy Markdown

I just saw that this new feature is on the official 2026 03 Eclipse version Thank you very much @danthe1st and everyone else helping him I really appreciate it. I am waiting for it to get to Eclipse Spring Sts version which I am sure is usually going to be tomorrow.

I actually started to vibe code plugins for Eclipse (I love this Ide) :) and even made a great plugin for my very old Eclipse Sts (Running Java 7) and I am working on a version for the new Sts (from Java 8 onward).

The plugin brings the other unique killer feature of Eclipse to the front The "Clone Editor" option. I have made a plugin which brings this option and the split options to the front. It makes Icons for it in the toolbar and in the right click context menu of the editor.

I also made a new option (Which I also asked for in another issue I posted here) which was missing from the clone editor. I added an option to clone a method which mean to open the implantation of a method in a new cloned tab.

The plugin works perfectly on my old Sts. I still have a few problems on the new Sts version. I may want to publish and share it to everyone but I dont know what is the proper way to do it.

I am not really a plugin developer (I know nothing about the code the Ai wrote) since the Ai did all the work I just directed him till the plugin worked perfectly as far as I can see. Can I share a plugin that the Ai developed ? do plugins go trough the same unit test process before they can go to the marketplace ?

@danthe1st

danthe1st commented Mar 11, 2026

Copy link
Copy Markdown
Contributor Author

@totomomo18 This should be in Spring Tools 5.1.0.
Make sure you configured the correct update site(s).

Can I share a plugin that the Ai developed ? do plugins go trough the same unit test process before they can go to the marketplace ?

Yes, you can create an update site with your plugin (just serve it somewhere on the internet) and then add a marketplace entry at https://marketplace.eclipse.org for people to discover it.

Anyway if you enjoy developing plugins-ins, maybe you also want to contribute a bugfix or some other change to the Eclipse IDE.

@totomomo18

totomomo18 commented Mar 11, 2026

Copy link
Copy Markdown

I assumed there will be a new version of Sts coming out like 5.2.0 following the 2026 03 Eclipse release so I thought I download it from the Spring site. I have problems with my current Sts 5.1.0 . I recently check for updates on my Sts 5.1.0 and it showed me there where some update on the git plugins. I updated those change and now every time I check for updates I get no remedy error. I tried to revert the changes and it does not help. The Ai told this may caused by confict with the update sites. what are the correct update site(s) ?

I would love to help you guys make changes to Eclipse. I love this Ide and I want to make it better (It already is way better than Intellij and Vscode) but I lack the knowledge. The Ai made the plugins not me I just had the ideas for improvements. I would not know where to start on changing the inner working of the actual Eclipse.

@danthe1st

danthe1st commented Mar 11, 2026

Copy link
Copy Markdown
Contributor Author

Spring Tools 5.1.0 was released today and it should be based on Eclipse 2026-03 (Note that it's an external projects so this is probably not the right place for it).

If you want to contribute to the Eclipse IDE, there's a starting point at https://github.com/eclipse-ide.
You can also get help in the Eclipse IDE newcomers channel on https://chat.eclipse.org and if you want to, you can also contact me directly via Discord (you should be able to find a way for that on my GH profile) but note that I'm by no means an expert when it comes to Eclipse development.

@totomomo18

Copy link
Copy Markdown

Just wanted to give you a last update. I just finally succeeded to update my Sts 5.01 to the latest version and tested your new feature on my real code. I press show only selected element on a method and then tried the folding on a couple of big ifs and tries and it worked perfectly (With even closing } that was a problem) Thank You.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants