最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

vscode中4个json的区别和联系

维修知识 admin 157浏览 0评论

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(代码完成、提示等)。

官网链接:

模板为:

{"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


官网链接:

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:

  • 例子

    {"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

=1001.2014.3001.5501

存在远程debug容器中的

tasks.json


官网链接:

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

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

以下为自定义task

{// See /?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++程序

{"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


官网链接:

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

不同的设置范围:

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

=1001.2014.3001.5501

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(代码完成、提示等)。

官网链接:

模板为:

{"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


官网链接:

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:

  • 例子

    {"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

=1001.2014.3001.5501

存在远程debug容器中的

tasks.json


官网链接:

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

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

以下为自定义task

{// See /?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++程序

{"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


官网链接:

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

不同的设置范围:

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

=1001.2014.3001.5501

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论