Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

VSCode-go adds incorrect imports #1423

Closed
wjessop opened this issue Dec 23, 2017 · 2 comments
Closed

VSCode-go adds incorrect imports #1423

wjessop opened this issue Dec 23, 2017 · 2 comments

Comments

@wjessop
Copy link

wjessop commented Dec 23, 2017

Given a program that uses a global variable (log in this example) that is defined in a second file:

main.go

package main

func main() {
	createLogger(true)
	log.Debug("foo")
}

logging.go

package main

import (
	logging "github.com/op/go-logging"

	"os"
)

var (
	log       = logging.MustGetLogger("myprog")
	logFormat = logging.MustStringFormatter(`%{color}%{time:15:04:05.000} %{shortfunc} ▶ %{level:.5s} %{id:03x}%{color:reset} %{message}`)
)

func createLogger(isDebug bool) {
	logBackend := logging.NewLogBackend(os.Stderr, "", 0)
	logFormatter := logging.NewBackendFormatter(logBackend, logFormat)
	logLeveled := logging.AddModuleLevel(logFormatter)
	logging.SetBackend(logLeveled)

	if isDebug {
		logLeveled.SetLevel(logging.DEBUG, "")
		log.Debugf("Setting log level to DEBUG")
	} else {
		logLeveled.SetLevel(logging.INFO, "")
	}
}

VSCode-go adds an incorrect import for log that prevents the code from working:

package main

import log "github.com/mgutz/logxi/v1"

func main() {
	createLogger(true)
	log.Debug("foo")
}

It is expected that no import is added in this situation. I created a full demo replicating this issue.

@ramya-rao-a
Copy link
Contributor

Try setting "go.formatTool" to "goimports"

@ramya-rao-a
Copy link
Contributor

Also see #613 (comment)

@vscodebot vscodebot bot locked and limited conversation to collaborators Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants