MCPcopy Create free account
hub / github.com/compiler-explorer/compiler-explorer / initialize

Method initialize

lib/formatting-service.ts:59–100  ·  view source on GitHub ↗
(ceProps: PropertyGetter)

Source from the content-addressed store, hash-verified

57 }
58
59 public async initialize(ceProps: PropertyGetter): Promise<void> {
60 const formatters = _.compact(ceProps('formatters', '').split(':'));
61 for (const formatter of formatters) {
62 logger.info(`Performing discovery of formatter named ${formatter}`);
63 const executable = ceProps<string>(`formatter.${formatter}.exe`);
64 const type = ceProps<string>(`formatter.${formatter}.type`);
65 if (!executable) {
66 logger.warn(`Formatter ${formatter} does not have a valid executable. Skipping...`);
67 continue;
68 }
69 if (!type) {
70 logger.warn(`Formatter ${formatter} does not have a valid type. Skipping...`);
71 continue;
72 }
73 const versionArgument = ceProps<string>(`formatter.${formatter}.version`, '--version');
74 const versionRegExp = ceProps<string>(`formatter.${formatter}.versionRe`, '.*');
75 const hasExplicitVersion = ceProps(`formatter.${formatter}.explicitVersion`, '') !== '';
76 try {
77 const result = await exec.execute(executable, [versionArgument], {});
78 const match = result.stdout.match(versionRegExp);
79 const formatterClass = getFormatterTypeByKey(type);
80 const styleList = ceProps<string>(`formatter.${formatter}.styles`, '');
81 const styles = styleList === '' ? [] : styleList.split(':');
82 // If there is an explicit version, grab it. Otherwise, try to filter the output
83 const version = hasExplicitVersion
84 ? ceProps<string>(`formatter.${formatter}.explicitVersion`)
85 : match
86 ? match[0]
87 : result.stdout;
88 const instance = new formatterClass({
89 name: ceProps(`formatter.${formatter}.name`, executable),
90 exe: executable,
91 version,
92 styles,
93 type,
94 });
95 this.registry.set(formatter, instance);
96 } catch (err: unknown) {
97 logger.warn(`Error while fetching tool info for ${executable}:`, {err});
98 }
99 }
100 }
101}

Callers 8

loadConfigurationFunction · 0.45
properties-test.tsFile · 0.45
exec-tests.tsFile · 0.45
checks.tsFile · 0.45
builtin-tests.tsFile · 0.45

Calls 3

matchMethod · 0.80
executeMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected