Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Cursor jump unexpectedly #1346

Closed
maxint64 opened this issue Nov 16, 2017 · 30 comments
Closed

Cursor jump unexpectedly #1346

maxint64 opened this issue Nov 16, 2017 · 30 comments

Comments

@maxint64
Copy link

After the latest update of vscode-go, I found my cursor would move unexpectedly, the cursor might jump to end of line or bottom of file suddenly when I'm coding. I use vscode-go and vscode-vim together, and the problem appears more frequently when I move cursor past a bracket (including (), {}, []).
I guess there may be something conflict. I close vscode-vim and open vscode-go, cursor move unexpectedly yet. When I close vscode-go and keep using vscode-vim, everything is ok. It's very strange.
Thank you for any suggestion!

@maxint64 maxint64 changed the title Cursor moves unexpectedly Cursor jump unexpectedly Nov 16, 2017
@zhao-kun
Copy link

I have the same issue as you, I also used vscode-go and vscode-vim. But when I modified the user settings "files.autoSave": "off", the problem was solved.

@maxint64
Copy link
Author

@zhao-kun Thank you very much!

@ramya-rao-a
Copy link
Contributor

This is weird. The only thing happening on save that can move stuff around is the formatting feature.

I can repro the case when the cursor moves to the next line, but not the case when the cursor moving to the bottom of the file.

Can either of you provide a small sample code with repro steps for when you see the cursor going to the end of the file?

@ramya-rao-a
Copy link
Contributor

I have pushed the fix for the issue that I see i.e cursor jumping to the next line.

Can either of you test it and see if it solves your case as well? All you have to do is

ramya-rao-a added a commit that referenced this issue Nov 19, 2017
@ramya-rao-a
Copy link
Contributor

Scratch that.

I can repro the case when the cursor jumps to the last line.
It is when the changes due to formatting spans multiple lines till the end of the document.

The root cause is due to changes in the core api. I'll dig around a little more and get back here.

@maxint64
Copy link
Author

@ramya-rao-a I tried your extension but the problem still exists. I did more test and found cursor will certainly jump to end of file after saving, no matter which way I use (click save button, press ctrl+s, or use vim command :w)

@ramya-rao-a
Copy link
Contributor

@maxint64 Thanks. I found today that the root cause is with the way edits are applied by VS Code. Something changed between VS code 1.17 and 1.18 release.
I have logged an upstream issue for this. microsoft/vscode#38728
We should be able to get a fix in the Insiders soon.

Until then, the work around is to either disable the format on save feature or the auto save feature.
There is no fix to be done from the Go extension's side

@Xjs
Copy link

Xjs commented Nov 27, 2017

@ramya-rao-a Just a quick hint that after your changes introduced in 89e1a18 the curser no longer moves to the end but to the beginning of the file when formatting-on-save.

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Nov 27, 2017

@Xjs I know... Its a temporary fix. I figured cursor moving to start of the same line is a just a little bit less annoying than it moving to the end of the file.

Previously, the edits being applied were multi line edits
Right now the edits being applied are single line

The right fix would require us to apply edits only for the part of the line that needs the change which is slightly more complicated as the Go tools only return diffs at line level

@Hokutosei
Copy link

any updates on this guys? I had to scroll back up to the line where I am editing on a Go file with like 1k lines..

@ramya-rao-a
Copy link
Contributor

@Hokutosei Update to the latest version of the Go extension (0.6.69). The cursor wouldn't go to end of file, but to the start of the line on save if formatting changes exist.

Other workaround is to disable the format on save feature until we get a complete fix for this issue

@imlinax
Copy link

imlinax commented Nov 30, 2017

I have already up to the latest verion of Go extension(0.6.69), but the cursor still go to end of file.
OS: mac 10.13.1
go for vscode:0.6.69
vscodevim:0.10.5

@Hokutosei
Copy link

@ramya-rao-a oh god..I have updated it already to 0.6.69 . I guess I have to wait for the fix. currently, I am editing somewhere on 500th line, and hit save, my cursor will go to top (not start of the line) and click back again to where I am editing.. why is this even happening? before, I did not have any problems.

I can't disable formatting on save this time. this is part of my workflow..

thanks for the help btw.. looking forward for the fix.

@ramya-rao-a
Copy link
Contributor

The root cause is that there has been a change in VSCode in the way it treats the edits returned by extensions. If extension returns an edit/edits across contiguous group of lines, the cursor moves to the last line of this group. This was what was happening in Go 0.6.68

You can see the upstream issue at microsoft/vscode#38728

For Go 0.6.69 I made a change so that the extension returns one edit per line instead of one edit per contiguous group of lines.

I would strongly suggest disabling format on save and run formatting manually once in a while

@Hokutosei
Copy link

sorry but any fix on this? as far as I am looking on the upstream issue, there seems to be no fix unless the author of this plugin fix the formatting issue that VSCode created.

first, this should have not been a problem if VSCode did not change the way it treats the edits.

so now what,. disable the format:onSave? maybe no. this was a good plugin, it helped me alot and many others I would suppose.

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Dec 7, 2017

first, this should have not been a problem if VSCode did not change the way it treats the edits.

VS Code did change the way it treats edits.

any fix on this

We are close to releasing the next update for VS Code, therefore I was busy and couldn't devote much time to this issue or the Go extension.

But, now I am working on this as we speak. The fix requires the Go extension to enable running formatting tools on the file contents (pass via stdin) instead of saving the file and then running the tools on the file on disk.

The formatting tools (goimports and goreturns) have 2 issues with this approach. See #613 and #630. Which is why I abandoned my previous effort last year to make this change.

After my investigations today, I found that the use of the new flag -srcdir in goimports which fixes #613, fixes both the #630 as well. Now the only remaining blocker is to get support for the same in goreturns

Long story short, you can expect a fix soon. I'll try for end of week.

so now what,. disable the format:onSave?

Until the fix, you can disable the format on save feature and run format manually when needed

@Hokutosei
Copy link

@ramya-rao-a accepted. sorry for the rant. I am looking forward for the fix, and yeah I guess I'll be waiting until next week maybe..hopefully.

thank you again for the help.

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Dec 7, 2017

@Hokutosei and others on this thread,

I have the fix ready, can you help me with testing? You will have to

"go.formatTool": "goimports",
"[go]": {
    "editor.formatOnSave": true
  }
  • Run Go: Install/Update tools to ensure you have goimports installed.

Issues #613 and #630 will still exist if you use goreturns. Therefore, use goimports as the formatting tool instead

@Nick-Lucas
Copy link

^ looks like that fixed it, though the install command didn't work for me (on Windows), it just launched Code without installing the tool.

I followed these steps to be sure:

  • Uninstall Go extension from Code
  • Restart Code
  • Use the Code extensions manager to "install from VSIX"
  • Replace settings with the above

It then appears to be fixed. Thanks so much for this :)

@ramya-rao-a
Copy link
Contributor

though the install command didn't work for me

Oh sorry, there was a typo there. It should be --install-extension not --install-extensions.

It then appears to be fixed. Thanks so much for this

Awesome!

@Hokutosei
Copy link

@ramya-rao-a sorry for the super late reply. I have tried your fix

$ code --install-extension Go-latest.vsix
Extension 'Go-latest.vsix' was successfully installed!

updated my settings, and I am glad to report to you that it fixed the problem. I am glad I don't have to scroll back again up/down from a huge Go file.

thank you so much :)

@julianfrank
Copy link

I'm getting the following error

$ code --install-extension Go-latest.vsix
Error: end of central directory record signature not found
    at D:\Program Files\Microsoft VS Code\resources\app\node_modules\yauzl\index.js:183:14
    at D:\Program Files\Microsoft VS Code\resources\app\node_modules\yauzl\index.js:618:5
    at D:\Program Files\Microsoft VS Code\resources\app\node_modules\fd-slicer\index.js:32:7
    at FSReqWrap.wrapper [as oncomplete] (fs.js:629:17)

@ramya-rao-a
Copy link
Contributor

@julianfrank I've seen that issue for a few users on Linux. Clone the vscode-go repo and get the file from there.

@julianfrank
Copy link

I'm on Windows 10 home ... Do I still need to use the clone and compile?

@ramya-rao-a
Copy link
Contributor

You don't need compile. Just clone and use the Go-latest.vsix file from the cloned repo as per instructions in #1346 (comment)

@pharrisee
Copy link

Can also confirm that the Go-latest.vsix installation and config change fixed the issue for me.

Woohoo!

:)

@ramya-rao-a
Copy link
Contributor

The latest update to the Go extension (0.6.70) has this fix.

Thanks for the patience everyone!

@apang1992
Copy link

Thank you very much for your excellent work! I have just upgraded the extension :-)

@maxint64
Copy link
Author

Thank you!

@julianfrank
Copy link

The whole jumping has stopped for me.... Thanks

@vscodebot vscodebot bot locked and limited conversation to collaborators Feb 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants