gopls/internal/span: some cleanups

This change eliminates these redundant helper functions
- cache.rangeFromPositions
- source.LineToRange
- source.ByteOffsetsToRange
and makes various other simplifications and documentation
improvements.

Change-Id: Ic820ab560d71b88bde00b005e3a919334a5d1856
Reviewed-on: https://go-review.googlesource.com/c/tools/+/442015
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
diff --git a/gopls/internal/lsp/cache/mod_tidy.go b/gopls/internal/lsp/cache/mod_tidy.go
index 63346dc..8e4e060 100644
--- a/gopls/internal/lsp/cache/mod_tidy.go
+++ b/gopls/internal/lsp/cache/mod_tidy.go
@@ -287,7 +287,7 @@
 
 // unusedDiagnostic returns a source.Diagnostic for an unused require.
 func unusedDiagnostic(m *protocol.ColumnMapper, req *modfile.Require, onlyDiagnostic bool) (*source.Diagnostic, error) {
-	rng, err := rangeFromPositions(m, req.Syntax.Start, req.Syntax.End)
+	rng, err := m.OffsetRange(req.Syntax.Start.Byte, req.Syntax.End.Byte)
 	if err != nil {
 		return nil, err
 	}
@@ -313,7 +313,7 @@
 // directnessDiagnostic extracts errors when a dependency is labeled indirect when
 // it should be direct and vice versa.
 func directnessDiagnostic(m *protocol.ColumnMapper, req *modfile.Require, computeEdits source.DiffFunction) (*source.Diagnostic, error) {
-	rng, err := rangeFromPositions(m, req.Syntax.Start, req.Syntax.End)
+	rng, err := m.OffsetRange(req.Syntax.Start.Byte, req.Syntax.End.Byte)
 	if err != nil {
 		return nil, err
 	}
@@ -325,8 +325,8 @@
 		if comments := req.Syntax.Comment(); comments != nil && len(comments.Suffix) > 0 {
 			end := comments.Suffix[0].Start
 			end.LineRune += len(comments.Suffix[0].Token)
-			end.Byte += len([]byte(comments.Suffix[0].Token))
-			rng, err = rangeFromPositions(m, comments.Suffix[0].Start, end)
+			end.Byte += len(comments.Suffix[0].Token)
+			rng, err = m.OffsetRange(comments.Suffix[0].Start.Byte, end.Byte)
 			if err != nil {
 				return nil, err
 			}
@@ -359,7 +359,7 @@
 	if pm.File != nil && pm.File.Module != nil && pm.File.Module.Syntax != nil {
 		start, end := pm.File.Module.Syntax.Span()
 		var err error
-		rng, err = rangeFromPositions(pm.Mapper, start, end)
+		rng, err = pm.Mapper.OffsetRange(start.Byte, end.Byte)
 		if err != nil {
 			return nil, err
 		}
@@ -429,11 +429,7 @@
 	if req.Syntax == nil {
 		return nil, fmt.Errorf("no syntax for %v", req)
 	}
-	spn, err := span.NewRange(file, imp.Path.Pos(), imp.Path.End()).Span()
-	if err != nil {
-		return nil, err
-	}
-	rng, err := m.Range(spn)
+	rng, err := m.PosRange(imp.Path.Pos(), imp.Path.End())
 	if err != nil {
 		return nil, err
 	}
@@ -447,14 +443,6 @@
 	}, nil
 }
 
-func rangeFromPositions(m *protocol.ColumnMapper, s, e modfile.Position) (protocol.Range, error) {
-	spn, err := spanFromPositions(m, s, e)
-	if err != nil {
-		return protocol.Range{}, err
-	}
-	return m.Range(spn)
-}
-
 func spanFromPositions(m *protocol.ColumnMapper, s, e modfile.Position) (span.Span, error) {
 	toPoint := func(offset int) (span.Point, error) {
 		l, c, err := span.ToPosition(m.TokFile, offset)