Skip to content

Commit 28b5be3

Browse files
committed
WIP
1 parent fe0db3d commit 28b5be3

File tree

1 file changed

+56
-9
lines changed

1 file changed

+56
-9
lines changed

Diff for: pkg/golinters/goanalysis/runners.go

+56-9
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,54 @@ func buildIssues(diags []Diagnostic, linterNameBuilder func(diag *Diagnostic) st
9696
} else {
9797
text = fmt.Sprintf("%s: %s", diag.Analyzer.Name, diag.Message)
9898
}
99+
/// ---
100+
101+
issue := result.Issue{
102+
FromLinter: linterName,
103+
Text: text,
104+
Pos: diag.Position,
105+
Pkg: diag.Pkg,
106+
// LineRange: &result.Range{
107+
// From: diag.SuggestedFixes[0].TextEdits[0].Pos,
108+
// To: 0,
109+
// },
110+
// Replacement: &result.Replacement{
111+
// NeedOnlyDelete: false,
112+
// NewLines: nil,
113+
// Inline: nil,
114+
// },
115+
}
116+
117+
// FIXME how to handle multiple SuggestedFixes and multiple TextEdits?
118+
119+
if len(diag.SuggestedFixes) > 0 {
120+
// issue.LineRange = &result.Range{
121+
// From: diag.Pkg.Fset.Position(diag.SuggestedFixes[0].TextEdits[0].Pos).Line,
122+
// To: diag.Pkg.Fset.Position(diag.SuggestedFixes[0].TextEdits[0].End).Line,
123+
// }
124+
125+
length := diag.Pkg.Fset.Position(diag.SuggestedFixes[0].TextEdits[0].End).Column - diag.Pkg.Fset.Position(diag.SuggestedFixes[0].TextEdits[0].Pos).Column
126+
127+
if length <= 0 {
128+
// FIXME it's a problem with the inline system, works with LineRange?
129+
}
130+
131+
println("GGGGGGG", length)
132+
133+
issue.Replacement = &result.Replacement{
134+
Inline: &result.InlineFix{
135+
StartCol: diag.Pkg.Fset.Position(diag.SuggestedFixes[0].TextEdits[0].Pos).Column - 1,
136+
Length: length,
137+
// NewString: "TEST",
138+
// Length: len(string(diag.SuggestedFixes[0].TextEdits[0].NewText)),
139+
NewString: string(diag.SuggestedFixes[0].TextEdits[0].NewText),
140+
},
141+
}
142+
}
143+
144+
issues = append(issues, issue)
145+
146+
/// ---
99147

100148
issues = append(issues, result.Issue{
101149
FromLinter: linterName,
@@ -104,17 +152,16 @@ func buildIssues(diags []Diagnostic, linterNameBuilder func(diag *Diagnostic) st
104152
Pkg: diag.Pkg,
105153
})
106154

107-
if len(diag.Related) > 0 {
108-
for _, info := range diag.Related {
109-
issues = append(issues, result.Issue{
110-
FromLinter: linterName,
111-
Text: fmt.Sprintf("%s(related information): %s", diag.Analyzer.Name, info.Message),
112-
Pos: diag.Pkg.Fset.Position(info.Pos),
113-
Pkg: diag.Pkg,
114-
})
115-
}
155+
for _, info := range diag.Related {
156+
issues = append(issues, result.Issue{
157+
FromLinter: linterName,
158+
Text: fmt.Sprintf("%s(related information): %s", diag.Analyzer.Name, info.Message),
159+
Pos: diag.Pkg.Fset.Position(info.Pos),
160+
Pkg: diag.Pkg,
161+
})
116162
}
117163
}
164+
118165
return issues
119166
}
120167

0 commit comments

Comments
 (0)