Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextEdit[] returned from provideDocumentFormattingEdits doesn't behave correctly? #144

Closed
lukehoban opened this issue Nov 19, 2015 · 3 comments
Assignees
Labels
important Issue identified as high-priority verified Verification succeeded

Comments

@lukehoban
Copy link
Contributor

I'm trying to determine the root cause of microsoft/vscode-go#16, but I don't see any problem with the TextEdit object I'm providing back to the provideDocumentFormattingEdits. It seems that in some cases Code will corrupt the buffer in odd but deterministic ways.

I haven't been able to pin down the exact incorrect behaviour, but two example:

Example 1
Before text:

package caddy\n\nfunc main() {\n\tfmt.Println("Hello World! :)")\n}\n

Then replace the full range with:

package caddy\n\nimport "fmt"\n\nfunc main() {\n\tfmt.Println("Hello World! :)")\n}\n

The result will be

package caddyimport "fmt"func main() {\n\tfmt.Println("Hello World! :)")\n}\n

Example 2
Before text:

package caddy\n\nfunc main() {\n    fmt.Println("Hello World! :)")\n}\n

Then replace the full range with:

package caddy\n\nimport "fmt"\n\nfunc main() {\n\tfmt.Println("Hello World! :)")\n}\n

The result will be

package caddy\n\nimport "fmt"\n\nfunc main() {\n\tfmt.Println("Hello World! :)")\n}\n

Note that the only difference between these examples is the "\t" vs " " in the original text. The result in Example 1 has corruption in the string result in a seemingly random location.

Two question:

  1. Is this a bug in the extension API, or am I somehow calling it wrong?
  2. If it's a bug, is there any workaround?
@lukehoban
Copy link
Contributor Author

@alexandrudima @bpasero Any thoughts on this? Any chance there is a workaround? This is currently blocking addressing the top piece of feedback on vscode-go and I'm not sure how to workaround it.

@egamma egamma assigned jrieken and alexdima and unassigned alexdima and jrieken Nov 24, 2015
@egamma egamma added this to the Nov 2015 - end milestone Nov 24, 2015
@alexdima
Copy link
Member

TL;DR; It is an issue in the formatCommand.ts edit trimming. A fix is on the way in the November recovery drop.

The format command tries to do some smart front/rear trimming of edits to reduce edit ranges. E.g.

Given a buffer containing "some cool cool text"
replace [0,19] with "some cool cool text" => no-op
replace [0,19] with "something interesting" => replace [4,19] with "thing interesting"
replace [0, 19] with "some interesting text" => replace [5,14] with "interesting"
It had a bug when prefix & suffix overlap. e.g.:
replace [0, 19] with "some cool and cool text" => invalid edit
replace [0, 19] with "some cool text" => invalid edit

You can either wait for our recovery drop due end of this week or early next week or you can try to massage the edits on your side such that there is no prefix & suffix overlap. Removing the same prefix would already work.

@pali88
Copy link

pali88 commented Nov 24, 2015

616b9ad

alexdima added a commit that referenced this issue Nov 24, 2015
@alexdima alexdima assigned egamma and unassigned alexdima Nov 25, 2015
@egamma egamma added the verified Verification succeeded label Nov 25, 2015
@bpasero bpasero added the important Issue identified as high-priority label Nov 25, 2015
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
important Issue identified as high-priority verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

6 participants