dpkt31779 2018-01-22 12:26
浏览 158
已采纳

在goimport匹配多个具有相同名称的软件包时,如何强制VSCode要求手动选择?

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())
}
  • 写回答

1条回答 默认 最新

  • douju6651 2018-01-22 20:25
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办