From 92211316783d93a277f25bf07980c27d58128e5e Mon Sep 17 00:00:00 2001 From: Danish Dua Date: Fri, 7 Aug 2020 16:48:53 -0400 Subject: [PATCH] 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 Reviewed-by: Heschi Kreinick TryBot-Result: Gobot Gobot --- internal/lsp/call_hierarchy.go | 9 ++++++--- internal/lsp/source/source_test.go | 8 ++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/internal/lsp/call_hierarchy.go b/internal/lsp/call_hierarchy.go index f9307d7016..43c4ea8d5b 100644 --- a/internal/lsp/call_hierarchy.go +++ b/internal/lsp/call_hierarchy.go @@ -12,7 +12,8 @@ import ( ) 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) prepareCallHierarchy(ctx context.Context, params *protocol.Call } 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) incomingCalls(ctx context.Context, params *protocol.CallHierarc } 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 c8e4d99c18..76fce9bb31 100644 --- a/internal/lsp/source/source_test.go +++ b/internal/lsp/source/source_test.go @@ -105,12 +105,12 @@ func (r *runner) CallHierarchy(t *testing.T, spn span.Span, expectedCalls *tests 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 @@ func (r *runner) CallHierarchy(t *testing.T, spn span.Span, expectedCalls *tests } // 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)) }