vscode(visual studio code) 是微軟推出的一款編輯器。免費,跨平臺,最主要是輕便,消耗資源少, 成爲碼農閱讀code的利器。
vscode能夠安裝第三方的一些插件,知足平常閱讀source code的需求。可是這個插件有些小bug,致使效果不如意。下面跟隨我一塊兒挑戰這些小bug,讓你的tools轉起來。
目標:
1. 支持 Go to definition;
2. 支持 Find all reference;
步驟:
1. 安裝 vscode;
2. 安裝gtags(gnu global), 一款相似於cscope + ctags的工具, 網上教程比較多,在此不提供安裝方法,請自行百度。
有一點須要牢記,安裝完後,須要加入環境變量中,確保在命令行模式下能好到gtags命令;
$ gtags --version
gtags (GNU GLOBAL) 6.6.2
Copyright (c) 1996-2017 Tama Communications Corporation
License GPLv3+: GNU GPL version 3 or later <http://www.gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
3. 爲vscode安裝插件 C++ Intellisense
這個插件支持"Peek definition" && "Find all reference" 功能, 可是這個插件有個小bug, 安裝完後並不能正常工做。並且做者很長時間沒有更新這個插件了,無奈只能本身折騰一番。
找個下面這個文件:
linux下: ~/.vscode/extensions/austin.code-gnu-global-0.2.2/out/src/features/referenceProvider.js
windows下: /c/Users/Administrator/.vscode/extensions/austin.code-gnu-global-0.2.2/out/src/features
個人是Administrator用戶,因此在這個目錄,請自行調整用戶目錄;
GlobalReferenceProvider.prototype.provideReferences = function (document, position, options, token) {
console.log(position);
var word = document.getText(document.getWordRangeAtPosition(position)).split(/\r?\n/)[0];
var self = this;
return this._global.run(['--encode-path', '" "', '-rsax', word])
.then(function (output) {
console.log(output);
var bucket = new Array();
將 「-rax」 修改成 「-rsax」 保存一下。
4. 到源代碼目錄下, 運行gtags 命令,會生成三個文件。 用 vs打開source code目錄後,會看到這個三個文件
5. 到此爲止,你的vscode能夠正常work了, enjoy it.html

注意事項:本身裝GNU Global的時候沒有讓gtags執行完,因此致使仍是提示一樣的錯誤,這個命令執行時間比較長,因此須要耐心等待執行完便可成功。linux