netbeans icon indicating copy to clipboard operation
netbeans copied to clipboard

Fix code-folding for LSP clients that support line-folding only

Open sid-srini opened this issue 1 year ago • 3 comments

  1. Added TextDocumentServiceImpl.convertToLineOnlyFolds which:

    • accepts code-folds specified as fine-grained Position-based (line, column) ranges, and,
    • changes them to coarse-grained line-only ranges.
    • The line-only ranges computed uphold the code-folding invariant that: a fold does not end at the same point where another fold starts.
  2. This is used in TextDocumentServiceImpl.foldingRange() when the client capabilities have FoldingRangeClientCapabilities.lineFoldingOnly = true.

Symptoms of this issue maybe seen in oracle/javavscode#249.

sid-srini avatar Sep 13 '24 05:09 sid-srini

On a (relatively) quick review, this seems OK to me. But, I would say the convertToLineOnlyFolds method is quite complex, and some tests would be desirable. Round-trip test (like those in ServerTest) would not be bad, but this method could be also tested in a unit-test way. E.g. the method could be package-private and static, and called directly from the test(?)

lahodaj avatar Sep 13 '24 14:09 lahodaj

On a (relatively) quick review, this seems OK to me. But, I would say the convertToLineOnlyFolds method is quite complex, and some tests would be desirable. Round-trip test (like those in ServerTest) would not be bad, but this method could be also tested in a unit-test way. E.g. the method could be package-private and static, and called directly from the test(?)

Thanks @lahodaj for taking a quick look at this draft PR. I intended to add the unit tests before making it ready-for-review. :)

sid-srini avatar Sep 13 '24 18:09 sid-srini

I added the unit test for this enhancement. @lahodaj - Please review whenever you get a chance. Thank you.

sid-srini avatar Sep 23 '24 10:09 sid-srini

@lahodaj Request you to please facilitate in reviewing this PR. Thank you.

sid-srini avatar Oct 24 '24 23:10 sid-srini

Looks OK to me. Thanks!

Thank you very much.

sid-srini avatar Oct 25 '24 08:10 sid-srini

Unless there are objections, I'll merge tonight.

lahodaj avatar Oct 25 '24 08:10 lahodaj

The LSP ServerTest. testCodeFolding and ServerTest.testPullUp seem to be failing in the merge tests run due to an NPE since NbCodeClientCapabilities.getClientCapabilities() is null for the unit tests.

I was trying to look to this PR's github workflow actions but could not find it. I am not sure why the github actions didn't run on the PR. I am very sorry for this unit tests breakage.

I will need to add the following fix to TextDocumentServiceImpl

            lineFoldingOnly = client != null
                    && (nbCodeCapabilities = client.getNbCodeCapabilities()) != null
                    && (clientCapabilities = nbCodeCapabilities.getClientCapabilities()) != null
                    && (textDocument = clientCapabilities.getTextDocument()) != null
                    && (foldingRange = textDocument.getFoldingRange()) != null
                    && Objects.equals(foldingRange.getLineFoldingOnly(), Boolean.TRUE);

sid-srini avatar Oct 29 '24 07:10 sid-srini

How about this: https://github.com/apache/netbeans/pull/7921

lahodaj avatar Oct 29 '24 07:10 lahodaj

Thank you very much @lahodaj.

sid-srini avatar Oct 29 '24 08:10 sid-srini

I am not sure why the github actions didn't run on the PR.

I am also not completely sure what happened here. But it looks like the last change to this branch was about a month ago, and github didn't add the green check mark there. This could mean that the CI-run was waiting to be approved for this PR and nobody pressed the button? But this is just a guess - could be something else.

image

here our PR review / merge check list as reminder: https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=240884239#PRsandYouAreviewerGuide-PRapprovalchecklist

in particular:

did the right tests run? When did they run?

mbien avatar Oct 29 '24 16:10 mbien