✨ feat(vscode): 有说明的函数、类卡片也能重写注释

重写按钮不再只挂在单独的注释卡片上。只替换说明那几行,上下文用这块代码,不当成文件顶上的说明。
This commit is contained in:
cruldra committed 2026-10-03 03:22:20 +08:00
1 parent b608f6cb87
commit a66e4410e7
5 files changed
+46 -7

No files matched your search

@@ -147,6 +147,20 @@ describe('重写注释的提示', () => {
expect(isModuleComment('"""旧"""', ['function'])).toBe(false)
})
it('函数上的说明用这块代码当上下文,不当成文件顶上的说明', () => {
const prompt = commentRewritePrompt({
comment: '"""旧说明"""',
source: 'def run():\n """旧说明"""\n return 1\n\ndef other():\n return 2',
startLine: 1,
endLine: 1,
earlierKinds: [],
attached: 'def run():\n return 1',
})
expect(prompt).toContain('def run():')
expect(prompt).toContain('return 1')
expect(prompt).not.toContain('def other()')
})
it('模型套了代码围栏时只留里面的正文', () => {
expect(modelCommentBody('```\n新说明\n```')).toBe('新说明')
expect(modelCommentBody(' ')).toBeUndefined()