2010年7月11日 星期日

Integrate vim and lxr

LXR is the Linux cross reference which a "a software toolset for indexing and presenting source code repositories" (from lxr web site). It's very useful when you develop large software system with big team. There always are apis you never know and don't know how to use it or data object you need to check what's it exactly provided. But it provide web base interface and I want use it in my vim.

There is another advantage for me to integrate lxr and vim. Our team rebuild the lxr database to refresh member's update automatically and I don't have to update index database like cscope by myself which I did it past two years.

The way I integrate vim and LXR is quite simple. I think maybe it's just too simple and I can't find any related information from internet. Anyway, I made it myself and it does help to me.

I integrate the vim and LXR by provide a utility which send http request to LXR web server, parser the http response, and translate to cscope's line-oriented output. Then, the vim can interactive with cscope by line-oriented mode. It's so simple that you can even use shell script to make it and I made it with python. Actually it's a cscope line-oriented mode enumerator for LXR. :-) The other benefit is emacs can use it too.

The MOST IMPORTANT THING is that prompt of cscope is ">> ". Note the last space character. It's part of prompt. The space take me one day to debug. I even read the vim and global source code. You can avoid the stupid bug if you read my blog. It's OK to skip all other part of this article when you note this. :-)

Then, not all cscope functions can map to LXR. For example, cscope can only search who call a function or everyone called by a function. But the LXR provide all reference only. My team use older version's LXR and it provide less information then latest.

The last thing is LXR can tell you a line of a source file reference to the keyword you search but no code segment. You have to check each result You can either send another http request to LXR web server to get code segment or grep source file according to the file path provided by search result. The code segment is very very helpful when you get large search result.

沒有留言: