internal/span: handle escaping file URIs

I wasn't sure if we should just manually construct the URI here or use
the URL unescaping function. Let me know which you think is best.

Updates golang/go#34270

Change-Id: Idb48fc2650d39f3e54cac141a70f356c31e303ad
Reviewed-on: https://go-review.googlesource.com/c/tools/+/195618
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
diff --git a/internal/lsp/source/util.go b/internal/lsp/source/util.go
index 7feba2f..1941598 100644
--- a/internal/lsp/source/util.go
+++ b/internal/lsp/source/util.go
@@ -86,7 +86,7 @@
 	if err != nil {
 		return nil, nil, nil, err
 	}
-	file, m, err := pkgToMapper(ctx, view, pkg, uri)
+	file, m, err := pkgToMapper(ctx, view, pkg, f.URI())
 	if err != nil {
 		return nil, nil, nil, err
 	}
@@ -109,7 +109,7 @@
 	if err != nil {
 		return nil, nil, err
 	}
-	file, m, err := pkgToMapper(ctx, view, pkg, uri)
+	file, m, err := pkgToMapper(ctx, view, pkg, f.URI())
 	if err != nil {
 		return nil, nil, err
 	}
diff --git a/internal/span/uri.go b/internal/span/uri.go
index 9dfbdaa..e05a9e6 100644
--- a/internal/span/uri.go
+++ b/internal/span/uri.go
@@ -124,7 +124,11 @@
 		Scheme: fileScheme,
 		Path:   path,
 	}
-	return URI(u.String())
+	uri := u.String()
+	if unescaped, err := url.PathUnescape(uri); err == nil {
+		uri = unescaped
+	}
+	return URI(uri)
 }
 
 // isWindowsDrivePath returns true if the file path is of the form used by
diff --git a/internal/span/uri_test.go b/internal/span/uri_test.go
index 36dd199..907b47b 100644
--- a/internal/span/uri_test.go
+++ b/internal/span/uri_test.go
@@ -23,6 +23,7 @@
 		`c:/Go/src/bob.go`,
 		`/path/to/dir`,
 		`/a/b/c/src/bob.go`,
+		`c:/Go/src/bob george/george/george.go`,
 	} {
 		testPath := filepath.FromSlash(test)
 		expectPath := testPath