Code Monkey home page Code Monkey logo

Comments (10)

David-Else avatar David-Else commented on June 30, 2024 1

Thanks for adding me as a contributor, I have not seen it done in this way on Github, nice :)

I am working through Refactoring: Improving the Design of Existing Code (2nd Edition), and it is amazing! The more of that that can be automated the better... I can see things getting pretty complicated for the advanced ones, but I dream of a day you can press a button and perform all the complex logic refactorings automatically... that really would be magic!

from abracadabra.

David-Else avatar David-Else commented on June 30, 2024 1

@nicoespeon Hello. I just wanted to add that this issue will hopefully become a non issue with the next update of VS Code, they are adding refactor preview! This is going to be the best update for VS Code refactoring for a long time, so I hope it will all work well with your extension :)

https://github.com/microsoft/vscode/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+Refactor+preview

from abracadabra.

nicoespeon avatar nicoespeon commented on June 30, 2024

Thanks for this very nice bug report @David-Else πŸ‘

I'll investigate what's going on 🧐

from abracadabra.

nicoespeon avatar nicoespeon commented on June 30, 2024

@all-contributors please add @David-Else for bug

from abracadabra.

allcontributors avatar allcontributors commented on June 30, 2024

@nicoespeon

I've put up a pull request to add @David-Else! πŸŽ‰

from abracadabra.

nicoespeon avatar nicoespeon commented on June 30, 2024

You're welcome, I like how all-contributors acknowledge for all kind of contributions. Raising up relevant bugs helps a lot!

And yes, Refactoring 2nd Edition has a strong influence on the development of this extension. My former experience with IntelliJ refactorings too. As you said, advanced refactorings are not easy, but when there is a recipe it can be automated and save us so much time πŸ˜„

from abracadabra.

nicoespeon avatar nicoespeon commented on June 30, 2024

I gave this one more thoughts.

TL;DR:

  • that's indeed a problem
  • it's hard to solve and I don't think it's a frequent one
  • so I won't fix it and I'm closing the issue
  • but I'm open to further feedbacks, ideas or PRs to help me solve that

Detailed explanations

When we do the refactoring, we insert the code, then we mutate the selection to put the cursor at the correct position:Β 

// Put cursor at correct position
this.editor.selection = newCursorPosition
? toVSCodeCursor(newCursorPosition)
: cursorAtInitialStartPosition;

When we "undo" (Ctrl+Z), then "redo" (Ctrl + ⇧ + Z) the refactoring, it doesn't redo that mutation. So the code is inserted again, but the cursor ends up at the end of the newly inserted code. Because most refactorings would rewrite the whole code (preserving what wasn't modified), the cursor is likely to end up at the end of the file.

I don't know how to make the "redo" understands the selection mutationβ€”if that's even possible.

The only way I see to kinda-fix this would be to fine tune each refactoring so they only insert code that changed instead of the whole code. But that's much more complex to do it (properly). And even with this, I think the cursor would still end up further than we would expect.

That's why, considering this happens when you "undo", then "redo" a refactoring and knowing the complexity of the fix, I will not fix it unless:

  • Many people report that this is a problem for them because they undo-redo refactorings
  • Someone come up with a simpler idea to fix this (or a PR)

from abracadabra.

David-Else avatar David-Else commented on June 30, 2024

Thanks for the detailed info!

from abracadabra.

nicoespeon avatar nicoespeon commented on June 30, 2024

You're welcome. That's only fair to explain why I'm closing this. I don't have a good solution in mind yet and I don't want this to stay open for 2 years without any feedback.

Sorry I couldn't help more for this. I hope I (or someone) will find a simple way to fix that πŸ€·β€β™‚

from abracadabra.

nicoespeon avatar nicoespeon commented on June 30, 2024

@David-Else that sounds great indeed πŸ‘

I can see they're working on improving the way refactorings are provided to the users. That's nice. That will probably mean less custom implementation here for more native solutions (e.g. a keybinding to see the list of available refactorings under the cursor position).

from abracadabra.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.