-
Notifications
You must be signed in to change notification settings - Fork 17.4k
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: renaming an imported package name does not rename the imported package itself #68096
Comments
another odd behavior along the same line was, I updated world := &bonus.World{} in main to world := &worldroller.World{} by typing it manually, and ctrl +s removed the import line for the old bonus package and and didn't add the one for the worldroller package. But then hit undo, selected bonus, started typing, saw predicted text "world roller" hit tab, and that updated the import perfectly correctly even before I saved. When doing this in a file with more than one instance, it kept the old 'bad' import and added the new one on a new line, which makes sense because it was still referenced in the code. update, further testing showed that when you right click the directory name in the import list and you click "rename symbol" it will populate the box so like further investigation reveals that if you try to delete the import to prevent the mistake, then you can't use "rename symbol" on the code because it no longer recognizes it. |
There are three issues here. Let's call this one issue 1.
The symbol To rename a package, invoke the Rename operation while selecting the |
Issue 2:
I tried to reproduce this using the
If you see something different, could you please give instructions for reproducing it with these standard library symbols? Ideally this should be a separate GitHub issue, since it is unrelated to the other two items. |
Issue 3:
Correct, renaming an import declaration such as
Indeed; to undo this mistake you should rename again to the original name. |
@findleyr wonders whether issue 2 may have been affected by https://go.dev/cl/590377. |
I installed the latest gopls as per @findleyr and followed the steps for issue 2 and everything behaved as you described as normal with the redundant imports not being removed until saving the file and the xml completions showing before the package is imported on-save. |
Type: Bug
step 1, have a very simple application file app/mapper.go and a simple test file in the same package, but a different directory app_test/mapper_test.go
both have first line 'package app'
step 2, start fixing your file structure, create a new directory named 'mapper' and put mapper.go and mapper_test.go both in there.
step 3, change the package for mapper to 'package mapper' and mapper_test to 'package mapper_test'
step 4, right click the 'app' in rooms := &app.Generate()
step 5, left-click Rename Symbol
step 6, type in 'mapper' to match the package name properly
step 7, ctrl + s saves the file
Import list before step 7
import (
"data-algo/app"
"fmt"
"math/rand"
"testing"
"time"
)
after step 7
import (
mapper "data-algo/app"
"fmt"
"math/rand"
"testing"
"time"
)
I have many folders I'm fixing like this and I repeated this bug consistently
Extension version: 0.41.4
VS Code version: Code 1.90.1 (611f9bfce64f25108829dd295f54a6894e87339d, 2024-06-11T21:02:43.666Z)
OS version: Linux x64 6.6.25-01713-g2f237acc8e50
Modes:
System Info
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: disabled_off
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: disabled_software
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
A/B Experiments
The text was updated successfully, but these errors were encountered: