程序员开发实例大全宝库

网站首页 > 编程文章 正文

VS code 插件配置手册(vs code代码提示插件)

zazugpt 2024-09-02 04:28:02 编程文章 21 ℃ 0 评论

本文为你介绍了常见的插件配置问题。

VS code 插件配置手册

C/C++ Tools插件---C/C++支持

安装

库文件的配置

GDB本地调试配置

GDB远程调试配置

Remote VSCode插件---远程编辑文件

安装

环境配置

在本地端的配置

在远程端的配置

工作流

Ftp Sync插件--—远程代码的同步

安装

环境配置

工作流

C/C++ Tools插件---C/C++支持

此扩展的预览版本为C / C ++添加了对Visual Studio Code的语言支持,包括:

语言服务:

代码格式(clang格式)

自动补全

符号搜索

签名帮助

快速信息

转到定义/声明

查看定义/声明

类/方法导航

调试:

支持调试Windows、Linux和macOS应用程序

断点

变量查看

逐行代码调试

支持多线程调试

支持核心转储调试

安装

在VSCode的扩展插件中找到C/C++插件并进行安装;

Windows下想开发Linux代码需要安装Mingw开发工具

库文件的配置

打开项目到工作区,

按F1打开命令行,输入:

open settings json

选择Preferences:Opem Settings (JSON),打开settings.json文件

在settings.json文件中添加:

/*****C/C++ Tools*****/

"C_Cpp.autocomplete": "Default",

"[cpp]": {

"editor.quickSuggestions": true

},

"[c]": {

"editor.quickSuggestions": true

},

"C_Cpp.default.cStandard": "c11",

"C_Cpp.default.cppStandard": "c++11",

/*****C/C++ Tools*****/

按F1打开命令行,输入:

edit configuration json

选择C/C++:Edit configurations (JSON),打开c_cpp_properties.json文件

在settings.json文件中添加:

{

"configurations": [

{

"name": "system", //系统类型

"includePath": [ //头文件目录,**表示匹配目录文件及子目录

"${workspaceFolder}/**"

],

"defines": [],

"compilerPath": "path", //编译器地址

"intelliSenseMode": "mode" //编译器类型

"cStandard": "c11",

"cppStandard": "c++11"

}

],

"version": 4

}

如:

Windows :

{

"configurations": [

{

"name": "Win32",

"includePath": [

"${workspaceFolder}/**",

"C:/opencv/build/include/opencv2/**"

],

"defines": [

"_DEBUG",

"UNICODE",

"_UNICODE"

],

"intelliSenseMode": "msvc-x64",

"cStandard": "c11",

"cppStandard": "c++11"

}

],

"version": 4

}

Linux:

{

"configurations": [

{

"name": "Linux",

"includePath": [

"${workspaceFolder}/**"

],

"defines": [],

"compilerPath": "/usr/bin/gcc",

"intelliSenseMode": "clang-x64",

"cStandard": "c11",

"cppStandard": "c++11"

}

],

"version": 4

}

GDB本地调试配置

打开项目到工作区,

打开侧栏的“调试”界面->点击“设置”按钮,选择C++(GDB/LLDB)选项:

打开launch.json文件,在文件中添加:

{

// 使用 IntelliSense 了解相关属性。

// 悬停以查看现有属性的描述。

// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387

"version": "0.2.0",

"configurations": [

{

"name": "(gdb) Launch", // 配置名称,将会在启动配置的下拉菜单中显示

"type": "cppdbg", // 配置类型,不需修改

"request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加)

"program": "${workspaceFolder}/bin文件", // 将要进行调试的程序的路径

"args": [], // 程序调试时传递给程序的命令行参数,["arg1", "arg2].

"stopAtEntry": false, // 设为true时程序将暂停在程序入口处,一般设置为false

"cwd": "${workspaceFolder}", // 程序调试程序时要搜索的代码的目录

"additionalSOLibSearchPath": "path" // 程序调试程序时要搜索的.so文件的目录(选填)

"environment": [], // 针对调试的程序,要添加到环境中的环境变量(选填)

"externalConsole": true, // 调试时是否显示控制台窗口,一般设置为true显示控制台

"MIMode": "gdb", // VSCode要使用的调试工具,必须设置为gdb或lldb

"miDebuggerPath": "path", // VSCode要使用的调试工具路径(需要绝对路径)

"preLaunchTask": "g++", // 调试开始前执行的任务,需要配置tasks.json文件(选填)

"setupCommands": [

{

"description": "Enable pretty-printing for gdb",

"text": "-enable-pretty-printing",

"ignoreFailures": true

}

]

}

]

}

如:

Windows:

{

"version": "0.2.0",

"configurations": [

{

"name": "(gdb) Launch",

"type": "cppdbg",

"request": "launch",

"program":"${workspaceRoot}/bin/pthread.exe",

"args": [],

"stopAtEntry": false,

"cwd": "${workspaceFolder}",

"externalConsole": true,

"MIMode": "gdb",

"miDebuggerPath": "C:\\MinGw\\bin\\gdb.exe"

"setupCommands": [

{

"description": "Enable pretty-printing for gdb",

"text": "-enable-pretty-printing",

"ignoreFailures": true

}

]

}

]

}

Linux:

{

"version": "0.2.0",

"configurations": [

{

"name": "(gdb local) L",

"type": "cppdbg",

"request": "launch",

"program": "${workspaceFolder}/bin/pthread",

"args": [],

"stopAtEntry": false,

"cwd": "${workspaceFolder}",

"externalConsole": true,

"MIMode": "gdb",

"setupCommands": [

{

"description": "Enable pretty-printing for gdb",

"text": "-enable-pretty-printing",

"ignoreFailures": true

}

]

}

]

}

打开侧栏的“调试”界面->点击“开始调试”按钮,开始调试

GDB远程调试配置

打开项目到工作区,

打开侧栏的“调试”界面->点击“设置”按钮,选择C++(GDB/LLDB)选项:

打开launch.json文件,在文件中添加:

{

// 使用 IntelliSense 了解相关属性。

// 悬停以查看现有属性的描述。

// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387

"version": "0.2.0",

"configurations": [

{

"name": "(gdb) Launch", // 配置名称,将会在启动配置的下拉菜单中显示

"type": "cppdbg", // 配置类型,不需修改

"request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加)

"program": "${workspaceFolder}/bin文件", // 将要进行调试的程序的路径

"args": [], // 程序调试时传递给程序的命令行参数,["arg1", "arg2].

"stopAtEntry": false, // 设为true时程序将暂停在程序入口处,一般设置为false

"cwd": "${workspaceFolder}", // 程序调试程序时的代码所在的目录

"additionalSOLibSearchPath": "path",// 程序调试程序时要搜索的.so文件的目录(选填)

"environment": [], // 针对调试的程序,要添加到环境中的环境变量(选填)

"externalConsole": true, // 调试时是否显示控制台窗口,一般设置为true显示控制台

"MIMode": "gdb", // VSCode要使用的调试工具,必须设置为gdb或lldb

"miDebuggerPath": "path", // VSCode要使用的调试工具路径(需要绝对路径)

/**********与本地调试不同的地方**********/

"miDebuggerServerAddress": "addr:port", // 要远程调试的地址,IP地址:端口号

"debugServerArgs": "args", // 调试器服务器的参数

/**********与本地调试不同的地方**********/

"preLaunchTask": "g++", // 调试开始前执行的任务,需要配置tasks.json文件(选填)

"setupCommands": [

{

"description": "Enable pretty-printing for gdb",

"text": "-enable-pretty-printing",

"ignoreFailures": true

}

]

}

]

}

如:

Linux:

{

"version": "0.2.0",

"configurations": [

{

"name": "(gdb server) L",

"type": "cppdbg",

"request": "launch",

"program": "${workspaceFolder}/bin/pthread",

"args": [],

"stopAtEntry": false,

"cwd": "${workspaceFolder}",

"externalConsole": true,

"MIMode": "gdb",

/**********与本地调试不同的地方**********/

"miDebuggerServerAddress": "192.168.0.100:2333",

"debugServerArgs": "",

/**********与本地调试不同的地方**********/

"setupCommands": [

{

"description": "Enable pretty-printing for gdb",

"text": "-enable-pretty-printing",

"ignoreFailures": true

}

]

}

]

}

先远程端:

打开一个新终端,运行gdbserver打开要调试的程序:

gdbserver localhost:port bin文件路径(与launch.json文件配置路径相同)

如:

gdbserver localhost:2333 ./bin/pthread

若想关闭gdbserver,需要在远程打开新终端,输入:

killall gdbserver

再在本地端:

打开侧栏的“调试”界面->点击“开始调试”按钮,开始调试

Remote VSCode插件---远程编辑文件

此扩展允许您轻松地获取并编辑远端文件,而不是使用命令行和 vi 编辑远端文件这种原始的操作。

安装

在VSCode的扩展插件中找到Remote VSCode插件并进行安装;

环境配置

在本地端的配置

右键点击“Remote VSCode插件”->“配置扩展设置”,在设置页面设置相应参数:

Remote:Host(本地IP地址)设置为:127.0.0.1

Remote:Port(本地通信端口)设置为:52698

Remote:Onstartup(插件自启动)设置为:false

Remote:Dont Show Port Already In Use Error(端口正在使用时不报错)设置为:false

或者,按F1打开命令行,输入:

open settings json

选择Preferences:Opem Settings (JSON),打开settings.json文件

在settings.json文件中添加:

/*****Remote VSCode*****/

"remote.host": "127.0.0.1",

"remote.port": 52698,

"remote.onstartup": false,

"remote.dontShowPortAlreadyInUseError": false,

/*****Remote VSCode*****/

在远程端的配置

远程Linux安装 rmate:

wget https://raw.githubusercontent.com/sclukey/rmate-python/master/bin/rmate

chmod +x ./rmate

mv ./rmate /usr/local/bin/rmate

工作流

启动插件

按F1打开命令行,输入:

remote:start server

选择Remote:Start Server,开启插件

附件:

使用命令行:

remote:start server :开启插件

remote:stop server :关闭插件

连接远程系统,传输编辑文件:

本地:

打开上方工具栏”终端”->“新建终点”,或按ctrl + shift + `快捷键,打开PowerShell终端:

在终端窗口中输入:

ssh -R 52698:127.0.0.1:52698 远端用户名@远端地址

如:

ssh -R 52698:127.0.0.1:52698 linux@192.168.0.111

之后输入密码ssh连接远程Linux系统即可。

远端:

在远端终端中输入:

rmate -p 52698 打开要编辑的文件

如:

rmate -p 52698 ./main.cpp

Ftp Sync插件--—远程代码的同步

此扩展允许您轻松地将项目文件 通过FTP与远端同步。

安装

在VSCode的扩展插件中找到Ftp-Sync插件并进行安装;

环境配置

新建一个目录,并打开到工作区

按F1打开命令行,输入:

ftp-sync

选择Ftp-sync: Init ,新建并打开ftp-sync.json文件,初始化配置

在ftp-sync.json文件中配置:

{

"remotePath": "path", //要传输的文件的远端站点的目录

"host": "host", //远端地址

"username": "username", //远端用户名

"password": "password", //远端密码

"protocol": "sftp", //sftp协议,默认值为ftp协议

"port": 22, //ftp默认端口是21,sftp的默认端口是22

"uploadOnSave": false, //是否应该自动保存上传文件,默认值为false

"secure": false, //安全设置,默认值为false

"ignore": [ //忽略上传路径

"\\.vscode",

"\\.git",

"\\.DS_Store"

],

"passive": false,

"debug": false,

"privateKeyPath": null,

"passphrase": null,

"agent": null,

"allow": [],

"generatedFiles": {

"extensionsToInclude": [

""

],

"path": ""

}

}

如:

{

"remotePath": "/home/linux/pro/",

"host": "192.168.0.111",

"username": "linux",

"password": "123456",

"protocol": "sftp",

"port": 22,

"uploadOnSave": false,

"secure": false,

"ignore": [

"\\.vscode",

"\\.git",

"\\.DS_Store"

],

"passive": false,

"debug": false,

"privateKeyPath": null,

"passphrase": null,

"agent": null,

"allow": [],

"generatedFiles": {

"extensionsToInclude": [

""

],

"path": ""

}

}

工作流

使用命令行:

Ftp-sync: Sync Local to Remote : 本地同步到远程

Ftp-sync: Sync Remote to Local : 远程同步到本地

Ftp-sync: Commit : 提交修改

编辑:王菁

校对:林亦霖

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表