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

x/tools/gopls: organizeImports adds package line when fixing code on line after existing package line #38815

Open
zikaeroh opened this issue May 2, 2020 · 1 comment
Labels
Milestone

Comments

@zikaeroh
Copy link
Contributor

@zikaeroh zikaeroh commented May 2, 2020

Please answer these questions before submitting your issue. Thanks!

What did you do?

Had code like:

package main
var x = fmt.Sprintf("")

Then saved in VS Code, which does formatting and fixes.

What did you expect to see?

package main

import "fmt"

var x = fmt.Sprintf("")

What did you see instead?

package main

import "fmt"
package main
var x = fmt.Sprintf("")

If there's an empty line after the package line, things work fine.

LSP logs: https://gist.github.com/zikaeroh/3618c7cf2a982ade74dc83a89de5da5c

[
    {
        "title": "Organize Imports",
        "kind": "source.organizeImports",
        "edit": {
            "documentChanges": [
                {
                    "textDocument": {
                        "version": 26,
                        "uri": "file:///home/jake/testproj/badline/main.go"
                    },
                    "edits": [
                        {
                            "range": {
                                "start": {
                                    "line": 0,
                                    "character": 0
                                },
                                "end": {
                                    "line": 0,
                                    "character": 0
                                }
                            },
                            "newText": "package main\n\nimport \"fmt\"\n"
                        }
                    ]
                }
            ]
        }
    }
]

Build info

golang.org/x/tools/gopls master
    golang.org/x/tools/gopls@v0.0.0-20200501205727-542909fd9944 h1:20iD9K4bJEslXfAAA7dvM3nxxnR5TtBYjsLg24tqBiY=
    github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
    golang.org/x/mod@v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ=
    golang.org/x/sync@v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=
    golang.org/x/tools@v0.0.0-20200501205727-542909fd9944 h1:H2fcUfqnOlhuExePgcxfMRf98XwAWOF2pqkJTFTc2z0=
    golang.org/x/xerrors@v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
    honnef.co/go/tools@v0.0.1-2020.1.3 h1:sXmLre5bzIR6ypkjXCDI3jHPssRhc8KD/Ome589sc3U=
    mvdan.cc/xurls/v2@v2.1.0 h1:KaMb5GLhlcSX+e+qhbRJODnUUBvlw01jt4yrjFIHAuA=

Go info

go version go1.14.2 linux/amd64

@gopherbot gopherbot added this to the Unreleased milestone May 2, 2020
@gopherbot gopherbot added the Tools label May 2, 2020
@gopherbot
Copy link

@gopherbot gopherbot commented May 2, 2020

Thank you for filing a gopls issue! Please take a look at the Troubleshooting guide, and make sure that you have provided all of the relevant information here.

@gopherbot gopherbot added the gopls label May 2, 2020
@stamblerre stamblerre modified the milestones: Unreleased, gopls/v0.5.0 May 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.