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`. 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 {