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/go/ast/astutil: DeleteImport leaves behind inline comments #43291

Closed
zhengxiaowai opened this issue Dec 20, 2020 · 2 comments
Closed
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@zhengxiaowai
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.15.5 darwin/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/hexiangyu.shawn/Library/Caches/go-build"
GOENV="/Users/hexiangyu.shawn/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/hexiangyu.shawn/go/pkg/mod"
GONOPROXY="*.byted.org,*.everphoto.cn"
GONOSUMDB="*.byted.org,*.everphoto.cn"
GOOS="darwin"
GOPATH="/Users/hexiangyu.shawn/go"
GOPRIVATE="*.byted.org,*.everphoto.cn"
GOPROXY="https://go-mod-proxy.byted.org,https://goproxy.cn,https://proxy.golang.org,direct"
GOROOT="/Users/hexiangyu.shawn/go/go1.15.5"
GOSUMDB="sum.golang.google.cn"
GOTMPDIR=""
GOTOOLDIR="/Users/hexiangyu.shawn/go/go1.15.5/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/hexiangyu.shawn/larkcode/astcommon/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/5t/nnz47qfs67q03v3nn_5kv45m0000gn/T/go-build873978903=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

i try use astutil.DeleteImport to delete a import spec, just like:

import (
    "git.xxx.xxx/xx/other" 
    "git.xxx.xxx/xx/common" // i am a common package
)

i want to delete import "git.xxx.xxx/xx/common" with comment, but i got it:

import (
    "git.xxx.xxx/xx/other" 
    // i am a common package
)

What did you expect to see?

import (
    "git.xxx.xxx/xx/other" 
)

What did you see instead?

import (
    "git.xxx.xxx/xx/other" 
    // i am a common package
)

i check golang.org/x/tools/go/ast/astutil/import_test.go, it's same my test.

So,i has a question:

why did delete a import spec which not contain comment?

this Comment Field belong to ast.ImportSpec in source ccode:

// An ImportSpec node represents a single package import.
ImportSpec struct {
    Doc     *CommentGroup // associated documentation; or nil
    Name    *Ident        // local package name (including "."); or nil
    Path    *BasicLit     // import path
    Comment *CommentGroup // line comments; or nil
    EndPos  token.Pos     // end of spec (overrides Path.Pos if nonzero)
}

i think delete a import spec which should delete a full ImportSpec (about comment)

why was it designed this way?

Looking forward to your reply, Thanks.

@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Dec 20, 2020
@gopherbot gopherbot added this to the Unreleased milestone Dec 20, 2020
@dmitshur dmitshur changed the title x/tools/go/ast/astutil.DeleteImport without import spec comment x/tools/go/ast/astutil: DeleteImport leaves behind inline comments Dec 29, 2020
@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 29, 2020
@dmitshur
Copy link
Contributor

This behavior doesn't reproduce for me, see https://play.golang.org/p/Ih5e7bjhbNp.

Did you provide the *token.FileSet parameter to astutil.DeleteImport?

If this problem still happens for you, please include a minimal program to reproduce it.

@dmitshur dmitshur added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Dec 29, 2020
@gopherbot
Copy link

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@golang golang locked and limited conversation to collaborators Jan 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants