mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
go/{ast,doc}: update BasicLit.ValueEnd as well as ValuePos
For #76395 Change-Id: Ie2ad715a05cb298b08667cfe8a8394f1dfa3936c Reviewed-on: https://go-review.googlesource.com/c/go/+/722880 Reviewed-by: Robert Findley <rfindley@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
32a9804c7b
commit
fa30b68767
2 changed files with 24 additions and 2 deletions
|
|
@ -222,7 +222,7 @@ func sortSpecs(fset *token.FileSet, f *File, d *GenDecl, specs []Spec) []Spec {
|
||||||
if s.Name != nil {
|
if s.Name != nil {
|
||||||
s.Name.NamePos = pos[i].Start
|
s.Name.NamePos = pos[i].Start
|
||||||
}
|
}
|
||||||
s.Path.ValuePos = pos[i].Start
|
updateBasicLitPos(s.Path, pos[i].Start)
|
||||||
s.EndPos = pos[i].End
|
s.EndPos = pos[i].End
|
||||||
for _, g := range importComments[s] {
|
for _, g := range importComments[s] {
|
||||||
for _, c := range g.cg.List {
|
for _, c := range g.cg.List {
|
||||||
|
|
@ -245,3 +245,14 @@ func sortSpecs(fset *token.FileSet, f *File, d *GenDecl, specs []Spec) []Spec {
|
||||||
|
|
||||||
return specs
|
return specs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// updateBasicLitPos updates lit.Pos,
|
||||||
|
// ensuring that lit.End is displaced by the same amount.
|
||||||
|
// (See https://go.dev/issue/76395.)
|
||||||
|
func updateBasicLitPos(lit *BasicLit, pos token.Pos) {
|
||||||
|
len := lit.End() - lit.Pos()
|
||||||
|
lit.ValuePos = pos
|
||||||
|
if lit.ValueEnd.IsValid() {
|
||||||
|
lit.ValueEnd = pos + len
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -238,7 +238,7 @@ func playExample(file *ast.File, f *ast.FuncDecl) *ast.File {
|
||||||
spec := *s
|
spec := *s
|
||||||
path := *s.Path
|
path := *s.Path
|
||||||
spec.Path = &path
|
spec.Path = &path
|
||||||
spec.Path.ValuePos = groupStart(&spec)
|
updateBasicLitPos(spec.Path, groupStart(&spec))
|
||||||
namedImports = append(namedImports, &spec)
|
namedImports = append(namedImports, &spec)
|
||||||
delete(unresolved, n)
|
delete(unresolved, n)
|
||||||
}
|
}
|
||||||
|
|
@ -720,3 +720,14 @@ func isExampleSuffix(s string) bool {
|
||||||
r, size := utf8.DecodeRuneInString(s)
|
r, size := utf8.DecodeRuneInString(s)
|
||||||
return size > 0 && unicode.IsLower(r)
|
return size > 0 && unicode.IsLower(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// updateBasicLitPos updates lit.Pos,
|
||||||
|
// ensuring that lit.End is displaced by the same amount.
|
||||||
|
// (See https://go.dev/issue/76395.)
|
||||||
|
func updateBasicLitPos(lit *ast.BasicLit, pos token.Pos) {
|
||||||
|
len := lit.End() - lit.Pos()
|
||||||
|
lit.ValuePos = pos
|
||||||
|
if lit.ValueEnd.IsValid() {
|
||||||
|
lit.ValueEnd = pos + len
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue