forked from Gitlink/forgeplus-react
63 lines
1.6 KiB
JavaScript
Executable File
63 lines
1.6 KiB
JavaScript
Executable File
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() {}
|
||
}
|