Skip to content

[feature request] 自动为 sdcc 项目生成 clangd 兼容文件 #413

@Kodecable

Description

@Kodecable

虽然目前 clangd 并不支持 sdcc,但通过添加配置文件和定义可以正常使用。
目前 eide 自动兼容的官方 cpp 扩展并不完整支持 sdcc(相关 issue),使 clangd 开箱即用有助于方便用户使用。

对于 89c52_SDCC,示例如下:

# 自动生成文件: .clangd
# 部分内容与项目设置有关,需要 eide 自动生成和更新。
CompileFlags:
    Add:
        - -std=c2x
        - -D__SDCC
        - -DCLANGD # 用于激活 reg52.h 中的假定义
        - -Wno-unknown-warning-option
        - -Wno-main-return-type
    Remove:
        - --std-c99
        - -mmcs51
        - --opt-code-speed
        - --iram-size
        - --xram-size
        - --code-size
    CompilationDatabase: ./build/Debug
// 添加至模板项目中的 reg52.h

#ifdef CLANGD
// 为使 clangd 正常工作假定义一些关键字

#define __data
#define __near
#define __xdata
#define __far
#define __idata
#define __pdata
#define __code
#define __interrupt(x)
#define __using(x)
#define __at(x)

#include <stdint.h>
typedef uint8_t __sfr;
typedef uint16_t __sfr16;
typedef uint32_t __sfr32;

//try find bool define
#if __STDC_VERSION__>=202311L
#define bit_t bool
#endif
#if !defined(bit_t)&&__STDC_VERSION__>=199901L
#include <stdbool.h>
#define bit_t _Bool
#endif
#if !defined(bit_t)
#define bit_t int
#endif

typedef bit_t __sbit;
typedef bit_t __bit;

#endif

进行一定修改后理论上也应该可以使官方 cpp 扩展正确识别 sdcc 的特殊类型,使智能补全等功能更完善。

相关:
#386

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions