Skip to content

Import package only if expression will be resolved afterwards #2446

@dlsniper

Description

@dlsniper
  • Plugin version (or commit hash): 0.11.1273

Given the following example:

package main

func main() {
    demopack.Demo
}

If in the GOPATH there's a package called demopack then it will be added automatically to the import list. However, the if the package doesn't contain any Demo definition then the unresolved expression will now shift from the demopack to Demo.
If possible, I propose the following rules:

if package name name matches the first part of the expression then
  check if the second part is defined in the said package
  if defined then import else
    if package is in current project then
      import package
    else skip
else skip

The reason I'm suggesting to still allow for importing the package if it's in the current project is that we can then later provide a quickfix to say: create (variable/conf/struct/interface) in package
Does it make sense?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions