-
Notifications
You must be signed in to change notification settings - Fork 28.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
simplify fold merging #155302
simplify fold merging #155302
Conversation
Hi @aeschli, I'm not comfortable with some of those changes to the merge routine. Some of them are just removing unnecessary code given the assumption that the second parameter is always the currently folded ranges. I wrote the code with an eye toward it being more general and eventually replacing the merge in syntaxRangeProvider with this merge. Because their purpose is the same and the merge in syntaxRangeProvider doesn't catch all bad cases. But removing the currently unnecessary bits is harmless for now, they just may be needed again later. I'm uncomfortable with removing the test "&& nextA.endLineNumber === nextB.endLineNumber" and instead using rangeA whenever the start line number is the same. Two issues: I'm also uncomfortable with removing the two pass logic and the "} else if (nextB.isCollapsed && !nextB.isManualSelection && passNumber === 1) {" section. I think that the new code will now incorrectly keep a folded range in some cases. E.g. start with:
Fold the "if" line. |
I still think we should test for both start and end line number like the original code. Here's an example of why using the newest code. In next image I select a bunch of lines and then ctrl-K-. Only the first few get folded. I think this behaviour will generate a lot of user queries: Regarding the two pass behaviour here's an example of how removing it creates what I think is the wrong behaviour. (This was what I meant with changing "if", sorry, my brain wasn't in gear then.) I think in the following the fold should auto-unfold: One more thing, something else I noticed today in the newest code which I think used to work. In the following image when the manual fold is unfolded, at that moment the fold icons should reappear on the two auto regions. But they don't reappear now until we do something to get the folding provider invoked, when I type "xx" below: |
I continued to work on the PR:
@PieterBranderhorst Giving user folded ranges precedence addresses the issue you mentioned in the first and third gif of comment . The second issue looks ok to me. As mentioned, the range should only expand when after the |
@aeschli That looks good to me in principle, making "userdefined" and "recovered" separate things. I'd have preferred an enum "kind" of { provider, userdefined, recovered } instead of the two bit flags, because isUserDefined and isRecovered should never both be set at the same time. A 3-valued "kind" would be clearer and safer to me. But the bit flags should work. I'm a bit worried about how quickly this is going into release. I don't have time to review it all today. I'll try to later this week. I'm concerned that there may be subtle consequences. One thing I did notice in a quick look at some of the code. I think that the line "isUserDefined: range.isRecovered," in getMemento in foldingRange.ts will result in flipping saved ranges back and forth between types userdefined and recovered every time a save-apply pair of calls happens. |
Thanks for catching this, @PieterBranderhorst. Good idea to replace the bits with an enum. I created #156273. |
@tjx666 |
@aeschli I reviewed the rest of the code changes and didn't see any other problem. The code looks good and is nicely readable. One comment: I see that you re-added a test I had removed. In folding.ts, in restoreViewState, the test for "state.lineCount !== model.getLineCount()". I suggest removing that test again. I removed it because the new checksum tests detect changes with much greater accuracy and I know that some users use folding with log files. Some log files might change between one use and the next by having lines added at the end. With the checksum tests in place we don't need to invalidate saved fold information in that situation and it seems good to keep it. |
Back from vacation.. Thanks @PieterBranderhorst, makes sense, will do, I created #159032 |
Good stuff, thanks @aeschli. I've been watching issues since these folding changes went live and all seems well, nothing has come up. |
Simplifying the merge logic that merges the previously folded ranges with the newly computed ranges.