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: report if accepting a completion item will result in auto-import #70975

Open
xzbdmw opened this issue Dec 23, 2024 · 2 comments
Open
Assignees
Labels
FeatureRequest gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@xzbdmw
Copy link

xzbdmw commented Dec 23, 2024

gopls version

0.17.1

go env

..

What did you do?

"os" is not yet imported:
image

however, strings are already imported:
image

What did you see happen?

They looks the same.

What did you expect to see?

Show a hint whether a package is going to be auto-imported, because some package names look similar, I want to use an already imported one, but find myself often accept a wrong name, therefor need to undo auto import.

In clangd, there is a little circle indicating this:
image

after accpeting printf, the circle disappears, because stdio.h is auto imported
image

Editor and settings

No response

Logs

No response

@xzbdmw xzbdmw added gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. labels Dec 23, 2024
@gopherbot gopherbot added this to the Unreleased milestone Dec 23, 2024
@xzbdmw xzbdmw changed the title x/tools/gopls: report if a package will be auto-import in completion item x/tools/gopls: report if accepting a completion item will result in auto-import Dec 23, 2024
@findleyr
Copy link
Member

Thanks. Coincidentally, I am working on unimported completion, so I will look into this.

Off the top of my head, I do not know what causes the cdot for the clang analyzer, but I can investigate. This is VS Code, right?

@findleyr findleyr self-assigned this Dec 23, 2024
@findleyr findleyr modified the milestones: Unreleased, gopls/backlog Dec 23, 2024
@xzbdmw
Copy link
Author

xzbdmw commented Dec 24, 2024

Yes, the circle is part of the returned completion item
https://clangd.llvm.org/features#namespace-and-include-insertion
that's what printf returns if it is going to import

{
  additionalTextEdits = { {
      newText = "#include <stdio.h>\n",
      range = {
        ["end"] = {
          character = 0,
          line = 6
        },
        start = {
          character = 0,
          line = 6
        }
      }
    } },
  detail = "int",
  documentation = {
    kind = "markdown",
    value = "From `<stdio.h>`"
  },
  filterText = "printf",
  insertText = "printf(${1:const char *, ...})",
  insertTextFormat = 2,
  kind = 3,
  label = "•printf",
  labelDetails = {
    detail = "(const char *, ...)"
  },
  score = 0.50908720493317,
  sortText = "40fdac76printf",
  textEdit = {
    newText = "printf(${1:const char *, ...})",
    range = {
      ["end"] = {
        character = 5,
        line = 13
      },
      start = {
        character = 4,
        line = 13
      }
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants