mirror of
https://github.com/golang/go.git
synced 2025-05-07 00:23:03 +00:00
internal/lsp/source: move the common path to the left
As per the following guidance: "Try to keep the normal code path at a minimal indentation" I know this is normally applied to error handling, but the same logic about improving readability applies here too. Change-Id: Ib20dae9975e94b40fb6ff7049782375b18ef59ba Change-Id: Ib20dae9975e94b40fb6ff7049782375b18ef59ba GitHub-Last-Rev: 97919272de76ec15845556e032985c5969a277fa GitHub-Pull-Request: golang/tools#125 Reviewed-on: https://go-review.googlesource.com/c/tools/+/183698 Reviewed-by: Suzy Mueller <suzmue@golang.org> Run-TryBot: Suzy Mueller <suzmue@golang.org>
This commit is contained in:
parent
ba023a1bc9
commit
1a55b1581c
@ -101,26 +101,29 @@ func (r *renamer) update(ctx context.Context) (map[span.URI][]TextEdit, error) {
|
|||||||
}
|
}
|
||||||
result[refSpan.URI()] = append(result[refSpan.URI()], edit)
|
result[refSpan.URI()] = append(result[refSpan.URI()], edit)
|
||||||
|
|
||||||
if ref.isDeclaration {
|
if !ref.isDeclaration { // not a declaration
|
||||||
// Perform the rename in doc comments too (declared in the original package)
|
continue
|
||||||
if doc := r.docComment(r.pkg, ref.ident); doc != nil {
|
|
||||||
for _, comment := range doc.List {
|
|
||||||
for _, locs := range docRegexp.FindAllStringIndex(comment.Text, -1) {
|
|
||||||
rng := span.NewRange(r.fset, comment.Pos()+token.Pos(locs[0]), comment.Pos()+token.Pos(locs[1]))
|
|
||||||
spn, err := rng.Span()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
result[refSpan.URI()] = append(result[refSpan.URI()], TextEdit{
|
|
||||||
Span: spn,
|
|
||||||
NewText: r.to,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
comment.Text = docRegexp.ReplaceAllString(comment.Text, r.to)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
doc := r.docComment(r.pkg, ref.ident)
|
||||||
|
if doc == nil { // no doc comment
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Perform the rename in doc comments declared in the original package
|
||||||
|
for _, comment := range doc.List {
|
||||||
|
for _, locs := range docRegexp.FindAllStringIndex(comment.Text, -1) {
|
||||||
|
rng := span.NewRange(r.fset, comment.Pos()+token.Pos(locs[0]), comment.Pos()+token.Pos(locs[1]))
|
||||||
|
spn, err := rng.Span()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
result[refSpan.URI()] = append(result[refSpan.URI()], TextEdit{
|
||||||
|
Span: spn,
|
||||||
|
NewText: r.to,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user