Skip to content

Commit

Permalink
Merge pull request #679 from DaYoung-woo/main
Browse files Browse the repository at this point in the history
[fix]#520 git 연동이 안된 프로젝트에서 무한로딩 증상 개선
  • Loading branch information
DaYoung-woo authored Sep 11, 2024
2 parents 0de4dda + 507df62 commit f18f1d8
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 47 deletions.
8 changes: 6 additions & 2 deletions packages/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export async function activate(context: vscode.ExtensionContext) {
myStatusBarItem.text = `$(check) ${projectName}`;
return;
}

const gitPath = (await findGit()).path;

const currentWorkspaceUri = vscode.workspace.workspaceFolders?.[0].uri;
Expand All @@ -57,6 +58,7 @@ export async function activate(context: vscode.ExtensionContext) {
}

const fetchBranches = async () => await getBranches(gitPath, currentWorkspacePath);

const fetchCurrentBranch = async () => {
let branchName;
try {
Expand All @@ -76,6 +78,7 @@ export async function activate(context: vscode.ExtensionContext) {
const fetchClusterNodes = async (baseBranchName = initialBaseBranchName) => {
const gitLog = await getGitLog(gitPath, currentWorkspacePath);
const gitConfig = await getGitConfig(gitPath, currentWorkspacePath, "origin");

const { owner, repo: initialRepo } = getRepo(gitConfig);
webLoader.setGlobalOwnerAndRepo(owner, initialRepo);
const repo = initialRepo[0];
Expand All @@ -89,8 +92,7 @@ export async function activate(context: vscode.ExtensionContext) {
});

const { isPRSuccess, csmDict } = await engine.analyzeGit();
if (isPRSuccess) console.log("crawling PR failed");

if (isPRSuccess) console.log("crawling PR Success");
return mapClusterNodesFrom(csmDict);
};

Expand All @@ -99,6 +101,7 @@ export async function activate(context: vscode.ExtensionContext) {
fetchBranches,
fetchCurrentBranch,
});

currentPanel = webLoader.getPanel();

currentPanel?.onDidDispose(
Expand All @@ -121,6 +124,7 @@ export async function activate(context: vscode.ExtensionContext) {
vscode.window.showErrorMessage(error.message);
} else {
vscode.window.showErrorMessage((error as Error).message);
myStatusBarItem.text = `$(diff-review-close) ${projectName}`;
}
}
});
Expand Down
104 changes: 59 additions & 45 deletions packages/vscode/src/webview-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ export default class WebviewLoader implements vscode.Disposable {
const { fetchClusterNodes, fetchBranches, fetchCurrentBranch } = fetcher;
const viewColumn = vscode.ViewColumn.One;

//캐시 초기화
console.log("Initialize cache data");
context.workspaceState.keys().forEach(key => {
context.workspaceState.update(key, undefined);
});
//캐시 초기화
console.log("Initialize cache data");
context.workspaceState.keys().forEach((key) => {
context.workspaceState.update(key, undefined);
});

this._panel = vscode.window.createWebviewPanel("WebviewLoader", "githru-view", viewColumn, {
enableScripts: true,
Expand All @@ -31,52 +31,66 @@ export default class WebviewLoader implements vscode.Disposable {

const icon_path = vscode.Uri.file(path.join(this.extensionPath, "images", "logo.png"));
this._panel.iconPath = icon_path;

let analyzedData;
this._panel.webview.onDidReceiveMessage(async (message: { command: string; payload?: string }) => {
const { command, payload } = message;

if (command === "fetchAnalyzedData" || command === "refresh") {
const baseBranchName = (payload && JSON.parse(payload)) ?? (await fetchCurrentBranch());
const storedAnalyzedData = context.workspaceState.get<ClusterNode[]>(`${ANALYZE_DATA_KEY}_${baseBranchName}`);
let analyzedData = storedAnalyzedData;
if (!storedAnalyzedData) {
console.log("No cache Data");
console.log("baseBranchName : ",baseBranchName);
analyzedData = await fetchClusterNodes(baseBranchName);
context.workspaceState.update(`${ANALYZE_DATA_KEY}_${baseBranchName}`, analyzedData);
}else console.log("Cache data exists");

// 현재 캐싱된 Branch
console.log("Current Stored data");
context.workspaceState.keys().forEach(key=>{
console.log(key);
})


const resMessage = {
command,
payload: analyzedData,
};

await this.respondToMessage(resMessage);
}
try {
const { command, payload } = message;

if (command === "fetchAnalyzedData" || command === "refresh") {
const baseBranchName = (payload && JSON.parse(payload)) ?? (await fetchCurrentBranch());

Check warning on line 40 in packages/vscode/src/webview-loader.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'baseBranchName' is assigned a value but never used
try {
const baseBranchName = (payload && JSON.parse(payload)) ?? (await fetchCurrentBranch());
const storedAnalyzedData = context.workspaceState.get<ClusterNode[]>(
`${ANALYZE_DATA_KEY}_${baseBranchName}`
);
let analyzedData = storedAnalyzedData;
if (!storedAnalyzedData) {
console.log("No cache Data");
console.log("baseBranchName : ", baseBranchName);
analyzedData = await fetchClusterNodes(baseBranchName);
context.workspaceState.update(`${ANALYZE_DATA_KEY}_${baseBranchName}`, analyzedData);
} else console.log("Cache data exists");

// 현재 캐싱된 Branch
console.log("Current Stored data");
context.workspaceState.keys().forEach((key) => {
console.log(key);
});

const resMessage = {
command,
payload: analyzedData,
};

await this.respondToMessage(resMessage);
} catch (e) {
console.error("Error fetching analyzed data:", e);
throw e;
}
}

if (command === "fetchBranchList") {
const branches = await fetchBranches();
await this.respondToMessage({
...message,
payload: branches,
});
}
if (command === "fetchBranchList") {
const branches = await fetchBranches();
await this.respondToMessage({
...message,
payload: branches,
});
}

if (command === "updatePrimaryColor") {
const colorCode = payload && JSON.parse(payload);
if (colorCode.primary) {
setPrimaryColor(colorCode.primary);
if (command === "updatePrimaryColor") {
const colorCode = payload && JSON.parse(payload);
if (colorCode.primary) {
setPrimaryColor(colorCode.primary);
}
}
} catch (e) {
console.error("An error occurred while processing the webview message:", e);
}
});

if (!analyzedData) {
this.dispose();
throw new Error("Project not connected to Git.");
}
this._panel.webview.html = this.getWebviewContent(this._panel.webview);
}

Expand Down

0 comments on commit f18f1d8

Please sign in to comment.