From 2c7ac215d468d5372860d847edd495e2ed626920 Mon Sep 17 00:00:00 2001 From: Sigurd Tullander Date: Sat, 24 Jun 2023 10:40:40 +0200 Subject: [PATCH 1/2] Support placeholders in style config options. Also increases the version number to a new minor version, since there are new features that might something. --- package.json | 2 +- src/extension.ts | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 5ce9058..a08e082 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "clang-format", "displayName": "Clang-Format", "description": "Use Clang-Format in Visual Studio Code", - "version": "1.9.0", + "version": "1.10.0", "publisher": "xaver", "engines": { "vscode": "^1.15.0" diff --git a/src/extension.ts b/src/extension.ts index c49688f..3038a26 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -156,12 +156,24 @@ export class ClangDocumentFormattingEditProvider implements vscode.DocumentForma } private getStyle(document: vscode.TextDocument) { - let ret = vscode.workspace.getConfiguration('clang-format').get(`language.${this.getLanguage(document)}.style`); + let ret = vscode.workspace.getConfiguration('clang-format').get(`language.${this.getLanguage(document)}.style`) + .replace(/\${workspaceRoot}/g, vscode.workspace.rootPath) + .replace(/\${workspaceFolder}/g, this.getWorkspaceFolder()) + .replace(/\${cwd}/g, process.cwd()) + .replace(/\${env\.([^}]+)}/g, (sub: string, envName: string) => { + return process.env[envName]; + }); if (ret.trim()) { return ret.trim(); } - ret = vscode.workspace.getConfiguration('clang-format').get('style'); + ret = vscode.workspace.getConfiguration('clang-format').get('style') + .replace(/\${workspaceRoot}/g, vscode.workspace.rootPath) + .replace(/\${workspaceFolder}/g, this.getWorkspaceFolder()) + .replace(/\${cwd}/g, process.cwd()) + .replace(/\${env\.([^}]+)}/g, (sub: string, envName: string) => { + return process.env[envName]; + }); if (ret && ret.trim()) { return ret.trim(); } else { From 6993d4e860a3a95dcf1e6fd89afe4ce5f5638b9e Mon Sep 17 00:00:00 2001 From: Sigurd Tullander Date: Mon, 26 Jun 2023 11:11:29 +0200 Subject: [PATCH 2/2] Document placeholder support for style config in `README.md` --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index adcd6d7..d376fb2 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,8 @@ For example: - `${fileNoExtension}.cpp` - `/home/src/foo.h` will be formatted with `-assume-filename /home/src/foo.cpp`. +The same placeholders are also supported for `clang-format.style` and `clang-format.language..style`. + ## Installing Clang-Format On Linux, one can simply run `sudo apt install clang-format`.