Fix highlight problem in preprocessor
The highlighting of preprocessor goes wrong. Everything after the define line has no highlighting.
This PR resolves the Issue #3505
Changes
There was a simple change in cpp.js file.
path: src/languages/cpp.js
Before:
const PREPROCESSOR = {
className: 'meta',
begin: /#\s*[a-z]+\b/,
end: /$/, <----------------------------- see this
keywords: { keyword:
'if else elif endif define undef warning error line '
+ 'pragma _Pragma ifdef ifndef include' },
contains: ......
After
const PREPROCESSOR = {
className: 'meta',
begin: /#\s*[a-z]+\b/,
end: /\s/, <----------------------- the change
keywords: { keyword:
'if else elif endif define undef warning error line '
+ 'pragma _Pragma ifdef ifndef include' },
contains: ......
*The header files <....> are treated as html elements and hence not shown
Checklist
- [x] Added markup tests, or they don't apply here because...
- [x] Updated the changelog at
CHANGES.md
Should I add the contains property or end the preprocessor after "\s" ? This ending doesn't seems to me a proper way so adding the contains might be a good approach. can you suggest me
Thanks for the attempt here, but I think this one might be a bit more complex.
If this does fix 3505, it's a very "round-about" fix... the stated issue there is that lines following a pre-processor line are not highlighted at all (because of how we handling templating), not that the content on the same line immediately following a pre-processor directive is not highlighted.
The current behavior seems an intentional choice. True, it's not what VS Code does, but seems unclear to me that VS Code is superior. The text that follows any random compiler directive is not necessarily C code, and thus using those same rules to highlight it (as normal C code) seems quite wrong in some ways.
I'll leave this open for now to see if it draws any further discussion/opinions.
Github highlighting (just for curiosity):
// this is a continued\
comment.
#include <iostream>
#include <iostream>
#define what do{ cout << "Hello"; } while(0);
#define PI 3.14;
#pragma warning(disable : 1234)
#if !defined(CONFIG_OPTION)
#error "CONFIG_OPTION is not defined."
#endif
#line 42 "mycode.cpp"
#undef PI
Looks like it tries to parse some directives and highlight them special and the rest just get the macro highlighted and the rest entirely untouched.