简体   繁体   中英

How to force VSCode to require manual choice where goimports match multiple packages with same name?

I just ran into issues where I am writing small web service with Go Iris framework. Iris has few useful packages for HTTP request error handling.

Namely, I wanted to use "github.com/kataras/iris/middleware/logger" and "github.com/kataras/iris/middleware/recover" however when I start typing app.Use(logger....) VSCode auto imported " github.com/hashicorp/consul/logger " which is also in my path.

Simply copy-pasting right path will solve the issue, but is there a way to force VSCode to make a manual choice where multiple packages names are matched or even fully disable goimports for these cases.

Example below:

package main

import (
    // "github.com/hashicorp/consul/logger" ! incorrect package

    "github.com/kataras/iris"
    "github.com/kataras/iris/middleware/logger"
    "github.com/kataras/iris/middleware/recover"
)

func main() {
    app := iris.New()
    app.Logger().SetLevel("debug")
    // Optionally, add 2 built'n handlers
    // that can recover from any http-related error
    // and log the requests in terminal
    app.Use(recover.New())
    app.Use(logger.New())
}

If you start typing in the import () declaration, it will give you suggestions that match. So if you were to type logger it would give you the suggestion of:

github.com/kataras/iris/middleware/logger

and

github.com/hashicorp/consul/logger

Just put the "" in the import and start typing the package you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM