internal/lsp: release resources for call hierarchy file requests

* adds call to release resources for beginFileRequest in
  lsp/call_hierarchy.go
* fixes source_test

Change-Id: Id45f61ccd474a2df9f46be89fdb059cfe8584f0c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/247497
Run-TryBot: Danish Dua <danishdua@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
diff --git a/internal/lsp/call_hierarchy.go b/internal/lsp/call_hierarchy.go
index f9307d7..43c4ea8 100644
--- a/internal/lsp/call_hierarchy.go
+++ b/internal/lsp/call_hierarchy.go
@@ -12,7 +12,8 @@
 )
 
 func (s *Server) prepareCallHierarchy(ctx context.Context, params *protocol.CallHierarchyPrepareParams) ([]protocol.CallHierarchyItem, error) {
-	snapshot, fh, ok, err := s.beginFileRequest(ctx, params.TextDocument.URI, source.Go)
+	snapshot, fh, ok, release, err := s.beginFileRequest(ctx, params.TextDocument.URI, source.Go)
+	defer release()
 	if !ok {
 		return nil, err
 	}
@@ -21,7 +22,8 @@
 }
 
 func (s *Server) incomingCalls(ctx context.Context, params *protocol.CallHierarchyIncomingCallsParams) ([]protocol.CallHierarchyIncomingCall, error) {
-	snapshot, fh, ok, err := s.beginFileRequest(ctx, params.Item.URI, source.Go)
+	snapshot, fh, ok, release, err := s.beginFileRequest(ctx, params.Item.URI, source.Go)
+	defer release()
 	if !ok {
 		return nil, err
 	}
@@ -30,7 +32,8 @@
 }
 
 func (s *Server) outgoingCalls(ctx context.Context, params *protocol.CallHierarchyOutgoingCallsParams) ([]protocol.CallHierarchyOutgoingCall, error) {
-	snapshot, fh, ok, err := s.beginFileRequest(ctx, params.Item.URI, source.Go)
+	snapshot, fh, ok, release, err := s.beginFileRequest(ctx, params.Item.URI, source.Go)
+	defer release()
 	if !ok {
 		return nil, err
 	}
diff --git a/internal/lsp/source/source_test.go b/internal/lsp/source/source_test.go
index c8e4d99..76fce9b 100644
--- a/internal/lsp/source/source_test.go
+++ b/internal/lsp/source/source_test.go
@@ -105,12 +105,12 @@
 	if err != nil {
 		t.Fatalf("failed for %v: %v", spn, err)
 	}
-	fh, err := r.view.Snapshot().GetFile(r.ctx, spn.URI())
+	fh, err := r.snapshot.GetFile(r.ctx, spn.URI())
 	if err != nil {
 		t.Fatal(err)
 	}
 
-	items, err := source.PrepareCallHierarchy(r.ctx, r.view.Snapshot(), fh, loc.Range.Start)
+	items, err := source.PrepareCallHierarchy(r.ctx, r.snapshot, fh, loc.Range.Start)
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -127,11 +127,11 @@
 	}
 
 	// TODO: add span comparison tests for expectedCalls once call hierarchy is implemented
-	incomingCalls, err := source.IncomingCalls(r.ctx, r.view.Snapshot(), fh, loc.Range.Start)
+	incomingCalls, err := source.IncomingCalls(r.ctx, r.snapshot, fh, loc.Range.Start)
 	if len(incomingCalls) != 0 {
 		t.Errorf("expected no incoming calls but got %d", len(incomingCalls))
 	}
-	outgoingCalls, err := source.OutgoingCalls(r.ctx, r.view.Snapshot(), fh, loc.Range.Start)
+	outgoingCalls, err := source.OutgoingCalls(r.ctx, r.snapshot, fh, loc.Range.Start)
 	if len(outgoingCalls) != 0 {
 		t.Errorf("expected no outgoing calls but got %d", len(outgoingCalls))
 	}