MCPcopy
hub / github.com/compiler-explorer/compiler-explorer / ClangFormatTool

Class ClangFormatTool

lib/tooling/clang-format-tool.ts:33–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31import {BaseTool} from './base-tool.js';
32
33export class ClangFormatTool extends BaseTool {
34 static get key() {
35 return 'clang-format-tool';
36 }
37
38 constructor(toolInfo: ToolInfo, env: ToolEnv) {
39 super(toolInfo, env);
40
41 this.addOptionsToToolArgs = false;
42 }
43
44 override async runTool(compilationInfo: CompilationInfo, inputFilepath: string, args: string[], stdin: string) {
45 const sourcefile = inputFilepath;
46 const compilerExe = compilationInfo.compiler.exe;
47 const options = compilationInfo.options;
48 const dir = path.dirname(sourcefile);
49
50 let compileFlags = options.filter(option => option !== sourcefile);
51 if (!compilerExe.includes('clang++')) {
52 compileFlags = compileFlags.concat(this.tool.options);
53 }
54
55 await fs.writeFile(path.join(dir, 'compile_flags.txt'), compileFlags.join('\n'));
56 if (stdin !== '') {
57 const clang_format_file = path.join(dir, 'clang_format_options.txt');
58 await fs.writeFile(clang_format_file, stdin);
59 args.push(`-style=file:${clang_format_file}`);
60 }
61 return await super.runTool(compilationInfo, sourcefile, args, stdin);
62 }
63}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected