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

Format indentation issue? #899

Closed
DT-ZhangJia opened this issue Mar 31, 2017 · 3 comments
Closed

Format indentation issue? #899

DT-ZhangJia opened this issue Mar 31, 2017 · 3 comments

Comments

@DT-ZhangJia
Copy link

VSCode Version: 1.10.2
OS Version: macOS 10.12.3
Extension: Go 0.6.57
Extension add: goreturns/gofmt

Steps to Reproduce:

  1. Type code without indentation.
  2. Leave the cursor after the code.
  3. Format the code (shift+option+f or save when formatOnSave=true).
  4. The cursor will select the last element of that line.
  5. The element selected will be replaced when press return key to change line, so that the code is broken.

fmt

Is there any settings to fix that problem? Really annoying.

@ramya-rao-a
Copy link
Contributor

@DT-ZhangJia hmm, nice catch.

I can repro it, but am not sure what is causing it.

Meanwhile if anyone can help figuring this one out, that would be very much appreciated.

@ramya-rao-a
Copy link
Contributor

Found the root cause!!

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

@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
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants