Skip to content

Commit 48cce5c

Browse files
ensorrowAaaaash
andauthored
fix: edit instruction (#4456)
* feat: add user's intention in apply prompt * fix: rangesFromDiffHunk error * fix: range * chore: remove useless comment chore: remove useless comment --------- Co-authored-by: 大表哥 <[email protected]>
1 parent 66e0c9f commit 48cce5c

3 files changed

Lines changed: 11 additions & 6 deletions

File tree

packages/ai-native/src/browser/chat/apply.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class ApplyService extends BaseApplyService {
3737
<code>${fileContent}</code>
3838
3939
<update>${codeBlock.codeEdit}</update>
40-
40+
${codeBlock.instructions ? `\nUser's intention: ${codeBlock.instructions}\n` : ''}
4141
Provide the complete updated code.
4242
`,
4343
{

packages/ai-native/src/browser/mcp/base-apply.service.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,12 @@ export abstract class BaseApplyService extends WithEventBus {
222222
this.onCodeBlockUpdateEmitter.fire(codeBlock);
223223
}
224224

225-
async registerCodeBlock(relativePath: string, content: string, toolCallId: string): Promise<CodeBlockData> {
225+
async registerCodeBlock(
226+
relativePath: string,
227+
content: string,
228+
toolCallId: string,
229+
instructions?: string,
230+
): Promise<CodeBlockData> {
226231
const lastMessageId = this.chatInternalService.sessionModel.history.lastMessageId!;
227232
const uriCodeBlocks = this.getUriCodeBlocks(URI.file(path.join(this.appConfig.workspaceDir, relativePath)));
228233
const originalModelRef = await this.editorDocumentModelService.createModelReference(
@@ -237,6 +242,7 @@ export abstract class BaseApplyService extends WithEventBus {
237242
createdAt: Date.now(),
238243
toolCallId,
239244
messageId: lastMessageId,
245+
instructions,
240246
// TODO: 支持range
241247
originalCode: originalModelRef.instance.getText(),
242248
};
@@ -590,7 +596,7 @@ export abstract class BaseApplyService extends WithEventBus {
590596
.map((line) => {
591597
if (line.startsWith('@@')) {
592598
const [, , , start, lineCount] = line.match(/@@ -(\d+),(\d+) \+(\d+),(\d+) @@/)!;
593-
return new Range(parseInt(start, 10), 0, parseInt(start, 10) + parseInt(lineCount, 10), 0);
599+
return new Range(parseInt(start, 10), 0, parseInt(start, 10) + parseInt(lineCount, 10) - 1, 0);
594600
}
595601
return null;
596602
})
@@ -611,7 +617,6 @@ export abstract class BaseApplyService extends WithEventBus {
611617
result?: string;
612618
}>;
613619

614-
// TODO: 支持使用内存中的document获取诊断信息,实现并行apply accept
615620
protected getDiagnosticInfos(uri: string, ranges: Range[]) {
616621
const markers = this.markerService.getManager().getMarkers({ resource: uri });
617622
return markers.filter(

packages/ai-native/src/browser/mcp/tools/handlers/EditFile.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export class EditFileHandler {
1313
private applyService: BaseApplyService;
1414

1515
async handler(params: { targetFile: string; codeEdit: string; instructions?: string }, toolCallId: string) {
16-
const { targetFile, codeEdit } = params;
17-
const block = await this.applyService.registerCodeBlock(targetFile, codeEdit, toolCallId);
16+
const { targetFile, codeEdit, instructions } = params;
17+
const block = await this.applyService.registerCodeBlock(targetFile, codeEdit, toolCallId, instructions);
1818
const blockData = await this.applyService.apply(block);
1919
return blockData;
2020
}

0 commit comments

Comments
 (0)