perf(extension): parallelize async operations and cache checks

This commit is contained in:
2026-04-06 14:21:03 +02:00
parent cecec8bf23
commit fd4fd87ea8
4 changed files with 587 additions and 577 deletions

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "ai-commit-ext",
"version": "0.0.1",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "ai-commit-ext",
"version": "0.0.1",
"version": "1.0.0",
"devDependencies": {
"@types/node": "^25.5.2",
"@types/vscode": "^1.110.0",

View File

@@ -2,7 +2,7 @@
"name": "ai-commit-ext",
"displayName": "AI Commit Ext",
"description": "Generate commit messages using OpenCode AI",
"version": "1.0.0",
"version": "1.0.1",
"publisher": "local",
"engines": {
"vscode": "^1.110.0"

View File

@@ -41,7 +41,11 @@ async function handleGenerateCommitMessage(): Promise<void> {
const showNotification = config.get<boolean>("showNotification", true);
try {
const opencodeAvailable = await isOpenCodeAvailable();
const [opencodeAvailable, gitExtension] = await Promise.all([
isOpenCodeAvailable(),
vscode.extensions.getExtension<GitExtension>("vscode.git"),
]);
if (!opencodeAvailable) {
if (showNotification) {
vscode.window.showErrorMessage(
@@ -51,8 +55,6 @@ async function handleGenerateCommitMessage(): Promise<void> {
return;
}
const gitExtension =
vscode.extensions.getExtension<GitExtension>("vscode.git");
if (!gitExtension) {
if (showNotification) {
vscode.window.showErrorMessage("Git extension not found");

View File

@@ -6,6 +6,8 @@ export interface GenerateOptions {
model?: string;
}
let opencodeAvailableCache: boolean | null = null;
const DEFAULT_PROMPT = `You are a helpful assistant that generates git commit messages.
Generate a concise Conventional Commit message (max 72 characters for the subject line).
Format: <type>(<scope>): <description>
@@ -15,9 +17,13 @@ Types: feat, fix, refactor, docs, style, test, chore, perf, ci, build, revert
Only output the commit message, nothing else.`;
export async function isOpenCodeAvailable(): Promise<boolean> {
if (opencodeAvailableCache !== null) {
return opencodeAvailableCache;
}
return new Promise((resolve) => {
exec("which opencode", (error: ExecException | null) => {
resolve(!error);
opencodeAvailableCache = !error;
resolve(opencodeAvailableCache);
});
});
}
@@ -32,8 +38,10 @@ export async function generateCommitMessage(
);
}
const diff = await getGitDiff();
const repoRoot = await getRepositoryRoot();
const [diff, repoRoot] = await Promise.all([
getGitDiff(),
getRepositoryRoot(),
]);
const config = vscode.workspace.getConfiguration("aiCommitExt");
const model = options.model || config.get<string>("model", "");