Skip to content

Commit b2a867f

Browse files
committed
initial
1 parent efae23a commit b2a867f

12 files changed

+539
-129
lines changed

error_templates/java/arithmetic_exception.go

-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ var ArithmeticException = lib.ErrorTemplate{
7373
Description: "This adjustment replaces the division by zero with a value that is not zero, ensuring the operation is valid. Division by zero is mathematically undefined, causing an 'ArithmeticException'. By changing the denominator to a non-zero value, you prevent the error.",
7474
StartPosition: cd.MainError.Nearest.StartPosition(),
7575
EndPosition: cd.MainError.Nearest.EndPosition(),
76-
Replace: true,
7776
})
7877
})
7978
case nonTerminatingDecimal:
@@ -83,7 +82,6 @@ var ArithmeticException = lib.ErrorTemplate{
8382
NewText: ", RoundingMode.HALF_UP)",
8483
StartPosition: cd.MainError.Nearest.EndPosition(),
8584
EndPosition: cd.MainError.Nearest.EndPosition(),
86-
Replace: true,
8785
})
8886
})
8987

error_templates/java/array_index_out_of_bounds_exception.go

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ var ArrayIndexOutOfBoundsException = lib.ErrorTemplate{
3838
NewText: fmt.Sprintf("%d", sampleIndex),
3939
StartPosition: cd.MainError.Nearest.StartPosition(),
4040
EndPosition: cd.MainError.Nearest.EndPosition(),
41-
Replace: true,
4241
Description: "This adjustment ensures that you're accessing an index that exists within the array bounds, preventing the `ArrayIndexOutOfBoundsException`.",
4342
})
4443
})

error_templates/java/array_required_type_error.go

-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ var ArrayRequiredTypeError = lib.ErrorTemplate{
5959
NewText: fmt.Sprintf("%s[] %s = {%s}", cd.Variables["foundType"], varNode.Text(), valueNode.Text()),
6060
StartPosition: declNode.StartPosition(),
6161
EndPosition: declNode.EndPosition(),
62-
Replace: true,
6362
})
6463
})
6564

error_templates/java/unknown_variable_error.go

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ var UnknownVariableError = lib.ErrorTemplate{
4545
NewText: fmt.Sprintf("String %s = \"\";", variable),
4646
StartPosition: ctx.rootNode.StartPosition(),
4747
EndPosition: ctx.rootNode.StartPosition(),
48-
Replace: false,
4948
})
5049
})
5150
},

error_templates/test_utils/test_utils.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func (cases TestCases) Execute(t *testing.T) {
186186
output := cases.engine.Translate(template, data)
187187
if output != tCase.ExpectedOutput {
188188
diff := dmp.DiffMain(escapeOutput(tCase.ExpectedOutput), escapeOutput(output), true)
189-
t.Errorf("\nExpected: %s\nGot: %s\nDiff: %s", tCase.ExpectedOutput, output, dmp.DiffPrettyText(diff))
189+
t.Errorf("\n======== Expected ========\n%s\n=========== Got ===========\n%s\n=========== Diff===========\n%s", tCase.ExpectedOutput, output, dmp.DiffPrettyText(diff))
190190
}
191191
})
192192
}

go.mod

-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ go 1.21
55
require (
66
github.com/sergi/go-diff v1.3.1
77
github.com/smacker/go-tree-sitter v0.0.0-20230720070738-0d0a9f78d8f8
8-
gopkg.in/src-d/go-git.v4 v4.13.1
98
)

go.sum

-44
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,23 @@
1-
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs=
2-
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
3-
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
4-
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
51
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
62
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
73
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
8-
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
9-
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
10-
github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
11-
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
12-
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
13-
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
14-
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
15-
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
164
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
175
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
18-
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
19-
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
206
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
21-
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
22-
github.com/pelletier/go-buffruneio v0.2.0/go.mod h1:JkE26KsDizTr40EUHkXVtNPvgGtbSNq5BcowyYOWdKo=
23-
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
247
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
258
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
26-
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
279
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
2810
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
2911
github.com/smacker/go-tree-sitter v0.0.0-20230720070738-0d0a9f78d8f8 h1:DxgjlvWYsb80WEN2Zv3WqJFAg2DKjUQJO6URGdf1x6Y=
3012
github.com/smacker/go-tree-sitter v0.0.0-20230720070738-0d0a9f78d8f8/go.mod h1:q99oHDsbP0xRwmn7Vmob8gbSMNyvJ83OauXPSuHQuKE=
31-
github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jWoI=
3213
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
33-
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
3414
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
35-
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
3615
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
3716
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
3817
github.com/stretchr/testify v1.7.4 h1:wZRexSlwd7ZXfKINDLsO4r7WBt3gTKONc6K/VesHvHM=
3918
github.com/stretchr/testify v1.7.4/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
40-
github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4=
41-
golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
42-
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
43-
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
44-
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
45-
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
46-
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
47-
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
48-
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
49-
golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
50-
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
51-
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
52-
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
53-
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
54-
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
55-
golang.org/x/tools v0.0.0-20190729092621-ff9f1409240a/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI=
5619
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
57-
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
58-
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
5920
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
60-
gopkg.in/src-d/go-billy.v4 v4.3.2/go.mod h1:nDjArDMp+XMs1aFAESLRjfGSgfvoYN0hDfzEk0GjC98=
61-
gopkg.in/src-d/go-git-fixtures.v3 v3.5.0/go.mod h1:dLBcvytrw/TYZsNTWCnkNF2DSIlzWYqTe3rJR56Ac7g=
62-
gopkg.in/src-d/go-git.v4 v4.13.1 h1:SRtFyV8Kxc0UP7aCHcijOMQGPxHSmMOPrzulQWolkYE=
63-
gopkg.in/src-d/go-git.v4 v4.13.1/go.mod h1:nx5NYcxdKxq5fpltdHnPa2Exj4Sx0EclMWZQbYDu2z8=
64-
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
6521
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
6622
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
6723
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

languages/python/symbols.txt

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
(import_statement
22
name: (_) @import.path) @import
33

4-
(expression_statement
5-
(assignment
6-
left: (identifier) @assignment.name
7-
right: (_) @assignment.content)) @assignment
8-
94
(function_definition
105
parameters: (parameters
116
[
@@ -14,10 +9,10 @@
149
((identifier) @parameter.name)
1510
type: (_) @parameter.return-type)
1611
]? @parameter) @parameters) @function
17-
(return_statement
12+
(return_statement
1813
(_) @block.content)?
1914

2015
(expression_statement
2116
(assignment
2217
left: (identifier) @assignment.name
23-
right: (identifier) @assignment.content) @assignment)
18+
right: (identifier) @assignment.content) @assignment)

output_gen.go

+24-17
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (gen *OutputGenerator) Generate(cd *ContextData, explain *ExplainGenerator,
7777
}
7878

7979
gen.generateFromExp(1, explain)
80-
doc := cd.MainError.Document.CopyContentsOnly()
80+
doc := cd.MainError.Document
8181

8282
if gen.IsTesting {
8383
startRow := cd.MainError.Nearest.StartPoint().Row
@@ -113,6 +113,8 @@ func (gen *OutputGenerator) Generate(cd *ContextData, explain *ExplainGenerator,
113113
gen.heading(2, "Steps to fix")
114114

115115
if bugFix.Suggestions != nil && len(bugFix.Suggestions) != 0 {
116+
editedDoc := doc.Editable()
117+
116118
for sIdx, s := range bugFix.Suggestions {
117119
if len(bugFix.Suggestions) == 1 {
118120
gen.heading(3, s.Title)
@@ -132,28 +134,32 @@ func (gen *OutputGenerator) Generate(cd *ContextData, explain *ExplainGenerator,
132134
}
133135

134136
for fIdx, fix := range step.Fixes {
135-
gen.writeln("```diff")
136-
startLine := fix.StartPosition.Line
137-
gen.writeLines(doc.LinesAt(startLine-2, startLine)...)
137+
editedDoc.Apply(Changeset{
138+
NewText: fix.NewText,
139+
StartPos: fix.StartPosition,
140+
EndPos: fix.EndPosition,
141+
})
138142

139-
gen.write("- ")
140-
gen.writeln(doc.LineAt(fix.StartPosition.Line))
143+
startLine := fix.StartPosition.Line
144+
afterLine := fix.EndPosition.Line
141145

142-
gen.write("+ ")
143-
gen.write(doc.LineAt(fix.StartPosition.Line)[:fix.StartPosition.Column])
144-
gen.write(fix.NewText)
146+
gen.writeln("```diff")
147+
gen.writeLines(editedDoc.LinesAt(startLine-2, startLine)...)
145148

146-
if fix.Replace {
147-
gen.write(doc.LineAt(fix.StartPosition.Line)[fix.EndPosition.Column:])
149+
original := editedDoc.LinesAt(startLine, afterLine)
150+
for _, origLine := range original {
151+
gen.write("- ")
152+
gen.writeln(origLine)
148153
}
149154

150-
gen._break()
151-
afterLine := startLine
152-
if fix.Replace {
153-
afterLine++
155+
modified := editedDoc.ModifiedLinesAt(startLine, afterLine)
156+
for _, modifiedLine := range modified {
157+
gen.write("+ ")
158+
gen.writeln(modifiedLine)
154159
}
155160

156-
gen.writeLines(doc.LinesAt(afterLine, min(afterLine+2, doc.TotalLines()))...)
161+
gen._break()
162+
gen.writeLines(editedDoc.LinesAt(afterLine, min(afterLine+2, editedDoc.TotalLines()))...)
157163
gen.writeln("```")
158164

159165
if fIdx < len(step.Fixes)-1 {
@@ -163,8 +169,9 @@ func (gen *OutputGenerator) Generate(cd *ContextData, explain *ExplainGenerator,
163169
}
164170
}
165171
}
172+
173+
editedDoc.Reset()
166174
}
167-
// gen._break()
168175
} else {
169176
gen.writeln("Nothing to fix")
170177
}

0 commit comments

Comments
 (0)