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

Code formatting jumps around #1096

Closed
sascha-andres opened this issue Jul 19, 2017 · 9 comments
Closed

Code formatting jumps around #1096

sascha-andres opened this issue Jul 19, 2017 · 9 comments

Comments

@sascha-andres
Copy link

sascha-andres commented Jul 19, 2017

  • VSCode Version: 1.14.1

  • OS Version:

    Linux HGL-049 4.8.0-58-generic Analysis tool install broken #63~16.04.1-Ubuntu SMP Mon Jun 26 18:08:51 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

    DISTRIB_ID=neon
    DISTRIB_RELEASE=16.04
    DISTRIB_CODENAME=xenial
    DISTRIB_DESCRIPTION="KDE neon User Edition 5.10"

Since the VSCode 1.14.1 Update the formatting of go code in larger files ( file used has 113 lines ) jumps around and slects text which then easily gets overwritten. I made a screen recording as this will probably make it easier to understand my point

Screen recording

Reproduces without extension: No

@fyndor
Copy link

fyndor commented Jul 30, 2017

Yea this is super annoying and in my opinion makes writing go code impossible in VS Code. One fix I have found is turning off auto save but then you lose a lot of instant gratification of the extension telling you when you are writing improper code etc. I think this is a really important bug to fix.

Edit: By the way I don't have a large file (i.e. hello world sample) and it is still an issue.

@ramya-rao-a
Copy link
Contributor

@sascha-andres, @fyndor

Sorry, this issue somehow got lost in the sea of notifications I currently have.

Do you have any of the editor.formatOn... settings turned on?

@sascha-andres
Copy link
Author

sascha-andres commented Aug 4, 2017

My go specific settings:

  // go extension
  "go.enableCodeLens": {
      "references": true,
      "runtest": true
  },
	"go.lintTool": "golint",
  "go.lintOnSave": "package",
  "go.useLanguageServer": false,
  "go.buildOnSave": "package",
  "go.vetOnSave": "off",
  "go.buildTags": "",
  "go.buildFlags": [],
  "go.lintFlags": [],
  "go.vetFlags": [],
  "go.coverOnSave": false,
  "go.useCodeSnippetsOnFunctionSuggest": false,
  "go.formatOnSave": true,
  "go.formatTool": "goimports",
  "go.gocodeAutoBuild": false,

Edit: I even tried to switch to gofmt but the behavior is still reproducible.

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Aug 4, 2017

@sascha-andres My question was around the format settings for the editor like editor.formatOnSave, editor.formatOnPaste, editor.formatOnType. Have you enabled any of these?

@sascha-andres
Copy link
Author

@ramya-rao-a No I do not have any editor.format... set. My editor. settings:

  // editor settings
  "editor.fontFamily": "Fira Code",
  "editor.fontSize": 16,
  "editor.fontLigatures": true,
  "editor.tabSize": 2,
  "editor.useTabStops": true,
  "editor.minimap.enabled": true,

@ramya-rao-a
Copy link
Contributor

@sascha-andres Can you disable all other extensions you have and try again? There have been cases when operations from other extensions interfere with the save cycle and triggering edits -> save -> format again.

@sascha-andres
Copy link
Author

sascha-andres commented Aug 4, 2017

@ramya-rao-a Done this but nothing has changed

@ramya-rao-a
Copy link
Contributor

I have a repro after spending an hour on this. Finally!

The root cause is that formatOnSave feature uses the TextEditorEdit api to apply the formatting edits on the file.
Edits made this way have this issue of ending up selecting part of the text that the cursor is on.

I have logged an upstream bug for this in VS Code:
microsoft/vscode#32058

To fix the issue from the Go extension's side, I have updated to use WorkspaceEdit api instead.

The fix will be out in the next update.

Thanks for logging the issue and being patient with me :)

@ramya-rao-a
Copy link
Contributor

The fix for this is now out in the latest update to the Go extension 0.6.64

@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 23, 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

3 participants