Code-Server 配置 CPP 开发环境
Dionysen
image

Deploy once,Code anywhere!

几乎任何浏览器都可以直接得到与VScode相近的编码体验。

安装

按照官方文档安装:Install - code-server Docs (coder.com)

配置

开启 https

下载 SSL 证书,解压到一个地方
.config/code-server/config.yaml 中加入:

cert: /path/to/*.crt
cert-key: /path/to/*.key

使用systemd重启服务即可

修改字体

目前最新版 code-server 不能用,实测 v4.7.1 可以

目前只能通过加入web-font的方式修改:

git clone https://github.com/tuanpham-dev/code-server-font-patch.git
cd code-server-font-patch

# Run this command (change path-to-code-server to your code-server path, leave it empty if you install code-server from installer or code-server is in /usr/lib/code-server):
sudo ./patch.sh [path-to-code-server]

You may need to set font family in code-server settings:

"editor.fontFamily": "'Fira Code', Consolas, 'Courier New', monospace",
"terminal.integrated.fontFamily": "'Fira Code', Consolas, 'Courier New', monospace",

Install Packages

Package Function
clang Compile
clangd Language support
clang-format Format the code
lldb Debug
cmake Quick configure project

Install Plugins

Search the plugins, CodeLLDB and clangd.

Config the CMake and Clangd

Using plugin cmake tool

Open a WSL2 distro and get into a folder, input code . and press enter.
Vscode will be started. There is empty in the folder.
Press ctrl+shift+p and input cmake: quick start, select the CMake: Quick Start.
Choice the clang variant.
Input the name of you project.
A hello world program will be auto-created.
Now, you can build and run your project.

Using little tool pm

个人开发的极不成熟的小工具,用以快速管理小型c++工程。

请查看Project Manager

Config debug

Add a launch.json in the workfolder, and add configuration lldb.
Modify the program.

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug",
"program": "${workspaceFolder}/build/</*Your project name/>",
"args": [],
"cwd": "${workspaceFolder}"
}
]
}

MultiFolders

Add the include_directories(./Sources) to CMakeLists.txt .

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
include_directories(Includes)
include_directories(Sources)
......

or cd ${PROJ_DIR}/build then run command cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 in terminal.

Clang-format

编辑 .clang-format 文件

IndentWidth: 4
# Mind the blank place is a tab

Setting.json (personal backup)

这是我个人的设置备份,请不要直接复制使用,最好查明每一项作用再使用。

{
"files.autoSave": "onFocusChange",
"editor.links": false,
"editor.guides.indentation": false,
"editor.fontFamily": "'Fira Code'",
"editor.fontWeight": 400,
"terminal.integrated.fontFamily": "'Fira Code'",
"editor.fontSize": 13,
"terminal.integrated.fontSize": 13,
"editor.lineHeight": 1.5,
// "vscode-neovim.neovimInitVimPaths.linux": "~/.config/nvim/init.lua",
"editor.inlayHints.enabled": "off",
"git.enabled": false,
"markdown-preview-enhanced.codeBlockTheme": "github.css",
"markdown.preview.breaks": true,
"markdown.extension.tableFormatter.enabled": true,
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.markdownlint": true
},
"cmake.autoSelectActiveFolder": false,
"cmake.configureOnEdit": false,
"editor.lineNumbers": "on",
"workbench.editor.showTabs": true,
"editor.minimap.autohide": true,
"editor.minimap.enabled": false,
"terminal.integrated.copyOnSelection": true,
"terminal.integrated.cursorBlinking": true,
"cmake.ignoreCMakeListsMissing": true,
"vim.vimrc.path": "$HOME/backup/.vimrc",
"vim.vimrc.enable": true,
"extensions.webWorker": false,
"vim.useCtrlKeys": false,
"vim.enableNeovim": true,
"vim.neovimConfigPath": "~/backup/init.vim",
}

Termux

{
"editor.fontFamily": "'Fira Code'",
"terminal.integrated.fontFamily": "Fira Code",
"markdown.preview.breaks": true,
"editor.minimap.autohide": true,
"markdown.styles": [
"/data/data/com.termux/files/home/storage/documents/note/notes/.vscode/markdown-styles/ia_typora_night.css"
],
"editor.wordWrap": "on",
}

Issues

Font size in console of Script run (vscode plugin)

Add to stylesheet:

.script-view .line {  
font-size: 17px;
}

CMake tools 在插件商店找不到

Ctrl+p 输入命令:

ext install ms-vscode.cmake-tools

Codelldb配置

插件安装遇到问题,如下载失败,请看VS code 安装插件 lldb 调试 CPP 程序

Install codelldb and create a launch.json :

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug",
"program": "${workspaceFolder}/myvector/build/myvector",
"args": [],
"cwd": "${workspaceFolder}/myvector",
}
]
}
  • If breakpoint doesn’t work, use cmake build a debug target.

Use shell:

cmake .. -DCMAKE_BUILD_TYPE=Debug
cmake --build . --config Debug

Or add to CMakeLists.txt :

set(CMAKE_BUILD_TYPE Debug)
显示评论