VSCode Clang-Format 插件使用教程

VSCode Clang-Format 插件使用教程

vscode-clang-formatA Visual Studio Code extension that provides C++, C, Obj-C, Java formatting with the use of clang-format项目地址:https://gitcode.com/gh_mirrors/vs/vscode-clang-format

项目目录结构及介绍

VSCode Clang-Format 插件的目录结构如下:

vscode-clang-format/
├── CHANGELOG.md
├── README.md
├── package.json
├── src/
│   ├── clangFormat.ts
│   ├── extension.ts
│   └── test/
│       ├── runTest.ts
│       └── suite/
│           ├── extension.test.ts
│           └── index.ts
├── syntaxes/
│   └── clang-format.json
└── vscode.png
  • CHANGELOG.md: 记录项目的更新日志。
  • README.md: 项目的主要介绍文档。
  • package.json: 项目的元数据文件,包含依赖、脚本等信息。
  • src/: 源代码目录。
    • clangFormat.ts: 主要功能实现文件。
    • extension.ts: 插件入口文件。
    • test/: 测试代码目录。
      • runTest.ts: 测试运行文件。
      • suite/: 测试套件目录。
        • extension.test.ts: 插件测试文件。
        • index.ts: 测试索引文件。
  • syntaxes/: 语法定义目录。
    • clang-format.json: Clang-Format 语法定义文件。
  • vscode.png: 项目图标。

项目的启动文件介绍

项目的启动文件是 src/extension.ts。这个文件是插件的入口点,负责初始化和注册插件的主要功能。以下是 extension.ts 的主要内容:

import * as vscode from 'vscode';
import { ClangFormatProvider } from './clangFormat';

export function activate(context: vscode.ExtensionContext) {
    const provider = new ClangFormatProvider();
    context.subscriptions.push(
        vscode.languages.registerDocumentFormattingEditProvider('cpp', provider)
    );
}

export function deactivate() {}
  • activate: 插件激活时调用的函数,注册文档格式化提供者。
  • deactivate: 插件停用时调用的函数。

项目的配置文件介绍

项目的配置文件主要是 package.json。这个文件包含了插件的所有元数据和配置信息。以下是 package.json 的部分内容:

{
    "name": "vscode-clang-format",
    "displayName": "Clang-Format",
    "description": "VS Code extension to format C/C++ code using Clang-Format.",
    "version": "1.9.0",
    "publisher": "xaverh",
    "engines": {
        "vscode": "^1.52.0"
    },
    "categories": [
        "Formatters"
    ],
    "activationEvents": [
        "onLanguage:cpp",
        "onLanguage:c"
    ],
    "main": "./out/extension.js",
    "contributes": {
        "configuration": {
            "type": "object",
            "title": "Clang-Format configuration",
            "properties": {
                "clang-format.style": {
                    "type": "string",
                    "default": "file",
                    "description": "Clang-Format style to use."
                },
                "clang-format.executable": {
                    "type": "string",
                    "default": "clang-format",
                    "description": "Path to the clang-format executable."
                }
            }
        }
    },
    "scripts": {
        "vscode:prepublish": "npm run compile",
        "compile": "tsc -p ./",
        "watch": "tsc -watch -p ./",
        "pretest": "npm run compile && npm run lint",
        "lint": "eslint src --ext ts",
        "test": "node ./out/test/runTest.js"
    },
    "devDependencies": {
        "@types/vscode": "^1.52.0",
        "@types/glob": "^7.1.3",
        "@types/mocha": "^8.2.0",
        "@types/node": "^12.11.7",
        "eslint":

vscode-clang-formatA Visual Studio Code extension that provides C++, C, Obj-C, Java formatting with the use of clang-format项目地址:https://gitcode.com/gh_mirrors/vs/vscode-clang-format

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

甄墨疆

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值