Improve app launch speed

This commit is contained in:
2025-09-21 03:04:23 +08:00
parent e372a0dd7c
commit 0338351680
80 changed files with 1227 additions and 17065 deletions

View File

@@ -107,33 +107,38 @@ const clangParser: Parser<string> = {
locEnd: (node: string) => node.length,
};
// Initialize clang-format WASM module
// Lazy initialize clang-format WASM module
let initPromise: Promise<void> | null = null;
let isInitialized = false;
function initClangFormat(): Promise<void> {
if (initPromise) {
return initPromise;
if (isInitialized) {
return Promise.resolve();
}
initPromise = (async () => {
if (!isInitialized) {
await clangFormatInit();
isInitialized = true;
}
})();
if (!initPromise) {
initPromise = (async () => {
try {
await clangFormatInit();
isInitialized = true;
} catch (error) {
console.warn('Failed to initialize clang-format WASM module:', error);
initPromise = null;
throw error;
}
})();
}
return initPromise;
}
// Printer configuration
const clangPrinter: Printer<string> = {
print: (path, options) => {
// @ts-expect-error -- Support async printer like shell plugin
async print(path, options) {
try {
if (!isInitialized) {
console.warn('clang-format WASM module not initialized, returning original text');
return (path as any).getValue ? (path as any).getValue() : path.node;
}
// Wait for initialization to complete
await initClangFormat();
const text = (path as any).getValue ? (path as any).getValue() : path.node;
const style = getClangStyle(options);
@@ -205,11 +210,6 @@ const clangPlugin: Plugin = {
...options,
};
// Initialize WASM module when plugin loads
initClangFormat().catch(error => {
console.warn('Failed to initialize clang-format WASM module:', error);
});
export default clangPlugin;
export { languages };
export const parsers = clangPlugin.parsers;