使用compile_commands激活vscode索引-跳转-代码提示功能

最近发现,使用vscode打开一个大的c++工程很容易无法正常调转和代码提示。所以经常会手动修改.vscode/c_cpp_properties.json文件的"includePath"属性。然而,当pkg越来越多 工程体量越来越大之后,我不得不探索如何自动的完成这一过程,而不是不停地修改includePath。

用法参考这个连接:
使用方法icon-default.png?t=O83Ahttps://blog.csdn.net/qq_37868450/article/details/105013325我解决的一个问题是,复杂工程的build目录下,可能有多个子floder,所以需要写一个py脚本,把build下的子文件夹的compile_commands.json合并成build下的一个总compile_commands.json。脚本如下:

# place this file at the root of your workspace

import os
import json

def merge_compile_commands(build_dir):
    merged_commands = []
    for root, dirs, files in os.walk(build_dir):
        if 'compile_commands.json' in files:
            file_path = os.path.join(root, 'compile_commands.json')
            with open(file_path, 'r') as f:
                commands = json.load(f)
                merged_commands.extend(commands)
    
    output_file = os.path.join(build_dir, 'compile_commands.json')
    with open(output_file, 'w') as f:
        json.dump(merged_commands, f, indent=2)

if __name__ == "__main__":
    build_directory = 'build'  
    merge_compile_commands(build_directory)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值