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

Update prompts #408

Merged
merged 11 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 27 additions & 14 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 91 additions & 0 deletions mobile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package main

import (
"fmt"
"time"
)

// Mobile struct represents a mobile device.
type Mobile struct {
Brand string
Model string
IsOn bool
Battery int
LastUsage time.Time
}
harjotgill marked this conversation as resolved.
Show resolved Hide resolved

// TurnOn turns on the mobile device.
func (m *Mobile) TurnOn() {
m.IsOn = true
m.LastUsage = time.Now()
fmt.Printf("%s %s is now turned on.\n", m.Brand, m.Model)
}

// TurnOff turns off the mobile device.
func (m *Mobile) TurnOff() {
m.IsOn = false
fmt.Printf("%s %s is now turned off.\n", m.Brand, m.Model)
}

// UseMobile simulates the usage of the mobile device.
func (m *Mobile) UseMobile(minutes int) {
if !m.IsOn {
fmt.Println("Please turn on the mobile device first.")
return
}

if m.Battery <= 0 {
fmt.Println("The mobile device is out of battery. Please charge it.")
return
}

m.LastUsage = time.Now()
fmt.Printf("Using %s %s for %d minutes.\n", m.Brand, m.Model, minutes)

// Simulate battery drain
m.Battery -= minutes
if m.Battery < 0 {
m.Battery = 0
}

// Check battery level
if m.Battery == 0 {
m.TurnOff()
fmt.Println("The mobile device is out of battery. Please charge it.")
}
}
harjotgill marked this conversation as resolved.
Show resolved Hide resolved

// ChargeMobile charges the mobile device
func (m *Mobile) ChargeMobile(minutes int) {
m.LastUsage = time.Now()
m.Battery += minutes
if m.Battery > 100 {
m.Battery = 100
}
fmt.Printf("Charging %s %s for %d minutes.\n", m.Brand, m.Model, minutes)
}
harjotgill marked this conversation as resolved.
Show resolved Hide resolved

func main() {
// Create a new mobile device
myMobile := Mobile{
Brand: "Apple",
Model: "iPhone X",
IsOn: false,
Battery: 50,
}

// Turn on the mobile device
myMobile.TurnOn()

// Simulate using the mobile device
myMobile.UseMobile(60)

// Charge the mobile device
myMobile.ChargeMobile(30)

// Simulate using the mobile device again
myMobile.UseMobile(120)

// Turn off the mobile device
myMobile.TurnOff()
}
19 changes: 9 additions & 10 deletions src/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,9 @@ format \`<line_number><colon><whitespace>\`.
line number range must map exactly to the range (inclusive) that needs to
be replaced within a new hunk. For instance, if 2 lines of code in a hunk
need to be replaced with 15 lines of code, the line number range must be
those exact 2 lines. If an entire hunk need to be replaced with new code,
then the line number range must be the entire hunk and the new code must
exactly replace ALL the lines in the hunk. Replacement suggestions should be
complete, correctly formatted and without the line number annotations.
those exact 2 lines. You must replace all the lines in the range with your
suggestion. Replacement suggestions must be complete, correctly
formatted/indented and without the line number annotations.
- If there are no issues found on a line range, you MUST respond with the
text \`LGTM!\` for that line range in the review section.
- Reflect on your comments and line number ranges before sending the final
Expand Down Expand Up @@ -207,18 +206,18 @@ format \`<line_number><colon><whitespace>\`.

---new_hunk---
\`\`\`
12: z = x / y
13: return z
14:
z = x / y
return z

15: def add(x, y):
16: z = x - y
17: retrn z
18:
19: def multiply(x, y):
20: return x * y
21:
22: def subtract(x, y):
23: z = x - y

def subtract(x, y):
z = x - y
harjotgill marked this conversation as resolved.
Show resolved Hide resolved
\`\`\`

---old_hunk---
Expand Down
26 changes: 22 additions & 4 deletions src/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,10 @@ ${SHORT_SUMMARY_END_TAG}
### Ignoring further reviews
- Type \`@coderabbitai: ignore\` anywhere in the PR description to ignore further reviews from the bot.

### Support us :)

If you like this project, please support us by purchasing the [Pro version](https://coderabbit.ai)! The Pro version has advanced context and several proprietary improvements compared to the open source version.

</details>
`

Expand Down Expand Up @@ -810,7 +814,6 @@ const parsePatch = (
const oldHunkLines: string[] = []
const newHunkLines: string[] = []

// let old_line = hunkInfo.old_hunk.start_line
let newLine = hunkInfo.newHunk.startLine

const lines = patch.split('\n').slice(1) // Skip the @@ line
Expand All @@ -820,17 +823,32 @@ const parsePatch = (
lines.pop()
}

// Skip annotations for the first 3 and last 3 lines
const skipStart = 3
const skipEnd = 3

let currentLine = 0

const removalOnly = !lines.some(line => line.startsWith('+'))

for (const line of lines) {
currentLine++
if (line.startsWith('-')) {
oldHunkLines.push(`${line.substring(1)}`)
// old_line++
} else if (line.startsWith('+')) {
newHunkLines.push(`${newLine}: ${line.substring(1)}`)
newLine++
} else {
// context line
oldHunkLines.push(`${line}`)
newHunkLines.push(`${newLine}: ${line}`)
// old_line++
if (
removalOnly ||
(currentLine > skipStart && currentLine <= lines.length - skipEnd)
) {
newHunkLines.push(`${newLine}: ${line}`)
} else {
newHunkLines.push(`${line}`)
}
harjotgill marked this conversation as resolved.
Show resolved Hide resolved
newLine++
}
}
Expand Down