vim 中命名空间感知的omnicomplete

发布于 2024-12-21 23:25:30 字数 1527 浏览 1 评论 0原文

我一直试图找到解决我的麻烦的答案,但没有运气,所以这是我的问题。

我们的 C++ 类是在多个命名空间中定义的。因此,类成员通常具有属于其他命名空间的类型。对于这些情况,vim 的全能补全功能不起作用。 STL 成员和局部变量可以毫无问题地使用全能补全。问题似乎出在成员的变量类型具有命名空间范围标识符时,无论它是它自己的命名空间还是其他命名空间。 :ts tagname 命令始终有效。

小虚拟示例:

namespace T { namespace N2 {
class Lorry
{
public:
    Lorry(){}
    void printInfo(){
    }
private:
    int speed;
};

}}

namespace T { namespace N2 {
class Truck
{
    public:
        Truck();
        void printInfo();
    private:
        Lorry lorry;
        N2::Lorry lorry2; 
};

}}

namespace T { namespace N2 {
Truck::Truck(){}
void Truck::printInfo(){
lorry.printInfo();  // Omnicompletion works
lorry2.            // Omnicompletion does not work. Pattern not found!

}
}}

我使用以下映射生成标签文件:

map <C-F12> :!ctags -R --c++-kinds=+pl --fields=+iaS --extra=+q --language-force=C++ .<CR>

以及 .vimrc 中的一些配置:

let OmniCpp_MayCompleteDot = 1 " autocomplete with .
let OmniCpp_MayCompleteArrow = 1 " autocomplete with ->
let OmniCpp_MayCompleteScope = 1 " autocomplete with ::
let OmniCpp_SelectFirstItem = 2 " select first item (but don't insert)
let OmniCpp_NamespaceSearch = 2 " search namespaces in this and included files
let OmniCpp_ShowPrototypeInAbbr = 1 " show function prototype (i.e. parameters) in popup window
let OmniCpp_LocalSearchDecl = 1 " don't require special style of function opening braces
let OmniCpp_GlobalScopeSearch = 1
let OmniCpp_ShowAccess = 1

提前致谢

I have been trying to find an answer to my trouble with no luck, so here is my question.

Our C++ classes are defined in several namespaces. So, frequently, class members have a type that belongs to other namespace. For those cases, vim's omnicompletion feature does not work. STL members and local variables can be used with omnicompletion without trouble. The trouble seems be to when the variable type of a member has namespace scope identifier, regardless it is its own namespace or other one. :ts tagname command works always.

Little dummy example:

namespace T { namespace N2 {
class Lorry
{
public:
    Lorry(){}
    void printInfo(){
    }
private:
    int speed;
};

}}

namespace T { namespace N2 {
class Truck
{
    public:
        Truck();
        void printInfo();
    private:
        Lorry lorry;
        N2::Lorry lorry2; 
};

}}

namespace T { namespace N2 {
Truck::Truck(){}
void Truck::printInfo(){
lorry.printInfo();  // Omnicompletion works
lorry2.            // Omnicompletion does not work. Pattern not found!

}
}}

I generate tags file using the following map:

map <C-F12> :!ctags -R --c++-kinds=+pl --fields=+iaS --extra=+q --language-force=C++ .<CR>

and some configuration from .vimrc:

let OmniCpp_MayCompleteDot = 1 " autocomplete with .
let OmniCpp_MayCompleteArrow = 1 " autocomplete with ->
let OmniCpp_MayCompleteScope = 1 " autocomplete with ::
let OmniCpp_SelectFirstItem = 2 " select first item (but don't insert)
let OmniCpp_NamespaceSearch = 2 " search namespaces in this and included files
let OmniCpp_ShowPrototypeInAbbr = 1 " show function prototype (i.e. parameters) in popup window
let OmniCpp_LocalSearchDecl = 1 " don't require special style of function opening braces
let OmniCpp_GlobalScopeSearch = 1
let OmniCpp_ShowAccess = 1

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文