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

相关推荐
青 春 记 忆2 小时前
零基础入门Python11|Git实战:为任务管理器建立版本历史
开发语言·git·vscode·python·python3.11
️学习的小王15 小时前
Anaconda国内镜像配置与conda常用命令
ide·经验分享·python·conda
Magic-ZYJ15 小时前
HarmonyOS 调用系统文件保存器导出 JSON 与 CSV
华为·json·harmonyos·鸿蒙·独立开发者
雾沉川17 小时前
Rust IDE 选型:除 VS Code 之外,RustRover 非商业场景可免费使用
ide·vscode·rust
SeaTunnel18 小时前
从 JSON 到 JSONL,Apache SeaTunnel 如何解决HTTP 大数据传输的内存难题?
http·开源·json·apache·数据集成·seatunnel
++==1 天前
JSON和Python的 四种核心容器
python·json
精英的英1 天前
记一次 Qt5 Language Server 开发
开发语言·vscode·qt
2501_915918412 天前
iOS 真机调试工具推荐,安装运行、性能分析有哪些工具
ide·vscode·ios·objective-c·个人开发·swift·敏捷流程
笨鸟先飞,勤能补拙2 天前
AI与深度学习:从原理到应用
人工智能·windows·vscode·深度学习·机器学习·网络安全·github
lf13210272 天前
用 JSON Schema 管装修节点记录:从照片台账到可校验工程数据
网络·数据库·人工智能·经验分享·物联网·json·智能家居