Skip to content

Commit

Permalink
🔧 chore(webview): 重构 WebView 通信和界面逻辑
Browse files Browse the repository at this point in the history
- 【架构】重构WebView和扩展通信机制,引入VSCodeAPIWrapper
- 【功能】DateRangePicker的日期范围选择功能升级
- 【优化】重构编辑器组件的内容更新逻辑
- 【配置】更新vite构建配置,优化打包输出
- 【UX】优化WebView界面布局和样式
- 【SVN】添加svn相关忽略配置项
- 【调试】添加commit生成相关日志输出
  • Loading branch information
littleCareless committed Jan 2, 2025
1 parent 15bee62 commit 01f5f93
Show file tree
Hide file tree
Showing 16 changed files with 398 additions and 117 deletions.
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off",
"i18n-ally.localesPaths": ["i18n", "out/i18n", "src/i18n"]
"i18n-ally.localesPaths": [
"i18n",
"out/i18n",
"src/i18n"
],
"svn.ignoreMissingSvnWarning": true
}
3 changes: 2 additions & 1 deletion src/ai/providers/BaseOpenAIProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export abstract class BaseOpenAIProvider implements AIProvider {
model?: AIModel
): Promise<AIResponse> {
try {
console.log("commits", commits);
const response = await this.openai.chat.completions.create({
model: model?.id || this.config.defaultModel || "gpt-3.5-turbo",
messages: [
Expand All @@ -103,7 +104,7 @@ export abstract class BaseOpenAIProvider implements AIProvider {
},
],
});

console.log("response", response);
return {
content: response.choices[0]?.message?.content || "",
usage: {
Expand Down
18 changes: 12 additions & 6 deletions src/scm/CommitLogStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,26 @@ import { DateUtils } from "../utils/DateUtils";

const execAsync = promisify(exec);

interface Period {
startDate: string;
endDate: string;
}

export interface CommitLogStrategy {
getCommits(
workspacePath: string,
period: string,
period: Period,
author: string
): Promise<string[]>;
}

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

console.log("command", command);
const { stdout } = await execAsync(command, { cwd: workspacePath });
Expand All @@ -29,11 +34,12 @@ export class GitCommitStrategy implements CommitLogStrategy {
export class SvnCommitStrategy implements CommitLogStrategy {
async getCommits(
workspacePath: string,
period: string,
period: Period,
author: string
): Promise<string[]> {
const { startDate, endDate } = DateUtils.getDateRangeFromPeriod(period);
const command = `svn log -r "{${startDate.toISOString()}}:{${endDate.toISOString()}}" --search="${author}" --xml`;
// const { startDate, endDate } = DateUtils.getDateRangeFromPeriod(period);

const command = `svn log -r "{${period.startDate}}:{${period.endDate}}" --search="${author}" --xml`;

console.log("command", command);

Expand Down
10 changes: 5 additions & 5 deletions src/scm/SCMProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ export class SCMFactory {
"johnstoncode.svn-scm"
);

if (!gitExtension && !svnExtension) {
throw new Error(
LocalizationManager.getInstance().getMessage("scm.no.provider")
);
}
// if (!gitExtension && !svnExtension) {
// throw new Error(
// LocalizationManager.getInstance().getMessage("scm.no.provider")
// );
// }

const git = gitExtension?.exports
? new GitProvider(gitExtension.exports)
Expand Down
7 changes: 5 additions & 2 deletions src/services/weeklyReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import {
GitCommitStrategy,
SvnCommitStrategy,
} from "../scm/CommitLogStrategy";

interface Period {
startDate: string;
endDate: string;
}
export class WeeklyReportService {
private scmProvider: ISCMProvider | undefined = undefined;
private commitStrategy: CommitLogStrategy | undefined = undefined;
Expand All @@ -25,7 +28,7 @@ export class WeeklyReportService {
this.commitStrategy = this.createCommitStrategy(this.scmProvider.type);
}

async generate(period: string): Promise<WorkItem[]> {
async generate(period: Period): Promise<WorkItem[]> {
if (!this.scmProvider || !this.commitStrategy || !this.authorService) {
await this.initialize();
}
Expand Down
20 changes: 20 additions & 0 deletions src/utils/webview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Webview, Uri } from "vscode";
import * as path from "path";

export function getUri(
webview: Webview,
extensionPath: string,
pathList: string[]
) {
return webview.asWebviewUri(Uri.file(path.join(extensionPath, ...pathList)));
}

export function getNonce() {
let text = "";
const possible =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (let i = 0; i < 32; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
}
2 changes: 2 additions & 0 deletions src/webview-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@radix-ui/react-toggle": "^1.1.1",
"@radix-ui/react-toggle-group": "^1.1.1",
"@radix-ui/react-tooltip": "^1.1.6",
"@vscode/webview-ui-toolkit": "^1.4.0",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"cmdk": "^1.0.4",
Expand All @@ -66,6 +67,7 @@
"@types/node": "^22.10.2",
"@types/react": "^19.0.2",
"@types/react-dom": "^19.0.2",
"@types/vscode-webview": "^1.57.5",
"@vitejs/plugin-react": "^4.3.4",
"autoprefixer": "^10.4.20",
"eslint": "^9.17.0",
Expand Down
72 changes: 72 additions & 0 deletions src/webview-ui/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/webview-ui/src/App.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
width: 100%;
}
Loading

0 comments on commit 01f5f93

Please sign in to comment.