clighter
clighter copied to clipboard
Additional Declaration Highlights
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.
- Function invocations
- Function declarations
- Namespace qualifiers
- 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.
I have added 4 highlight groups into clighter, but all of them are link to "None" by default, because it's a little annoying.
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.
This recently got posted on LLVM weekly, color_coded
I will list all highlight groups in next release, and make them as an option
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
- 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.
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 afterclass
, or beforefrom
/to
, but it is highlighted insidepair
.template<class It> vector<pair<It, It>> divide(It from, It to, const std::ptrdiff_t number)
-
Function declarations inside classes in the headers.
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 :)
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); }
Great work adding class functions in 2ac874abcca63ad13574c248f88e30cefad7d6a4. Constructors are not yet highlighted though...
Another missing highlight:
std::for_each(begin(threads), end(threads), [](std::thread & t) { t.join(); });
Here "join" is not highlighted as a function.
Also:
vector<int> test = {1, 2};
vector<int> test2(test.size());
"size" is not highlighted as a function
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 :)
to enable member ref, you must add 'clighterMemberRefExpr' into g:clighter_syntax_groups
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.
To enable namespace ref highlight, add 'clighterNamespace' into g:clighter_syntax_groups
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.
Here is a screenshot of what I'm seeing:
I have enabled all highlight groups.
That's because in first line, clang see 'std' as "CursorKind.NAMESPACE_REF", but see as "CursorKind.CALL_EXPR" in second line
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.
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.
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
This is what I see of clighterMemberRefExprVar
Your color scheme looks good