Debian Codegraph @

gopls/internal/test/integration/misc/shared_test.go

raw symbols SCIP
1 // Copyright 2020 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package misc
6
7 import (
8 "testing"
9
10 . "golang.org/x/tools/gopls/internal/test/integration"
11 )
12
13 // Smoke test that simultaneous editing sessions in the same workspace works.
14 func TestSimultaneousEdits(t *testing.T) {
15 const sharedProgram = `
16 -- go.mod --
17 module mod
18
19 go 1.12
20 -- main.go --
21 package main
22
23 import "fmt"
24
25 func main() {
26 fmt.Println("Hello World.")
27 }`
28
29 WithOptions(
30 Modes(DefaultModes()&(Forwarded|SeparateProcess)),
31 ).Run(t, sharedProgram, func(t *testing.T, env1 *Env) {
32 // Create a second test session connected to the same workspace and server
33 // as the first.
34 env2 := ConnectGoplsEnv(t, env1.Ctx, env1.Sandbox, env1.Editor.Config(), env1.Server)
35 env2.Await(InitialWorkspaceLoad)
36 // In editor #1, break fmt.Println as before.
37 env1.OpenFile("main.go")
38 env1.RegexpReplace("main.go", "Printl(n)", "")
39 // In editor #2 remove the closing brace.
40 env2.OpenFile("main.go")
41 env2.RegexpReplace("main.go", "\\)\n(})", "")
42
43 // Now check that we got different diagnostics in each environment.
44 env1.AfterChange(Diagnostics(env1.AtRegexp("main.go", "Printl")))
45 env2.AfterChange(Diagnostics(env2.AtRegexp("main.go", "$")))
46
47 // Now close editor #2, and verify that operation in editor #1 is
48 // unaffected.
49 if err := env2.Editor.Close(env2.Ctx); err != nil {
50 t.Errorf("closing second editor: %v", err)
51 }
52
53 env1.RegexpReplace("main.go", "Printl", "Println")
54 env1.AfterChange(
55 NoDiagnostics(ForFile("main.go")),
56 )
57 })
58 }