Coder Social home page Coder Social logo

:GoFmt on :w mess with Vim :redo about vim-go HOT 32 CLOSED

fatih avatar fatih commented on May 20, 2024
:GoFmt on :w mess with Vim :redo

from vim-go.

Comments (32)

oblitum avatar oblitum commented on May 20, 2024

I think, if there's no solution for this, people should be warned about this when using auto formatting on saving the file. I'll stop using it, as I have given up once before, because undo & redo is more important for me =)

from vim-go.

fatih avatar fatih commented on May 20, 2024

Well first you don't have to use it if you don't want it. But thanks for pointing out this bug. I wasn't aware of this. Therefore you shouldn't be angry to me, which I think you are and I found your tone not good.

If people don't want to use that's their business, however people do like this plugin and they try to help me and also contribute to this plugin. You could try to contribute instead of being sad or angry.

However I've looked add this and seems andrews repo fixes this, here is an experimental branch test it out and see if it works for your:

https://github.com/fatih/vim-go/tree/experimental-fmt (i've pushed quickly, it's not the final version)

from vim-go.

oblitum avatar oblitum commented on May 20, 2024

I'm really not angry, pardon if I sounded so... as you may see, I myself was once in the same trap.

from vim-go.

oblitum avatar oblitum commented on May 20, 2024

I'll check if it works, regarding "that's their business", what I think is that people should be aware of the behavior while it's not fixed, through a notice or documentation. Even more because it's ON by default. I know what was happening when I was editing my files (because of previous knowledge in these matters), but other people may end up having to figure out what is happening with their editor.

from vim-go.

fatih avatar fatih commented on May 20, 2024

Yes, but it can be disabled, it has settings, the source code is open. There are so many options. If you don't want to use autofmt just disable it :)

let g:go_fmt_autosave = 0

Ever behavior in this plugin has also a disable settings which is intended solely for this purpose, to give users the choice to do what they want.

from vim-go.

oblitum avatar oblitum commented on May 20, 2024

What I'm trying to say is that, I woudn't go for disabling this if there wasn't this issue, and if I had already known upfront there was such an issue, I wouldn't even let it enabled. Anyway... I think I'm done, it sounds like you is mad not me. What I said is just the truth, knowledge of an issue may be useful for the user to make the choice of enabling it or not, instead of figuring it out, even more because I think I have seen some statements regarding the plugin not messing with undo history.

from vim-go.

fatih avatar fatih commented on May 20, 2024

I'm not mad. I'm trying to solve this problem, that's it. Did you try the branch? If yes we can fix it from there.

from vim-go.

oblitum avatar oblitum commented on May 20, 2024

Yes, it looks like it solves the issue, the solution seems like the more recent and second most upvoted answer on SO, which I suggested as the chosen answer if it worked out better than my approach.

from vim-go.

fatih avatar fatih commented on May 20, 2024

The current master is the same as in SO's second answer :/ There is no difference, just I also display the error results.

from vim-go.

oblitum avatar oblitum commented on May 20, 2024

@fatih ah, ok then, my bad...

from vim-go.

fatih avatar fatih commented on May 20, 2024

The experimental branch unfortunately is losing the cursor position.

from vim-go.

oblitum avatar oblitum commented on May 20, 2024

I didn't notice where that happens yet. Maybe this is unsolvable in Vim (I have given up autofmt before because I felt the same).

from vim-go.

fatih avatar fatih commented on May 20, 2024

To reproduce it do 4-5 changes and then only undos. You will see that the cursor will jump to the beginning of the file.

from vim-go.

oblitum avatar oblitum commented on May 20, 2024

ah ok, in truth I could reproduce this with just one change that would actually produce reformatting when saving, like a single extra space before some closing parentheses.

from vim-go.

clutchski avatar clutchski commented on May 20, 2024

It would be great to see a fix land for this. Thanks for the plugin.

from vim-go.

fatih avatar fatih commented on May 20, 2024

@oblitum @clutchski could you please the fmt branch https://github.com/fatih/vim-go/tree/fmt ? It has some changes that I believe fixes the problem but I'm still working on that. This is a Vim problem that is not easily solvable unfortunately.

from vim-go.

oblitum avatar oblitum commented on May 20, 2024

@fatih I'm not catching gaps in undo history as before yet, but the cursor still jumps to top of file when undoing/redoing.

from vim-go.

fatih avatar fatih commented on May 20, 2024

@oblitum that's not the case for me anymore. Wonder if something is causing this.

from vim-go.

oblitum avatar oblitum commented on May 20, 2024

@fatih

Opening a file with this content:

package main

import (
    "fmt"
)

func main() {
    fmt.Println("Hello" )
}

and issuing :w will cause the space after "Hello" to vanish, if you do undo after :w you go to top of file. This would also happens if I had a longer editing history.

from vim-go.

fatih avatar fatih commented on May 20, 2024

But you are creating a new file without any undo history. It's normal that it goes to the top. If you do the same, and change to Hello to Rello, if you do now undo it will not go to the top. Instead it will jump to H.

from vim-go.

oblitum avatar oblitum commented on May 20, 2024

@fatih As I said, this also happens if I had a longer editing history. Just edit the file, maybe changing the message, save it with :w, then add that extra space, save it, it will get fixed, now undo, you go back and forth from the top of the file.

from vim-go.

oblitum avatar oblitum commented on May 20, 2024

in sum, this inserts jumps to top of file in undo history when there's any refomatting on saving.

from vim-go.

fatih avatar fatih commented on May 20, 2024

Ok can you to pull again and try? Seems I was missing a line from the master that was not removing the undo point causing via bufwritepre.

from vim-go.

fatih avatar fatih commented on May 20, 2024

You can follow the commits from this PR btw: #150

from vim-go.

oblitum avatar oblitum commented on May 20, 2024

@fatih it seems to be working nice now, I can't find issues at the moment.

from vim-go.

oblitum avatar oblitum commented on May 20, 2024

ops, it's not in master yet but I've closed the issue.

from vim-go.

fatih avatar fatih commented on May 20, 2024

That's an awesome news! After nearly 4 months seems it's beeing fixed. Yes it's not in master but going to merge sooin. I would be happy if you could use it 1-2 days and let's merge that branch than. Thanks for the valuable feedback @oblitum .

from vim-go.

oblitum avatar oblitum commented on May 20, 2024

@fatih ok no problem but sadly I'm not writting much Go lately so I won't be able to give feedback because I would be coding in Go because I'm not :-/

from vim-go.

fatih avatar fatih commented on May 20, 2024

Ok nevermind :) I have announced it on twitter and I'm also testing it heavily.

from vim-go.

mitermayer avatar mitermayer commented on May 20, 2024

I am facing similar problem with vim-prettier used similar fixed as this to solve the “undo” but the “redo”from an undo of formatted coded still takes cursor to the top.

Does this behaviour also occurs here too ?

from vim-go.

oblitum avatar oblitum commented on May 20, 2024

@mitermayer vim-go is one of the few plugins that got this right (the only one at the time), even though I don't use it anymore, I tested it extensively, and reported it as a model for many other plugins that had the same issue. Not sure whether it's rock solid as before, but fatih came up with a solution after a good time of fiddling.

from vim-go.

bhcleek avatar bhcleek commented on May 20, 2024

@mitermayer vim-go does not suffer from that problem. The code hasn't changed much since the solution that @oblitum mentions. You can find the code that deals with undo in https://github.com/fatih/vim-go/blob/master/autoload/go/fmt.vim

from vim-go.

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.