Skip to content

Conversation

@danthe1st
Copy link
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
Copy link
Contributor

github-actions bot commented Dec 15, 2025

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

danthe1st commented Dec 19, 2025

@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
Contributor Author

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

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

@danthe1st
Copy link
Contributor Author

danthe1st commented Jan 10, 2026

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

vogella commented Jan 11, 2026

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

vogella commented Jan 12, 2026

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

vogella commented Jan 12, 2026

Thanks @danthe1st

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

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

danthe1st commented Jan 13, 2026

@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.

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.

3 participants