其他分享
首页 > 其他分享> > vscode 基础框架知识/关键字描述

vscode 基础框架知识/关键字描述

作者:互联网

目录

vscode 基础框架知识/关键字描述

简介

vscode的配置

vscode的配置结构

settings.json

tasks.json

launch.json

c_cpp_properties.json


vscode 基础框架知识/关键字描述

链接

简介

VSCode是一款免费的、开源的、高性能的、跨平台的、轻量级的代码编辑器 ​ vscode只提供编辑的环境而不提供编译的环境,如果想要用vscode来集成开发环境,则必须经过以下几步:

安装必须的编译器(比如mingw,python,texlive等)
​
配置相应编译环境(添加环境变量等)
​
安装匹配的vscode的拓展插件
​
通过拓展插件提供的“属性”将外部编译器链接到vscode
​

同时,一个文本编辑器肯定不会提供运行程序的功能,vscode也是如此。要运行程序,有如下几种方法:

vscode的一些拓展插件中会提供配置好的终端和运行程序的命令,我们可以直接使用;
​
vscode中有专门运行程序的拓展插件code-runner,可以安装后使用;
​
vscode提供了对数种终端的接口,我们可以在vscode中像使用cmd小黑框那样使用终端,由此我们可以在vscode终端中运行程序;

vscode的配置

首先,我们要明确vscode的配置的最小单元是文件夹,即可以使用打开文件夹功能我们可以把不同的文件夹链接到不同的外部编译器、实现不同的快捷任务、快速进行debug和详细设定拓展插件的功能等等。

vscode的配置结构

img

settings.json

在这个json文件中,我们可以通过键值对的方式设置vscode内置的或拓展插件的各项属性,其中就包括外部编译器地址、各项编译偏好等等。

同时,vscode提供层层嵌套的settings,

img

从高到低分别是全局设置、工作区设置、文件夹设置; 全局设置默认通过ctrl+shift+P后输入settings.json打开。

tasks.json

vscode就使用tasks来支持快捷实现一些方便的功能。

自定义各种各样的task,例如实现“编译当前文件”,“删除多余文件”等等操作。

tasks.json中定义的任务仅能在当前文件夹(包含该文件夹的工作区)中使用。

launch.json

这其中的内容主要是用来对调试提供支持。

c_cpp_properties.json

前提 安装C/C++ for Visual Studio Code

链接

{
  "env": {
    "myDefaultIncludePath": ["${workspaceFolder}", "${workspaceFolder}/include"],
    "myCompilerPath": "/usr/local/bin/gcc-7"
  },
  "configurations": [
    {
      "name": "Mac",
      "intelliSenseMode": "clang-x64",
      "includePath": ["${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",
      "browse": {
        "path": ["${workspaceFolder}"],
        "limitSymbolsToIncludedHeaders": true,
        "databaseFilename": ""
      }
    }
  ],
  "version": 4
}

顶级属性

env

用户自定义变量,可用于在其他配置属性中进行替换,在本例中myDefaultIncludePath即为用户自定义变量,在configurations.includePath字段下被引用 configurations 一组配置对象,向智能感知引擎提供有关你的项目和首选项的信息。默认情况下,扩展插件会根据操作系统自动创建相关信息,我们自定义配置主要就是修改这里 version 建议不要编辑这个字段,它跟踪c_cpp_properties.json文件的当前版本,以便扩展插件知道应该显示什么属性和设置,以及如何将该文件升级到最新版本

Configuration字段

  1. name 用来标识配置文件,一般是内核的名字就可以了,如"Linux"

  2. compilerPath 用于构建项目的编译器的完整路径,例如/usr/bin/gcc,以启用更精确的智能感知。扩展将查询编译器,以确定系统包含的路径和用于智能感知的默认定义(网易翻译) 在交叉编译时,将该字段设置为编译器的绝对路径就行了,例如/root/esp8266/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc

  3. compilerArgs 编译选项,之所以不重要,是因为defines的问题可以用browse解决,而include问题可以用includePath字段解决,该字段可以不写

  4. intelliSenseMode 智能感知模式,有msvc-x64.gcc-x64和clang-x64,根据编译器的前端选择就行,

  5. 例如我的xtensa编译器选的是gcc-x64

  6. includePath(重要)520/5000

    包含路径是一个包含头文件(如#include " myHeaderFile.h ")的文件夹,这些头文件包含在源文件中。指定IntelliSense引擎在搜索包含的头文件时要使用的路径列表。

    如果路径以/**结尾,智能感知引擎将从该目录开始递归搜索头文件。 用这个在要包含的主目录后面加上通配符就可以递归搜索,非常方便

  7. defines 用于智能感知引擎在解析文件时使用的预处理程序定义的列表。可以选择使用=设置一个值,例如VERSION=1,我使用vscode的目的是为了代码的智能提示,并不是要实时检测代码的正确性,所以不必要将在编译时加上的宏定义在这里写上,用browse来自动搜索可用的宏定义就行了

  8. cStandard 用于智能感知的C语言标准版本,根据实际情况确定

  9. cppStandard 用于智能感知的c++语言标准的版本,根据实际情况确定

  10. configurationProvider 用不到

  11. compileCommands The full path to the compile_commands.json file for the workspace. The include paths and defines discovered in this file will be used instead of the values set for includePath and defines settings. If the compile commands database does not contain an entry for the translation unit that corresponds to the file you opened in the editor, then a warning message will appear and the extension will use the includePath and defines settings

  12. instead. 用不到,因为有browse

  13. browse(重要) The set of properties used when “C_Cpp.intelliSenseEngine” is set to “Tag Parser” (also referred to as “fuzzy” IntelliSense, or the “browse” engine). These properties are also used by the Go To Definition/Declaration features, or when the “Default” IntelliSense engine is unable to resolve the #includes in your source files(官方文档) 如果只是将需要包含的头文件放在includePath字段中,那么include的问题解决了,但是defines的问题还没有解决,这将会出现一大堆的提示,这些提示大部分都是因为缺少相应的宏定义引起的,而browse可以搜索相应browse.path字段中所有的宏定义,并把缺少的宏定义补全,让Definition/Declaration操作可以无障碍

browse字段

很少,只有三个

  1. path A list of paths for the Tag Parser to search for headers included by your source files. If omitted, includePath will be used as the path. Searching on these paths is recursive by default. Specify * to indicate non-recursive search. For example: /usr/include will search through all subdirectories while /usr/include/* will not(官方文档) 注意通配符问题,与includePath字段不相同

  2. limitSymbolsToIncludedHeaders When true, the Tag Parser will only parse code files that have been directly or indirectly included by a source file in ${workspaceFolder}. When false, the Tag Parser will parse all code files found in the paths specified in the browse.path list.(官方文档) 通常设置为true,如果有些代码没法智能提示可以将该字段设置为false试试

  3. databaseFilename 用不上

标签:插件,框架,vscode,编译器,关键字,json,includePath,browse
来源: https://blog.csdn.net/qq_38608777/article/details/120583589