From 8ea713712a8d20f5211d0380e435bdbfd914df83 Mon Sep 17 00:00:00 2001 From: Dustin Byrne Date: Wed, 27 Nov 2024 14:06:29 -0500 Subject: [PATCH] fix: Review now includes code selections The JetBrains is still sending pinned items as 'code selections', instead of located files. This means that in IntelliJ, pinned items would not be considered during `@review`. --- packages/navie/src/commands/review-command.ts | 9 ++++++ .../test/commands/review-command.spec.ts | 28 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/packages/navie/src/commands/review-command.ts b/packages/navie/src/commands/review-command.ts index 16a119056d..d812d880f1 100644 --- a/packages/navie/src/commands/review-command.ts +++ b/packages/navie/src/commands/review-command.ts @@ -208,6 +208,15 @@ ${userPrompt} { locations } ); } + + // For backwards compatibility, include the code selections which have been sent + // without a location. + pinnedItemLookup.push( + ...pinnedItems + .filter(UserContext.isCodeSelectionItem) + .map((cs) => ({ ...cs, type: ContextV2.ContextItemType.CodeSelection })) + ); + return pinnedItemLookup; } diff --git a/packages/navie/test/commands/review-command.spec.ts b/packages/navie/test/commands/review-command.spec.ts index 733a8994d8..496ab0b3f1 100644 --- a/packages/navie/test/commands/review-command.spec.ts +++ b/packages/navie/test/commands/review-command.spec.ts @@ -303,6 +303,34 @@ lgtm }); }); + it('includes the code selections which have been sent without a location', async () => { + const content = 'here is some review criteria'; + const result = await read( + command.execute({ + question: 'review', + userOptions: new UserOptions(new Map()), + codeSelection: [ + { + type: 'code-selection', + content, + }, + { + type: 'code-snippet', + location: 'git diff', + content: 'diff content', + }, + ], + }) + ); + + const [firstArgument]: [Message[]] = (completionService.complete as jest.Mock).mock.calls[0]; + expect(result).toEqual(exampleSummaryMarkdown); + expect(firstArgument[1]).toStrictEqual({ + role: 'user', + content: expect.stringContaining(`\n${content}\n`), + }); + }); + it('includes the diff in the initial user prompt', async () => { const content = 'truly unique diff content'; const result = await read(