From e8a26f416010571efce8faf31c938eb775565db1 Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Tue, 7 Jan 2020 14:41:40 -0500 Subject: [PATCH] internal/lsp: prevent initial workspace load from being canceled In one of the many iterations on CL 212102, the contexts propagated through the initial workspace load were allowed to be canceled. This should not be allowed because the initial workspace load has to be completed. Change-Id: I6c6273b4e58fb9041af518f329f4766ed5f1f81b Reviewed-on: https://go-review.googlesource.com/c/tools/+/213641 Run-TryBot: Rebecca Stambler TryBot-Result: Gobot Gobot Reviewed-by: Heschi Kreinick --- internal/lsp/general.go | 5 ++++- internal/lsp/workspace.go | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/lsp/general.go b/internal/lsp/general.go index bad973429b..b921590a9c 100644 --- a/internal/lsp/general.go +++ b/internal/lsp/general.go @@ -17,6 +17,7 @@ import ( "golang.org/x/tools/internal/lsp/source" "golang.org/x/tools/internal/span" "golang.org/x/tools/internal/telemetry/log" + "golang.org/x/tools/internal/xcontext" errors "golang.org/x/xerrors" ) @@ -165,11 +166,13 @@ func (s *Server) addFolders(ctx context.Context, folders []protocol.WorkspaceFol for _, folder := range folders { uri := span.NewURI(folder.URI) - _, snapshot, err := s.addView(ctx, folder.Name, span.NewURI(folder.URI)) + view, snapshot, err := s.addView(ctx, folder.Name, span.NewURI(folder.URI)) if err != nil { viewErrors[uri] = err continue } + // Make sure that this does not get canceled. + ctx := xcontext.Detach(view.BackgroundContext()) go s.diagnoseSnapshot(ctx, snapshot) } if len(viewErrors) > 0 { diff --git a/internal/lsp/workspace.go b/internal/lsp/workspace.go index 358c839605..a607d9e896 100644 --- a/internal/lsp/workspace.go +++ b/internal/lsp/workspace.go @@ -10,6 +10,7 @@ import ( "golang.org/x/tools/internal/lsp/protocol" "golang.org/x/tools/internal/lsp/source" "golang.org/x/tools/internal/span" + "golang.org/x/tools/internal/xcontext" errors "golang.org/x/xerrors" ) @@ -52,6 +53,8 @@ func (s *Server) updateConfiguration(ctx context.Context, changed interface{}) e if err != nil { return err } + // Make sure that this does not get canceled. + ctx := xcontext.Detach(view.BackgroundContext()) go s.diagnoseSnapshot(ctx, view.Snapshot()) } return nil