Skip to content

Commit 54fef04

Browse files
author
guqiankun
committed
chore: 修改插件初始化逻辑
1 parent 57c130c commit 54fef04

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

  • packages/integrations/src/antcode-cr

packages/integrations/src/antcode-cr/index.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { useEffect, useRef, useState } from 'react';
2+
import { useEffect, useState, useMemo } from 'react';
33
import ReactDOM from 'react-dom';
44
import { Button, Switch } from 'antd';
55
import 'antd/dist/antd.css';
@@ -84,15 +84,14 @@ const App = () => {
8484

8585
// 插件
8686
const [pluginActivated, setPluginActivated] = useState(false);
87-
const blamePlugin = useRef(
88-
new CodeBlamePlugin(
87+
const blamePlugin = useMemo(() => {
88+
return new CodeBlamePlugin(
8989
() => setPluginActivated(true),
9090
(commitId: string) =>
9191
window.open(`/${project.namespace.path}/${project.path}/commit/${commitId}`),
9292
(projectId, commitId, path) => repoService.getCodeBlame(projectId, commitId, path)
93-
)
94-
);
95-
93+
);
94+
}, []);
9695
useEffect(() => {
9796
if (!pluginActivated) {
9897
return;
@@ -102,7 +101,7 @@ const App = () => {
102101
prevSha: diffsPack.fromVersion?.headCommitSha ?? diffsPack.toVersion.baseCommitSha,
103102
nextSha: diffsPack.toVersion.headCommitSha,
104103
};
105-
blamePlugin.current.commands?.executeCommand(ExtensionCommand.setProjectData, projectData);
104+
blamePlugin.commands?.executeCommand(ExtensionCommand.setProjectData, projectData);
106105
}, [pluginActivated, diffsPack]);
107106

108107
// const extensionMetadata = useLoadLocalExtensionMetadata();
@@ -183,7 +182,7 @@ const App = () => {
183182
staticServicePath: Uri.parse(window.location.href)
184183
.with({ path: path.join('/antcode', project.pathWithNamespace, 'raw') })
185184
.toString(),
186-
plugins: [acrPlugin, CodeScaningPlugin, blamePlugin.current],
185+
plugins: [acrPlugin, CodeScaningPlugin, blamePlugin],
187186
extensionMetadata: [CodeScaning, CodeBlame],
188187
// extensionMetadata,
189188
},

0 commit comments

Comments
 (0)