clighter icon indicating copy to clipboard operation
clighter copied to clipboard

Additional Declaration Highlights

Open kbenzie opened this issue 10 years ago • 22 comments

After using vim-cpp-enhanced-highlight for a while I've grown used to function and (some) namespace highlighting. I've become frustrated at the inconsistency of highlighting this plugin show due to only STL namespaces being highlighted and also by the highlighting of certain STL keywords.

I like how clighter highlights enums and macros but still find the results bland for other general code. My requests, in order of preference, are as follows.

  1. Function invocations
  2. Function declarations
  3. Namespace qualifiers
  4. Member qualifiers

I can provide examples of the desired results if you feel this would be something you would like to add in future. Thanks for the interesting plugin.

kbenzie avatar Oct 13 '14 19:10 kbenzie

I have added 4 highlight groups into clighter, but all of them are link to "None" by default, because it's a little annoying.

bbchung avatar Oct 14 '14 06:10 bbchung

The added highlight groups work great. Is it possible to also add a highlight group for function invocations/calls? With function calls (and template classes) highlighted, this plugin would replace vim-cpp-enhanced-highlight for me.

octol avatar Apr 06 '15 14:04 octol

This recently got posted on LLVM weekly, color_coded

kbenzie avatar Apr 06 '15 14:04 kbenzie

I will list all highlight groups in next release, and make them as an option

bbchung avatar Apr 07 '15 02:04 bbchung

plz update clighter to get these work, and this is default settings.

1.Function invocations hi default link clighterDeclRefExprCall Identifier -> disable

2.Function declarations hi default link clighterFunctionDecl Function -> disable

3.Namespace qualifiers hi default link clighterNamespace Type -> disable

4.Member qualifiers hi default link clighterFieldDecl Type -> disable hi default link clighterMemberRefExpr Identifier -> disable

  1. template class behavior should like normal class in the newest version

1~4 is disabled by default, because let g:clighter_syntax_groups = get(g:, 'clighter_syntax_groups', ['clighterMacroInstantiation', 'clighterStructDecl', 'clighterClassDecl', 'clighterEnumDecl', 'clighterEnumConstantDecl', 'clighterTypeRef', 'clighterDeclRefExprEnum'])

you can enable them by set g:clighter_syntax_groups, for example let g:clighter_syntax_groups = get(g:, 'clighter_syntax_groups', ['clighterMacroInstantiation', 'clighterStructDecl', 'clighterClassDecl', 'clighterEnumDecl', 'clighterEnumConstantDecl', 'clighterTypeRef', 'clighterDeclRefExprEnum','clighterDeclRefExprCall','clighterFunctionDecl','clighterNamespace','clighterFieldDecl','clighterMemberRefExpr'])

Clang provides too many type to highlight, enable all type is not unrealistic and low performance, so if there is any type should be highlighted in the future, just tell me.

bbchung avatar Apr 07 '15 03:04 bbchung

With the latest version function invocations now work, and class template declarations as well. Great work!

Three things that are not yet included in any syntax group:

  • Templated variable types

  • Template arguments in function declarations: in the following example It is not hightlighted after class, or before from/to, but it is highlighted inside pair.

    template<class It>
    vector<pair<It, It>> divide(It from, It to, const std::ptrdiff_t number)
    
  • Function declarations inside classes in the headers.

octol avatar Apr 07 '15 08:04 octol

Ok, I add more template support in 95e48b5f1772d7cb21199bdde23da73124479762 . By the way, in my environment, 'It' before 'from'/'to' is highlighted in 2b36f5ebbaa93b91fde222f5c5de000a96c2c0e0.

Thanks for your testing and keep testing :)

bbchung avatar Apr 07 '15 09:04 bbchung

Fixed:

  • I got 'It' in the above example highlighted correctly in the latest commit.
  • Templated variably types work too.

Left to do:

  • Functions declarations inside classes, such as

    class Test {
        void func();
    };
    
  • In the following example, std::vector in the return statement is not highlighted:

    std::vector<int> func1(int x) {
        return std::vector<int>(x);
    }
    

octol avatar Apr 07 '15 11:04 octol

Great work adding class functions in 2ac874abcca63ad13574c248f88e30cefad7d6a4. Constructors are not yet highlighted though...

octol avatar Apr 09 '15 17:04 octol

Another missing highlight:

std::for_each(begin(threads), end(threads), [](std::thread & t) { t.join(); });

Here "join" is not highlighted as a function.

octol avatar Apr 09 '15 17:04 octol

Also:

vector<int> test = {1, 2};
vector<int> test2(test.size());

"size" is not highlighted as a function

octol avatar Apr 09 '15 17:04 octol

Must say though, with the latest added highlight groups this plugin is really coming together for me. Soon I'll be able to use it full time :)

octol avatar Apr 09 '15 17:04 octol

to enable member ref, you must add 'clighterMemberRefExpr' into g:clighter_syntax_groups

bbchung avatar Apr 10 '15 03:04 bbchung

Ah I see. I had wrongly thought that MemberRefExpr refered to member variables. Enabling it indeed highlights member function calls correctly, but also includes member variables. Ideally I'd prefer to only hightlight member function calls and not member variables, but I can live with highlighting both.

Another one:

std::cout << std::chrono::duration<double, std::milli>(end - start).count()  << std::endl;

the 'std' before 'chrono' and 'milli' is not highlighted.

octol avatar Apr 10 '15 08:04 octol

To enable namespace ref highlight, add 'clighterNamespace' into g:clighter_syntax_groups

bbchung avatar Apr 10 '15 08:04 bbchung

Yes I have done that. In the above example std::cout and std::endl is highlighted but not std::chrono or std::milli. Also note that std::chrono in

auto end = std::chrono::steady_clock::now();

is correctly highlighted. I suspect the underlying reason is the same as why

return std::vector<int>(4);

is not highlighted.

octol avatar Apr 10 '15 18:04 octol

Here is a screenshot of what I'm seeing:

chrono

I have enabled all highlight groups.

octol avatar Apr 10 '15 23:04 octol

That's because in first line, clang see 'std' as "CursorKind.NAMESPACE_REF", but see as "CursorKind.CALL_EXPR" in second line

bbchung avatar Apr 11 '15 05:04 bbchung

I notice in the latest commit that that clighterMemberRefExprVar does not match anything, while clighterMemberRefExprCall matches both references to member function calls and member variables.

octol avatar Apr 11 '15 16:04 octol

Clang see both member ref call/var as MEMBER_REF_EXPR. So clighter differentiates them by their type kind, and the most rational way for now is treating cindex.TypeKind.UNEXPOSED as call ref, and others are var ref. It should work now.

bbchung avatar Apr 12 '15 04:04 bbchung

Well I tried setting hi link clighterMemberRefExprVar Error and I'm not seeing this fire anywhere in the code I've been trying it on :( Nonetheless I think that the current state is good enough that I will start use it the plugin as my daily driver.

If you're interested, this is the configuration that I'm using, which I think gives a balanced and a visually attractive look, even for the default theme. I suppose I could move the highlight groups that I set to None, to the blacklist.

let g:clighter_highlight_blacklist = [
            \   'cligherInclusionDirective',
            \   ]

" Free functions
hi link clighterDeclRefExprCall Function
hi link clighterFunctionDecl Function

" Enums
hi link clighterEnumDecl Identifier
hi link clighterEnumConstantDecl Constant
hi link clighterDeclRefExprEnum Constant

hi link clighterMacroInstantiation Constant
hi link clighterPrepro PreProc

" Member variable and method calls
hi link clighterMemberRefExprCall Function

" Not working
hi link clighterMemberRefExprVar Error

" namespace { ... }
hi link clighterNamespace Constant
hi link clighterNamespaceRef Constant

hi link clighterOccurrences IncSearch

" Templated types
hi link clighterTemplateRef Type

" References to templated types
hi link clighterTypeRef Type

" The 'T' in template <class T>
hi link clighterTemplateTypeParameter Type

" class/struct declarations
hi link clighterClassDecl None
hi link clighterStructDecl None

" 'using name = ...' statements
hi link clighterDecl None

" Class member variable declarations
hi link clighterFieldDecl None

" Function parameters, including the template types
hi link clighterParmDecl None

" Lambda campture variables, using std::name statements
hi link clighterRef None

hi link clighterUnionDecl None

" Local variables
hi link clighterVarDecl None

This is what it looks like out-of-the-box using the very popular tomasr/molokai theme

conway

octol avatar Apr 12 '15 08:04 octol

demo

This is what I see of clighterMemberRefExprVar

Your color scheme looks good

bbchung avatar Apr 12 '15 13:04 bbchung