-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Don't replace entire module and file nodes when inserting imports #6287
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
Conversation
|
Would returning |
|
SyntaxRewriter doesn't have any insertion logic yet from what I've seen which was why I didn't consider it I think. On a second thought it would probably make a lot more sense to have this use a |
|
I don't think a |
It can't model them now, but it makes sense to extend it to allow this. Implementation wise, rewrite_children function can look into some auxilary map to decide if it needs to appaend element to new_children That is, we can add and that might do the trick? |
|
Oh alright, I wasn't sure whether I should touch that part or not, but in that case I'll take another look at |
|
Nothing in rust-analyzer is completely complete :)
…On Tue, 20 Oct 2020 at 20:23, Lukas Wirth ***@***.***> wrote:
Oh alright, I wasn't sure whether I should touch that part or not, but in
that case I'll take another look at SyntaxRewriter
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#6287 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AANB3M6EFCVGVOT3USBCCG3SLXIQ3ANCNFSM4SWK4LAA>
.
|
|
I just realized the problem with using Unless I also do changes to |
6251: Semantic Highlight: Add Callable modifier for variables r=matklad a=GrayJack This PR added the `HighlightModifier::Callable` variant and assigned it to variables and parameters that are fn pointers, closures and implements FnOnce trait. This allows to colorize these variables/parameters when used in call expression. 6310: Rewrite algo::diff to support insertion and deletion r=matklad a=Veykril This in turn also makes `algo::diff` generate finer diffs(maybe even minimal diffs?) as insertions and deletions aren't always represented as as replacements of parent nodes now. Required for #6287 to go on. Co-authored-by: GrayJack <gr41.j4ck@gmail.com> Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
6365: Do insertion lookahead in algo::diff r=matklad a=Veykril This is the last blocker for #6287 after this I can update that PR to properly fix things through using `SyntaxRewriter`. This PR also shuffles tests around a bit and adds some more. Ideally this is just a hack until we implement a "proper" diff algorithm that approximates a minimal diff. Maybe something like [gumtree](https://github.com/GumTreeDiff/gumtree)? Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
bfc35c9 to
cd349db
Compare
|
Alright, updated this PR to my recent changes and tested the server locally. It now does not move the cursor in imports anymore 🎉 I had to rewrite |
|
Perfect, thanks! Rewrite of bors r+ |
|
Do you think it's possible to somehow insert the first import without rewriting the whole file? #[test]
fn first_use_added() {
check_diff(
r#"fn main() {
stdi<|>
}"#,
r#"use foo::bar;
fn main() {
stdi<|>
}"#,
expect![[r#"
insertions:
Line 0: Node(SOURCE_FILE@0..25)
-> use foo::bar;
-> "\n\n"
replacements:
deletions:
"#]],
);
}and instead I get the diff. |
|
I'm not sure, maybe with some special handling. The problem is what an insertion really means for diffing here, currently it just checks if the node in the original tree still exists in the new tree, then it marks everything between as insertions, otherwise it marks stuff as replacements. Prior to my changes this just replaced the whole parent node, so when fiddling with imports you'd just get a SOURCE_FILE replacement everytime. Edit: Hm actually this should already mark that as in insertion since the fn main node is still the same isnt it? thats weird |
|
It does mark it so, but the condition I'm not well familiar with syntax trees and the proper ways to make things work here, but interested to find some solution to this so appreciate any pointers or fixes 🙂 |
|
Yes I just noticed that again as well, insertions are anchored after elements, so if the first element is whats being inserted we have a problem here. Maybe we just gotta keep track of elements that are to be inserted directly into their parent as the first child in a separate Field in I could give it a try sometime later today unless you wanna experiment. |
|
You're definitely better than me in this, so go ahead if you want to. |
6512: Don't replace parent node when inserting as first child in algo::diff r=SomeoneToIgnore a=Veykril This makes the diff a bit more detailed. See #6287 (comment) for context cc @SomeoneToIgnore Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This change minifies the resulting diff of import insertions by inserting or replacing the produced use tree directly through an
actionreturn value instead replacing the entire container node. This action has to be applied by the caller now. This unfortunately pulls theAssistBuilderinto scope ofinsert_useback again but I tried to at least keep it away from theinsert_usefn itself.I'm open to more/better ideas regarding this :)
Fixes #6196