Skip to content
This repository was archived by the owner on Mar 6, 2024. It is now read-only.

Commit 010da63

Browse files
committed
single line comments
1 parent 5e10fbe commit 010da63

File tree

3 files changed

+111
-86
lines changed

3 files changed

+111
-86
lines changed

dist/index.js

Lines changed: 56 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/prompts.ts

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ The format for changes provided below consists of multiple change
105105
sections, each containing a new hunk (annotated with line numbers),
106106
an old hunk, and optionally, existing comment chains. Note that the
107107
old hunk code has been replaced by the new hunk. The line number
108-
annotation on each line in the new hunk is of the
109-
format \`<line_number><colon><whitespace>\`.
108+
annotations on lines in the new hunk is of the format
109+
\`<line_number><colon><whitespace>\`.
110110
111111
### Format for changes
112112
@@ -128,13 +128,54 @@ format \`<line_number><colon><whitespace>\`.
128128
---end_change_section---
129129
...
130130
131+
### Response format expected
132+
133+
<start_line_number>-<end_line_number>:
134+
<review comment>
135+
---
136+
<start_line_number>-<end_line_number>:
137+
<review comment>
138+
\`\`\`suggestion
139+
<code/text that replaces everything between start_line_number and end_line_number>
140+
\`\`\`
141+
---
142+
<start_line_number>-<end_line_number>:
143+
<review comment>
144+
\`\`\`<language>
145+
<new code snippet>
146+
\`\`\`
147+
---
148+
...
149+
150+
131151
## IMPORTANT: Response Instructions
132152
133153
- Your task is to review ONLY the new hunks line by line, ONLY pointing out
134154
substantive issues within line number ranges. Provide the exact line
135155
number range (inclusive) for each issue. Take into account any supplementary
136156
context from the old hunks, comment threads, and file contents during your
137-
review process.
157+
review process.
158+
- Respond only in the above response format (consisting of review
159+
sections). Each review section must have a line number range and a review
160+
comment for that range. Use separator after each review section.
161+
- Line number ranges for each review section must be within the
162+
range of a specific new hunk. <start_line_number> must belong to the same
163+
hunk as the <end_line_number>.
164+
- Use Markdown format for review comment text and fenced code blocks for
165+
code snippets.
166+
- If needed, suggest new code snippets using the relevant language identifier
167+
in the fenced code blocks. These snippets may be added to a different file
168+
(e.g. test cases), or within the same file at locations outside the provided
169+
hunks. Multiple new code snippets are allowed within a single review section.
170+
- If needed, provide replacement code to fix the issues by using fenced code
171+
blocks with the \`suggestion\` or the \`diff\` as the language identifier/format,
172+
depending on whether the suggestion is a few lines of code (~15 lines) or
173+
a larger diff (> 15 lines) respectively. The line number range must map
174+
exactly to the range (inclusive) that needs to be replaced within a new hunk.
175+
For instance, if 2 lines of code in a hunk need to be replaced with 15 lines of
176+
code, the line number range must be those exact 2 lines. You must replace all
177+
the lines in the range with your suggestion. Replacement suggestions must be complete,
178+
correctly formatted/indented and without the line number annotations.
138179
- Understand that the hunk provided for review is a part of a larger codebase
139180
and may not include all relevant parts, such as definitions, imports, or uses
140181
of functions or variables. You may see incomplete fragments of code or
@@ -156,51 +197,11 @@ format \`<line_number><colon><whitespace>\`.
156197
and is aware of their implications on the entire system. Instead of
157198
making generic comments about potential impacts on the system, focus
158199
on providing specific, objective insights based on the code itself.
159-
- Respond only in the below response format (consisting of review
160-
sections). Each review section must have a line number range and a review
161-
comment for that range. Use separator after each review section.
162-
- Line number ranges for each review section must be within the
163-
range of a specific new hunk. <start_line_number> must belong to the same
164-
hunk as the <end_line_number>.
165-
- Use Markdown format for review comment text and fenced code blocks for
166-
code snippets.
167-
- If needed, suggest new code snippets using the relevant language identifier
168-
in the fenced code blocks. These snippets may be added to a different file
169-
(e.g. test cases), or within the same file at locations outside the provided
170-
hunks. Multiple new code snippets are allowed within a single review section.
171-
- If needed, provide replacement code to fix the issues by using fenced code
172-
blocks with the \`suggestion\` or the \`diff\` as the language identifier/format,
173-
depending on whether the suggestion is a few lines of code (~15 lines) or
174-
a larger diff (> 15 lines) respectively. The line number range must map
175-
exactly to the range (inclusive) that needs to be replaced within a new hunk.
176-
For instance, if 2 lines of code in a hunk need to be replaced with 15 lines of
177-
code, the line number range must be those exact 2 lines. You must replace all
178-
the lines in the range with your suggestion. Replacement suggestions must be complete,
179-
correctly formatted/indented and without the line number annotations.
180200
- If there are no issues found on a line range, you MUST respond with the
181201
text \`LGTM!\` for that line range in the review section.
182202
- Reflect on your comments and line number ranges before sending the final
183203
response to ensure accuracy of line number ranges and replacement snippets.
184204
185-
### Response format expected
186-
187-
<start_line_number>-<end_line_number>:
188-
<review comment>
189-
---
190-
<start_line_number>-<end_line_number>:
191-
<review comment>
192-
\`\`\`suggestion
193-
<code/text that replaces everything between start_line_number and end_line_number>
194-
\`\`\`
195-
---
196-
<start_line_number>-<end_line_number>:
197-
<review comment>
198-
\`\`\`<language>
199-
<new code snippet>
200-
\`\`\`
201-
---
202-
...
203-
204205
## Example
205206
206207
### Example changes

src/review.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,7 @@ function parseReview(
874874

875875
const lines = response.split('\n')
876876
const lineNumberRangeRegex = /(?:^|\s)(\d+)-(\d+):\s*$/
877+
const lineNumberSingleRegex = /(?:^|\s)(\d+):\s*$/ // New single line regex
877878
const commentSeparator = '---'
878879

879880
let currentStartLine: number | null = null
@@ -976,6 +977,7 @@ ${review.comment}`
976977

977978
for (const line of lines) {
978979
const lineNumberRangeMatch = line.match(lineNumberRangeRegex)
980+
const lineNumberSingleMatch = line.match(lineNumberSingleRegex) // Check for single line match
979981

980982
if (lineNumberRangeMatch != null) {
981983
storeReview()
@@ -986,6 +988,15 @@ ${review.comment}`
986988
info(`Found line number range: ${currentStartLine}-${currentEndLine}`)
987989
}
988990
continue
991+
} else if (lineNumberSingleMatch != null) {
992+
storeReview()
993+
currentStartLine = parseInt(lineNumberSingleMatch[1], 10)
994+
currentEndLine = currentStartLine // For single line comments, start and end are the same
995+
currentComment = ''
996+
if (debug) {
997+
info(`Found single line comment: ${currentStartLine}`)
998+
}
999+
continue
9891000
}
9901001

9911002
if (line.trim() === commentSeparator) {

0 commit comments

Comments
 (0)