最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

syntax highlighting - nvim treesitter highlight for "#if...#elif...#endif" preprocessors - Stack Overflow

programmeradmin1浏览0评论

I am using nvim + nvim-treesitter to parse and highlight my code. There is a problem on C source code #if...#elif...#endif preprocessor block.

Say I have the following code

// test.c
#include "test.h"

#if defined(MACRO_A)
uint32_t myVar;
#elif defined(MACRO_B)
uint16_t myVar;
#endif

The default highlighting is as the following, as no macro definition is there.

If I define MACRO_A in test.h. The highlight is changed as expected. Content following MACRO_A is displayed normally, content following MACRO_B is commented out.

The problem is, for real world code, the macro is not always defined in a header file, it can be passed from IDE preprocessor settings or command line arguments. How do I let nvim/treesitter know such macro definition?

发布评论

评论列表(0)

  1. 暂无评论