1. 程式人生 > 其它 >Vscode解決Golang無法跳轉定義問題

Vscode解決Golang無法跳轉定義問題

首先,需要安裝好 go 外掛,外掛市場搜尋go,選一個即可安裝。

然後,需要安裝 go 的工具包。在 vscode 中,輸入快捷鍵:command(ctrl) + shift + p,在彈出的視窗中,輸入:go:install/Update Tools,回車後,選擇所有外掛(勾一下全選),點選確認,進行安裝(設定GOPROXY)。

接下來,在專案的 settings.json 檔案中新增配置:

   "go.goroot": "D:\\Go",
    "go.gopath": "D:\\gopath",
    //第三方庫程式碼提示
    "go.inferGopath": true,
    "go.formatTool": "goreturns",
    //自動完成未匯入的包
    "go.autocompleteUnimportedPackages": true,
    "go.gocodePackageLookupMode": "go",
    "go.gotoSymbol.includeImports": true,
    "go.docsTool": "gogetdoc",
    "go.useCodeSnippetsOnFunctionSuggest": true,
    "go.useCodeSnippetsOnFunctionSuggestWithoutType": true,
    "go.useLanguageServer": true,
    "[go]": { 
        "editor.formatOnSave": true, 
        "editor.codeActionsOnSave": { 
            "source.organizeImports": true, 
        },    // Optional: Disable snippets, as they conflict with completion ranking.    "editor.snippetSuggestions": "none", 
    },"[go.mod]": { 
        "editor.formatOnSave": true, 
        "editor.codeActionsOnSave": { 
            "source.organizeImports": true, 
        },
    },"go.trace.server": "verbose", 
    "gopls": { 
        // Add parameter placeholders when completing a function. 
       "usePlaceholders": false, 
       // If true, enable additional analyses with staticcheck. 
       // Warning: This will significantly increase memory usage.   "staticcheck": false, 
    },"go.languageServerFlags": [ 
        "-remote=auto", "-logfile=auto", "-debug=:0", "-rpc.trace", 
    ], 

首選項-設定 去掉 Use Language Server