Skip to content

Commit 01f5f93

Browse files
🔧 chore(webview): 重构 WebView 通信和界面逻辑
- 【架构】重构WebView和扩展通信机制,引入VSCodeAPIWrapper - 【功能】DateRangePicker的日期范围选择功能升级 - 【优化】重构编辑器组件的内容更新逻辑 - 【配置】更新vite构建配置,优化打包输出 - 【UX】优化WebView界面布局和样式 - 【SVN】添加svn相关忽略配置项 - 【调试】添加commit生成相关日志输出
1 parent 15bee62 commit 01f5f93

16 files changed

+398
-117
lines changed

.vscode/settings.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,10 @@
88
},
99
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
1010
"typescript.tsc.autoDetect": "off",
11-
"i18n-ally.localesPaths": ["i18n", "out/i18n", "src/i18n"]
11+
"i18n-ally.localesPaths": [
12+
"i18n",
13+
"out/i18n",
14+
"src/i18n"
15+
],
16+
"svn.ignoreMissingSvnWarning": true
1217
}

src/ai/providers/BaseOpenAIProvider.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export abstract class BaseOpenAIProvider implements AIProvider {
9090
model?: AIModel
9191
): Promise<AIResponse> {
9292
try {
93+
console.log("commits", commits);
9394
const response = await this.openai.chat.completions.create({
9495
model: model?.id || this.config.defaultModel || "gpt-3.5-turbo",
9596
messages: [
@@ -103,7 +104,7 @@ export abstract class BaseOpenAIProvider implements AIProvider {
103104
},
104105
],
105106
});
106-
107+
console.log("response", response);
107108
return {
108109
content: response.choices[0]?.message?.content || "",
109110
usage: {

src/scm/CommitLogStrategy.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,26 @@ import { DateUtils } from "../utils/DateUtils";
44

55
const execAsync = promisify(exec);
66

7+
interface Period {
8+
startDate: string;
9+
endDate: string;
10+
}
11+
712
export interface CommitLogStrategy {
813
getCommits(
914
workspacePath: string,
10-
period: string,
15+
period: Period,
1116
author: string
1217
): Promise<string[]>;
1318
}
1419

1520
export class GitCommitStrategy implements CommitLogStrategy {
1621
async getCommits(
1722
workspacePath: string,
18-
period: string,
23+
period: Period,
1924
author: string
2025
): Promise<string[]> {
21-
const command = `git log --since="${period}" --pretty=format:"%h - %an, %ar : %s" --author="${author}"`;
26+
const command = `git log --since="${period.startDate}" --until="${period.endDate}" --pretty=format:"%h - %an, %ar : %s" --author="${author}"`;
2227

2328
console.log("command", command);
2429
const { stdout } = await execAsync(command, { cwd: workspacePath });
@@ -29,11 +34,12 @@ export class GitCommitStrategy implements CommitLogStrategy {
2934
export class SvnCommitStrategy implements CommitLogStrategy {
3035
async getCommits(
3136
workspacePath: string,
32-
period: string,
37+
period: Period,
3338
author: string
3439
): Promise<string[]> {
35-
const { startDate, endDate } = DateUtils.getDateRangeFromPeriod(period);
36-
const command = `svn log -r "{${startDate.toISOString()}}:{${endDate.toISOString()}}" --search="${author}" --xml`;
40+
// const { startDate, endDate } = DateUtils.getDateRangeFromPeriod(period);
41+
42+
const command = `svn log -r "{${period.startDate}}:{${period.endDate}}" --search="${author}" --xml`;
3743

3844
console.log("command", command);
3945

src/scm/SCMProvider.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ export class SCMFactory {
2626
"johnstoncode.svn-scm"
2727
);
2828

29-
if (!gitExtension && !svnExtension) {
30-
throw new Error(
31-
LocalizationManager.getInstance().getMessage("scm.no.provider")
32-
);
33-
}
29+
// if (!gitExtension && !svnExtension) {
30+
// throw new Error(
31+
// LocalizationManager.getInstance().getMessage("scm.no.provider")
32+
// );
33+
// }
3434

3535
const git = gitExtension?.exports
3636
? new GitProvider(gitExtension.exports)

src/services/weeklyReport.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import {
77
GitCommitStrategy,
88
SvnCommitStrategy,
99
} from "../scm/CommitLogStrategy";
10-
10+
interface Period {
11+
startDate: string;
12+
endDate: string;
13+
}
1114
export class WeeklyReportService {
1215
private scmProvider: ISCMProvider | undefined = undefined;
1316
private commitStrategy: CommitLogStrategy | undefined = undefined;
@@ -25,7 +28,7 @@ export class WeeklyReportService {
2528
this.commitStrategy = this.createCommitStrategy(this.scmProvider.type);
2629
}
2730

28-
async generate(period: string): Promise<WorkItem[]> {
31+
async generate(period: Period): Promise<WorkItem[]> {
2932
if (!this.scmProvider || !this.commitStrategy || !this.authorService) {
3033
await this.initialize();
3134
}

src/utils/webview.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Webview, Uri } from "vscode";
2+
import * as path from "path";
3+
4+
export function getUri(
5+
webview: Webview,
6+
extensionPath: string,
7+
pathList: string[]
8+
) {
9+
return webview.asWebviewUri(Uri.file(path.join(extensionPath, ...pathList)));
10+
}
11+
12+
export function getNonce() {
13+
let text = "";
14+
const possible =
15+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
16+
for (let i = 0; i < 32; i++) {
17+
text += possible.charAt(Math.floor(Math.random() * possible.length));
18+
}
19+
return text;
20+
}

src/webview-ui/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"@radix-ui/react-toggle": "^1.1.1",
4141
"@radix-ui/react-toggle-group": "^1.1.1",
4242
"@radix-ui/react-tooltip": "^1.1.6",
43+
"@vscode/webview-ui-toolkit": "^1.4.0",
4344
"class-variance-authority": "^0.7.1",
4445
"clsx": "^2.1.1",
4546
"cmdk": "^1.0.4",
@@ -66,6 +67,7 @@
6667
"@types/node": "^22.10.2",
6768
"@types/react": "^19.0.2",
6869
"@types/react-dom": "^19.0.2",
70+
"@types/vscode-webview": "^1.57.5",
6971
"@vitejs/plugin-react": "^4.3.4",
7072
"autoprefixer": "^10.4.20",
7173
"eslint": "^9.17.0",

src/webview-ui/pnpm-lock.yaml

+72
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/webview-ui/src/App.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#root {
2-
max-width: 1280px;
32
margin: 0 auto;
43
padding: 2rem;
54
text-align: center;
5+
width: 100%;
66
}

0 commit comments

Comments
 (0)