mirror of
https://github.com/golang/go
synced 2024-11-18 09:04:49 -07:00
internal/lsp/regtest: await IWL before running tests
This change makes these tests a little more resilient by making sure that the initial workspace load is completed before we run them. Change-Id: I24735da31cc045cb78dfb280e88136b5835351a6 Reviewed-on: https://go-review.googlesource.com/c/tools/+/241276 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com>
This commit is contained in:
parent
d5a745333d
commit
134513de88
@ -11,6 +11,7 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
"sync"
|
||||
|
||||
"golang.org/x/tools/internal/event"
|
||||
"golang.org/x/tools/internal/jsonrpc2"
|
||||
@ -190,6 +191,17 @@ func (s *Server) addFolders(ctx context.Context, folders []protocol.WorkspaceFol
|
||||
originalViews := len(s.session.Views())
|
||||
viewErrors := make(map[span.URI]error)
|
||||
|
||||
var wg sync.WaitGroup
|
||||
if s.session.Options().VerboseWorkDoneProgress {
|
||||
work := s.StartWork(ctx, DiagnosticWorkTitle(FromInitialWorkspaceLoad), "Calculating diagnostics for initial workspace load...", nil)
|
||||
defer func() {
|
||||
go func() {
|
||||
wg.Wait()
|
||||
work.End(ctx, "Done.")
|
||||
}()
|
||||
|
||||
}()
|
||||
}
|
||||
for _, folder := range folders {
|
||||
uri := span.URIFromURI(folder.URI)
|
||||
view, snapshot, err := s.addView(ctx, folder.Name, uri)
|
||||
@ -206,7 +218,11 @@ func (s *Server) addFolders(ctx context.Context, folders []protocol.WorkspaceFol
|
||||
event.Log(ctx, buf.String())
|
||||
|
||||
// Diagnose the newly created view.
|
||||
go s.diagnoseDetached(snapshot)
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
s.diagnoseDetached(snapshot)
|
||||
wg.Done()
|
||||
}()
|
||||
}
|
||||
if len(viewErrors) > 0 {
|
||||
errMsg := fmt.Sprintf("Error loading workspace folders (expected %v, got %v)\n", len(folders), len(s.session.Views())-originalViews)
|
||||
|
@ -304,15 +304,19 @@ func _() {
|
||||
x := X{}
|
||||
b.SayHello(x)
|
||||
}`
|
||||
|
||||
// Add the new method before the implementation. Expect diagnostics.
|
||||
t.Run("method before implementation", func(t *testing.T) {
|
||||
runner.Run(t, pkg, func(t *testing.T, env *Env) {
|
||||
env.Await(
|
||||
NoDiagnostics("a/a.go"),
|
||||
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromInitialWorkspaceLoad), 1),
|
||||
)
|
||||
env.WriteWorkspaceFile("b/b.go", newMethod)
|
||||
env.Await(
|
||||
DiagnosticAt("a/a.go", 12, 12),
|
||||
OnceMet(
|
||||
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromDidChangeWatchedFiles), 1),
|
||||
DiagnosticAt("a/a.go", 12, 12),
|
||||
),
|
||||
)
|
||||
env.WriteWorkspaceFile("a/a.go", implementation)
|
||||
env.Await(
|
||||
@ -324,11 +328,14 @@ func _() {
|
||||
t.Run("implementation before method", func(t *testing.T) {
|
||||
runner.Run(t, pkg, func(t *testing.T, env *Env) {
|
||||
env.Await(
|
||||
NoDiagnostics("a/a.go"),
|
||||
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromInitialWorkspaceLoad), 1),
|
||||
)
|
||||
env.WriteWorkspaceFile("a/a.go", implementation)
|
||||
env.Await(
|
||||
NoDiagnostics("a/a.go"),
|
||||
OnceMet(
|
||||
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromDidChangeWatchedFiles), 1),
|
||||
NoDiagnostics("a/a.go"),
|
||||
),
|
||||
)
|
||||
env.WriteWorkspaceFile("b/b.go", newMethod)
|
||||
env.Await(
|
||||
@ -340,15 +347,18 @@ func _() {
|
||||
t.Run("implementation and method simultaneously", func(t *testing.T) {
|
||||
runner.Run(t, pkg, func(t *testing.T, env *Env) {
|
||||
env.Await(
|
||||
NoDiagnostics("a/a.go"),
|
||||
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromInitialWorkspaceLoad), 1),
|
||||
)
|
||||
env.WriteWorkspaceFiles(map[string]string{
|
||||
"a/a.go": implementation,
|
||||
"b/b.go": newMethod,
|
||||
})
|
||||
env.Await(
|
||||
NoDiagnostics("a/a.go"),
|
||||
NoDiagnostics("a/a.go"),
|
||||
OnceMet(
|
||||
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromDidChangeWatchedFiles), 1),
|
||||
NoDiagnostics("a/a.go"),
|
||||
),
|
||||
NoDiagnostics("b/b.go"),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
@ -25,15 +25,27 @@ type ModificationSource int
|
||||
const (
|
||||
// FromDidOpen is a file modification caused by opening a file.
|
||||
FromDidOpen = ModificationSource(iota)
|
||||
|
||||
// FromDidChange is a file modification caused by changing a file.
|
||||
FromDidChange
|
||||
// FromDidChangeWatchedFiles is a file modification caused by a change to a watched file.
|
||||
|
||||
// FromDidChangeWatchedFiles is a file modification caused by a change to a
|
||||
// watched file.
|
||||
FromDidChangeWatchedFiles
|
||||
|
||||
// FromDidSave is a file modification caused by a file save.
|
||||
FromDidSave
|
||||
|
||||
// FromDidClose is a file modification caused by closing a file.
|
||||
FromDidClose
|
||||
|
||||
// FromRegenerateCgo refers to file modifications caused by regenerating
|
||||
// the cgo sources for the workspace.
|
||||
FromRegenerateCgo
|
||||
|
||||
// FromInitialWorkspaceLoad refers to the loading of all packages in the
|
||||
// workspace when the view is first created.
|
||||
FromInitialWorkspaceLoad
|
||||
)
|
||||
|
||||
func (m ModificationSource) String() string {
|
||||
@ -46,8 +58,12 @@ func (m ModificationSource) String() string {
|
||||
return "files changed on disk"
|
||||
case FromDidSave:
|
||||
return "saved files"
|
||||
case FromDidClose:
|
||||
return "close files"
|
||||
case FromRegenerateCgo:
|
||||
return "regenerate cgo"
|
||||
case FromInitialWorkspaceLoad:
|
||||
return "initial workspace load"
|
||||
default:
|
||||
return "unknown file modification"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user