Skip to content

Commit 2bbefaa

Browse files
committed
Merge branch 'yrom-feat/config-diff-threshold'
2 parents e07a539 + 990d636 commit 2bbefaa

File tree

5 files changed

+22
-6
lines changed

5 files changed

+22
-6
lines changed

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,13 @@
199199
".DS_Store"
200200
]
201201
},
202+
"diffy-explain-ai.largeDiffThreshold": {
203+
"type": "number",
204+
"order": 6.5,
205+
"default": 2100,
206+
"minimum": 500,
207+
"markdownDescription": "Character length threshold to treat diffs as 'large'.\n\nWhen the diff text length is greater than or equal to this value, Diffy switches to name-only mode to reduce token usage.\n\n- **2100** *(Default)*: Balanced for most projects\n- Increase for more detailed diffs\n- Decrease for stricter token savings"
208+
},
202209
"diffy-explain-ai.respectGitignore": {
203210
"type": "boolean",
204211
"order": 7,

src/Diffy.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ class Diffy extends BaseDiffy {
205205
if (!diff) {
206206
return;
207207
}
208-
if (diff && diff.length >= 2100) {
208+
const largeThreshold = this.workspaceService?.getLargeDiffThreshold?.() ?? 2100;
209+
if (diff && diff.length >= largeThreshold) {
209210
nameOnly = true;
210211
diff = await this.gitService?.getDiffAndWarnUser(repo, true, nameOnly);
211212
}
@@ -302,7 +303,8 @@ class Diffy extends BaseDiffy {
302303
if (!diff) {
303304
return;
304305
}
305-
if (diff && diff.length >= 2100) {
306+
const largeThreshold = this.workspaceService?.getLargeDiffThreshold?.() ?? 2100;
307+
if (diff && diff.length >= largeThreshold) {
306308
nameOnly = true;
307309
diff = await this.gitService?.getDiffAndWarnUser(repo, true, nameOnly);
308310
}
@@ -525,7 +527,8 @@ class Diffy extends BaseDiffy {
525527
if (!diff) {
526528
return;
527529
}
528-
if (diff && diff.length >= 2100) {
530+
const largeThreshold = this.workspaceService?.getLargeDiffThreshold?.() ?? 2100;
531+
if (diff && diff.length >= largeThreshold) {
529532
nameOnly = true;
530533
const newDiff = await this.gitService?.getDiffAndWarnUser(repo, true, nameOnly);
531534
if (!newDiff) {

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// The module 'vscode' contains the VS Code extensibility API
22
// Import the module and reference it with the alias vscode in your code below
33
import * as vscode from "vscode";
4-
import type { API as GitApi, GitExtension, Repository } from "./@types/git";
4+
import type { GitExtension, Repository } from "./@types/git";
55
import Diffy from "./Diffy";
66

77
let app: Diffy | null = null;

src/service/GitService.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,13 @@ class GitService {
110110
this.showInformationMessage("No Changes");
111111
}
112112
}
113-
return null;
114113
}
115114
if (!silent) {
116115
this.showInformationMessage("No changes");
117116
}
118117
}
119118
return diff;
120119
}
121-
122120
/**
123121
* Check if a file path matches any of the exclusion patterns
124122
* @param filePath - The file path to check

src/service/WorkspaceService.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,14 @@ export default class WorkspaceService extends EventEmitter {
149149
return value;
150150
}
151151

152+
/**
153+
* Threshold for switching to name-only diff mode for large diffs
154+
*/
155+
getLargeDiffThreshold(): number {
156+
const value = this.getConfiguration().get("largeDiffThreshold");
157+
return typeof value === "number" && value > 0 ? value : 2100;
158+
}
159+
152160
getCommitMessageType() {
153161
const value = String(this.getConfiguration().get("commitMessageType"));
154162
return value || "conventional";

0 commit comments

Comments
 (0)