diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/go/token/position.go | 9 | ||||
| -rw-r--r-- | src/go/token/position_test.go | 3 |
2 files changed, 12 insertions, 0 deletions
diff --git a/src/go/token/position.go b/src/go/token/position.go index cbc2ddb5eb..4d129d938f 100644 --- a/src/go/token/position.go +++ b/src/go/token/position.go @@ -159,6 +159,15 @@ func (f *File) MergeLine(line int) { f.lines = f.lines[:len(f.lines)-1] } +// Lines returns the effective line offset table of the form described by SetLines. +// Callers must not mutate the result. +func (f *File) Lines() []int { + f.mutex.Lock() + lines := f.lines + f.mutex.Unlock() + return lines +} + // SetLines sets the line offsets for a file and reports whether it succeeded. // The line offsets are the offsets of the first character of each line; // for instance for the content "ab\nc\n" the line offsets are {0, 3}. diff --git a/src/go/token/position_test.go b/src/go/token/position_test.go index 65cb242808..19774a97ba 100644 --- a/src/go/token/position_test.go +++ b/src/go/token/position_test.go @@ -130,6 +130,9 @@ func TestPositions(t *testing.T) { if f.LineCount() != len(test.lines) { t.Errorf("%s, SetLines: got line count %d; want %d", f.Name(), f.LineCount(), len(test.lines)) } + if !reflect.DeepEqual(f.Lines(), test.lines) { + t.Errorf("%s, Lines after SetLines(v): got %v; want %v", f.Name(), f.Lines(), test.lines) + } verifyPositions(t, fset, f, test.lines) // add lines with SetLinesForContent and verify all positions |
