forgeplus-react/src/forge/Newfile/codeReview/plugins/code-blame.plugin.js

63 lines
1.6 KiB
JavaScript
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

export const ExtensionCommand ={
acrToggleBlame : 'code.blame.acrToggleBlame',
linkToCommit : 'code.blame.linktocommit',
onActive : 'code.blame.extension.active',
setProjectData : 'code.blame.setProjectData',
getBlameData : 'code.blame.getBlameData',
}
export default class IDEPlugin {
/**
* 插件 ID用于唯一标识插件
*/
PLUGIN_ID = 'ACR_BLAME_PLUGIN';
constructor(
onActive,
linkToCommit,
getBlame
) {
this.onActivate = onActive;
// 跳转
this.linkToCommit = linkToCommit;
// 传递blame数据
this.getBlame = getBlame;
}
/**
* 激活插件
*/
activate = (ctx) => {
const { commands, context } = ctx;
this.commands = commands;
context.subscriptions.push(
commands.registerCommand(ExtensionCommand.onActive, () => {
this.onActivate();
}),
commands.registerCommand(ExtensionCommand.linkToCommit, (params) => {
const { commitId } = params;
this.linkToCommit(commitId);
}),
commands.registerCommand(
ExtensionCommand.getBlameData,
async (sendData) => {
const { projectId, prevSha, nextSha, filePath } = sendData;
// kaitian内uri 和 antcode内不同 多了一个 /
const path = filePath.startsWith('/') ? filePath.slice(1) : filePath;
const response = await this.getBlame(projectId, nextSha, path).then(
(res) => {
return res;
}
);
return response;
}
)
);
};
/**
* 注销插件,可在此时机清理副作用
*/
deactivate() {}
}