Skip to content

Commit d650952

Browse files
committed
✨ Add gptcommit.openConfigFile command
1 parent 20e2bac commit d650952

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@
5454
{
5555
"command": "gptcommit.disableConventionalCommit",
5656
"title": "GPTCommit: Disable conventional commit"
57+
},
58+
{
59+
"command": "gptcommit.openConfigFile",
60+
"title": "GPTCommit: Open gptcommit configuration file"
5761
}
5862
],
5963
"menus": {

src/commands/createCommandConfigs.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as vscode from 'vscode';
2+
import * as path from 'path';
23
import { getRepo, saveConfig } from '../utils';
34

45
export function setupOpenAIApiKey(context: vscode.ExtensionContext, channel: vscode.OutputChannel) {
@@ -117,3 +118,21 @@ export function disableConventionalCommit(context: vscode.ExtensionContext, chan
117118

118119
context.subscriptions.push(disableConvCommitCommand);
119120
}
121+
122+
export function openConfigFile(context: vscode.ExtensionContext, channel: vscode.OutputChannel) {
123+
let openConfigFileCommand = vscode.commands.registerCommand('gptcommit.openConfigFile', async (uri?: vscode.SourceControl) => {
124+
const repo = getRepo(uri);
125+
if (!repo) {
126+
return;
127+
}
128+
channel.appendLine(`Opening ${path.join(repo.rootUri.fsPath, ".git", "gptcommit.toml")}`);
129+
const editor = vscode.window.activeTextEditor;
130+
const doc = await vscode.workspace.openTextDocument(path.join(repo.rootUri.fsPath, ".git", "gptcommit.toml"));
131+
await vscode.window.showTextDocument(doc, {
132+
preview: false,
133+
viewColumn: editor ? editor.viewColumn : undefined,
134+
});
135+
});
136+
137+
context.subscriptions.push(openConfigFileCommand);
138+
}

src/commands/createCommandGenerateGitCommitMessage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ export default (context: vscode.ExtensionContext, channel: vscode.OutputChannel)
1717
if (repo) {
1818
repo.inputBox.value = message;
1919
}
20-
vscode.commands.executeCommand('setContext', 'gptcommit.generating', false);
2120
}).catch((err) => {
22-
vscode.commands.executeCommand('setContext', 'gptcommit.generating', false);
2321
vscode.window.showErrorMessage(err, "Show Output").then((choice) => {
2422
if (choice === "Show Output") {
2523
channel.show();
2624
}
2725
});
26+
}).finally(() => {
27+
vscode.commands.executeCommand('setContext', 'gptcommit.generating', false);
2828
});
2929
}
3030
);

src/extension.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
setOutputLanguage,
99
showPerFileSummary,
1010
disableConventionalCommit,
11+
openConfigFile,
1112
} from './commands/createCommandConfigs';
1213

1314
// This method is called when your extension is activated
@@ -30,6 +31,7 @@ export function activate(context: vscode.ExtensionContext) {
3031
setOutputLanguage(context, channel);
3132
showPerFileSummary(context, channel);
3233
disableConventionalCommit(context, channel);
34+
openConfigFile(context, channel);
3335
}
3436

3537
// This method is called when your extension is deactivated

src/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export async function getCommitMessage(
118118
viewColumn: editor ? editor.viewColumn : undefined,
119119
});
120120
progress.report({ increment: 100 });
121+
vscode.commands.executeCommand('setContext', 'gptcommit.generating', false);
121122
});
122123

123124
let disposable = vscode.workspace.onDidSaveTextDocument(async (doc) => {

0 commit comments

Comments
 (0)