vscode中4个json的区别和联系


在vscode中快捷键ctrl+shift+p,然后输入setting,会出现下图几个选项

当不同设置之间出现冲突时,听谁的:

Open Workspace Settings(JSON) > Open Settings(JSON) = Open User Settings > Open Default Settings(JSON)

Open Workspace Settings(JSON):

点击该选项,会在当前工程目录下新建一个.vscode目录,在.vscode目录下,会多出一个settings.json文件,默认为空。

在这个settings.json文件中,可以写一些设置选项,这些设置选项仅仅对当前工程目录下的文件起作用.

c_cpp_properties.json


此文件用于配置VS Code的C/C++扩展,提供正确的IntelliSense(代码完成、提示等)。

官网链接:https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference

模板为:

json 复制代码
{
  "env": { //定义了一组环境变量,这些变量稍后在配置中可以引用
    "myDefaultIncludePath": ["${workspaceFolder}", "${workspaceFolder}/include"],//表示默认的头文件搜索路径
    "myCompilerPath": "/usr/local/bin/gcc-7" //定义了一个编译器的路径
  },
  "configurations": [
    {
      "name": "Mac", //mac,linux,win32/描述了这个配置的目的或使用的环境
      "intelliSenseMode": "clang-x64",
      "includePath": ["${myDefaultIncludePath}", "/another/path"],//包含头文件搜索路径的数组。它引用了前面定义的环境变量myDefaultIncludePath并添加了另一个路径/another/path
      "macFrameworkPath": ["/System/Library/Frameworks"],
      "defines": ["FOO", "BAR=100"],
      "forcedInclude": ["${workspaceFolder}/include/config.h"],
      "compilerPath": "/usr/bin/clang", //用于构建项目的编译器的完整路径
      "cStandard": "c11",
      "cppStandard": "c++17",
      "compileCommands": "/path/to/compile_commands.json",//指向一个compile_commands.json文件的路径,它提供了关于如何编译工程中各个文件的信息
      "browse": {
        "path": ["${workspaceFolder}"],
        "limitSymbolsToIncludedHeaders": true,
        "databaseFilename": ""
      }
    }
  ],
  "version": 4
}

launch.json


官网链接:https://code.visualstudio.com/docs/cpp/launch-json-reference

launch.json 文件用于在 Visual Studio Code 中配置调试器。要开始调试,您需要在program字段中填写您计划调试的可执行文件的路径。This must be specified for both the launch and attach (if you plan to attach to a running instance at any point) configurations.

生成的文件包含两部分,第一部分配置launch调试,第二部分配置attach调试

点击DEBUG->创建lauch.json

配置vscode调试行为

Set or change the following options to control VS Code's behavior during debugging:

  • 例子

    json 复制代码
    {
      "name": "C++ Launch (Windows)",
      "type": "cppvsdbg",
      "request": "launch",
      "program": "C:\\app1\\Debug\\app1.exe",
      "symbolSearchPath": "C:\\Symbols;C:\\SymbolDir2",
      "externalConsole": true,
      "logging": {
        "moduleLoad": false,
        "trace": true
      },
      "visualizerFile": "${workspaceFolder}/my.natvis",
      "showDisplayString": true
    }
  • program (required)

    指定调试器将启动或附加的可执行文件的完整路径。调试器需要该位置才能加载调试符号。

  • symbolSearchPath

    告诉 Visual Studio Windows 调试器搜索symbol(.pdb) 文件的路径。用分号分隔多个路径。例如"C:\Symbols;C:\SymbolDir2"。

  • requireExactSource

  • additionalSOLibSearchPath

    Tells GDB or LLDB what paths to search for .so files. Separate multiple paths with a semicolon. For example: "/Users/user/dir1;/Users/user/dir2".

  • externalConsole

    Used only when launching the debuggee. For attach, this parameter does not change the debuggee's behavior.

    • Linux: set to true,通知 VS Code 生成外部控制台;set to false,使用vscode终端
  • avoidWindowsConsoleRedirection

  • logging

    可选标记,用于确定哪些类型的信息应记录到调试控制台。

    • exceptions:可选标志,用于确定是否将异常信息记录到调试控制台。默认为 true。
    • moduleLoad(模块加载可选标记,用于确定是否将模块加载事件记录到调试控制台。默认为 true。
    • programOutput(程序输出):可选标志,用于确定是否将程序输出记录到调试控制台。默认为 true。
    • engineLogging(引擎记录):可选标记,用于确定是否将诊断引擎日志记录到调试控制台。默认为 false。
    • trace(跟踪):可选标记,用于确定是否将诊断适配器命令跟踪记录到调试控制台。默认为 false。
    • traceResponse:跟踪响应:可选标记,用于确定是否将诊断适配器命令和响应跟踪记录到调试控制台。默认为假。

自定义GDB或LLDB

https://blog.csdn.net/weixin_40579705/article/details/133788557?spm=1001.2014.3001.5501

存在远程debug容器中的

tasks.json


官网链接:https://code.visualstudio.com/Docs/editor/tasks

此文件定义了在VS Code中执行的任务。这些任务可以是编译、构建、运行脚本等。

ctrl+shift+p->task->使用模板创建tasks.json文件->others 运行任何外部命令的先例

以下为自定义task

json 复制代码
{
  // See https://go.microsoft.com/fwlink/?LinkId=733558
  // for the documentation about the tasks.json format
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Run tests",
      "type": "shell",
      "command": "./scripts/test.sh",
      "windows": {
        "command": ".\\scripts\\test.cmd"
      },
      "group": "test",
      "presentation": {
        "reveal": "always",
        "panel": "new"
      }
    }
  ]
}
  • label

    用户界面中使用的任务标签

  • type

    任务类型。对于自定义任务,可以是 shell 或进程。如果指定 shell,命令将被解释为 shell 命令(例如:bash、cmd 或 PowerShell)。如果指定 process,命令将被解释为一个要执行的进程。

  • command

    要执行的实际命令。

  • group

    Defines to which group the task belongs. In the example, it belongs to the test group. Tasks that belong to the test group can be executed by running Run Test Task from the Command Palette.presentation

  • options

    覆盖 cwd(当前工作目录)、env(环境变量)或 shell(默认 shell)的默认值。选项可按任务设置,也可全局或按平台设置。此处配置的环境变量只能在任务脚本或进程中引用,如果它们是 args、命令或其他任务属性的一部分,则不会被解析。

  • runOptions

    Defines when and how a task is run

示例:使用g++编译c++程序

json 复制代码
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "g++ build active file",
            "type": "shell",
            "command": "/usr/bin/g++",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

setting.json


官网链接:https://code.visualstudio.com/docs/getstarted/settings

可以根据自己的喜好通过各种配置来配置vscode。几乎vscode的编辑器,用户界面和功能行为的每个部分都有可以修改的地方

不同的设置范围:

  • 用户设置:全局应用到你打开的任何vscode实例的设置
  • 工作区设置:存储在工作区内部的设置,仅在工作区打开时应用

https://blog.csdn.net/weixin_40579705/article/details/131492235?spm=1001.2014.3001.5501

相关推荐
Diligently_5 天前
idea 中vm option 配置
java·ide·intellij-idea
我命由我123455 天前
在 Android Studio 中,新建 AIDL 文件按钮是灰色
android·ide·android studio·安卓·android jetpack·android-studio·android runtime
Hello World . .5 天前
Linux:线程间通信
linux·开发语言·vscode
AC赳赳老秦5 天前
云原生AI故障排查新趋势:利用DeepSeek实现高效定位部署报错与性能瓶颈
ide·人工智能·python·云原生·prometheus·ai-native·deepseek
被制作时长两年半的个人练习生5 天前
claude code for vscode 配置 qwen3.5
ide·vscode·claude code·qwen3.5
圣心5 天前
Visual Studio Code 中的 AI 智能操作
ide·人工智能·vscode
吹牛不交税5 天前
关于vscode左侧资源管理器目录层级疑似异常的问题
ide·vscode·编辑器
xixi09245 天前
selenium IDE安装使用教程
ide·selenium·测试工具
嵌入小生0075 天前
线程间通信---嵌入式(Linux)
linux·c语言·vscode·嵌入式·互斥锁·线程间通信·信号量
上海合宙LuatOS5 天前
LuatOS核心库API——【json 】json 生成和解析库
java·前端·网络·单片机·嵌入式硬件·物联网·json