1
0
mirror of https://github.com/golang/go synced 2024-11-05 14:56:10 -07:00

internal/lsp: add initial workspace load notification

Add workspace package load (IWL) notification.

Closes golang/go#40632

Change-Id: I4d4c6fba1ece08bb0d6df52da2e6f08c959fd1ae
Reviewed-on: https://go-review.googlesource.com/c/tools/+/248623
Run-TryBot: Danish Dua <danishdua@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
This commit is contained in:
Danish Dua 2020-08-12 12:05:41 -04:00
parent c4923e618c
commit 9882f1d182
4 changed files with 16 additions and 5 deletions

View File

@ -488,7 +488,7 @@ func (s *snapshot) KnownPackages(ctx context.Context) ([]source.Package, error)
func (s *snapshot) CachedImportPaths(ctx context.Context) (map[string]source.Package, error) { func (s *snapshot) CachedImportPaths(ctx context.Context) (map[string]source.Package, error) {
// Don't reload workspace package metadata. // Don't reload workspace package metadata.
// This function is meant to only return currently cached information. // This function is meant to only return currently cached information.
s.view.awaitInitialized(ctx) s.view.AwaitInitialized(ctx)
s.mu.Lock() s.mu.Lock()
defer s.mu.Unlock() defer s.mu.Unlock()
@ -667,7 +667,7 @@ func (s *snapshot) IsSaved(uri span.URI) bool {
func (s *snapshot) awaitLoaded(ctx context.Context) error { func (s *snapshot) awaitLoaded(ctx context.Context) error {
// Do not return results until the snapshot's view has been initialized. // Do not return results until the snapshot's view has been initialized.
s.view.awaitInitialized(ctx) s.view.AwaitInitialized(ctx)
if err := s.reloadWorkspace(ctx); err != nil { if err := s.reloadWorkspace(ctx); err != nil {
return err return err
@ -1161,7 +1161,7 @@ func (s *snapshot) findWorkspaceDirectories(ctx context.Context, modFH source.Fi
} }
func (s *snapshot) BuiltinPackage(ctx context.Context) (*source.BuiltinPackage, error) { func (s *snapshot) BuiltinPackage(ctx context.Context) (*source.BuiltinPackage, error) {
s.view.awaitInitialized(ctx) s.view.AwaitInitialized(ctx)
if s.builtin == nil { if s.builtin == nil {
return nil, errors.Errorf("no builtin package for view %s", s.view.name) return nil, errors.Errorf("no builtin package for view %s", s.view.name)

View File

@ -654,7 +654,8 @@ func (v *View) initialize(ctx context.Context, s *snapshot, firstAttempt bool) {
}) })
} }
func (v *View) awaitInitialized(ctx context.Context) { // AwaitInitialized waits until a view is initialized
func (v *View) AwaitInitialized(ctx context.Context) {
select { select {
case <-ctx.Done(): case <-ctx.Done():
return return
@ -677,7 +678,7 @@ func (v *View) invalidateContent(ctx context.Context, uris map[span.URI]source.V
v.cancelBackground() v.cancelBackground()
// Do not clone a snapshot until its view has finished initializing. // Do not clone a snapshot until its view has finished initializing.
v.awaitInitialized(ctx) v.AwaitInitialized(ctx)
// This should be the only time we hold the view's snapshot lock for any period of time. // This should be the only time we hold the view's snapshot lock for any period of time.
v.snapshotMu.Lock() v.snapshotMu.Lock()

View File

@ -197,11 +197,18 @@ func (s *Server) addFolders(ctx context.Context, folders []protocol.WorkspaceFol
dirsToWatch := map[span.URI]struct{}{} dirsToWatch := map[span.URI]struct{}{}
for _, folder := range folders { for _, folder := range folders {
uri := span.URIFromURI(folder.URI) uri := span.URIFromURI(folder.URI)
work := s.progress.start(ctx, "Setting up workspace", "Loading packages...", nil, nil)
view, snapshot, release, err := s.addView(ctx, folder.Name, uri) view, snapshot, release, err := s.addView(ctx, folder.Name, uri)
if err != nil { if err != nil {
viewErrors[uri] = err viewErrors[uri] = err
work.end(ctx, fmt.Sprintf("Error loading packages: %s", err))
continue continue
} }
go func() {
view.AwaitInitialized(ctx)
work.end(ctx, "Finished loading packages.")
}()
for _, dir := range snapshot.WorkspaceDirectories(ctx) { for _, dir := range snapshot.WorkspaceDirectories(ctx) {
dirsToWatch[dir] = struct{}{} dirsToWatch[dir] = struct{}{}
} }

View File

@ -141,6 +141,9 @@ type View interface {
// Shutdown closes this view, and detaches it from its session. // Shutdown closes this view, and detaches it from its session.
Shutdown(ctx context.Context) Shutdown(ctx context.Context)
// AwaitInitialized waits until a view is initialized
AwaitInitialized(ctx context.Context)
// WriteEnv writes the view-specific environment to the io.Writer. // WriteEnv writes the view-specific environment to the io.Writer.
WriteEnv(ctx context.Context, w io.Writer) error WriteEnv(ctx context.Context, w io.Writer) error