Repository: go
Issue: x/tools/gopls: add a regression test for adding a new function to a replace target
Labels: Testing,gopls,Tools,gopls/workspace

<!--
Please answer these questions before submitting your issue. Thanks!
For questions please use one of our forums: https://github.com/golang/go/wiki/Questions
-->

### What version of Go are you using (`go version`)?

<pre>
$ go version
go version go1.14.7 darwin/amd64
</pre>

<pre>
# gopls version
golang.org/x/tools/gopls 0.4.4
    golang.org/x/tools/gopls@v0.4.4 h1:8djGYsaZ0ByP0vaXg4T+mnyfDcHpWKSZ+tpQSGv9ahk=
</pre>

VS Code version v1.47.3
vscode-go v0.16.1

### Does this issue reproduce with the latest release?
Yes


### What operating system and processor architecture are you using (`go env`)?

<details><summary><code>go env</code> Output</summary><br><pre>
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/segev/Library/Caches/go-build"
GOENV="/Users/segev/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/segev/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.14.7/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.14.7/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/b_/c6yh0ksn63d1yy192x2p9f4c0000gn/T/go-build425202633=/tmp/go-build -gno-record-gcc-switches -fno-common"
</pre></details>

### What did you do?

<!--
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
-->
1. Create two new packages using Go modules:
   ```sh
   mkdir foo && cd foo
   go mod init github.com/segevfiner/foo
   cd ..
   mkdir bar && cd bar
   go mod init github.com/segevfiner/bar
   cd ..
   ```
2. Open VS Code with vscode-go installed and gopls enabled: `code foo bar`
3. Add `replace github.com/segevfiner/bar => ../bar` to module `foo`'s go.mod.
4. Add to module `foo` as `main.go`:
    ```go
    package main

    func main() {

    }
    ```
5. Add to module `bar` as `bar1.go`:
    ```go
    package bar
  
    func Bar1() {

    }
    ```
6. Try to add `foo.Bar1()` to `foo`'s `main.go`, it would work and also auto complete it. (Might need to manually add the import statement)
7. Add to module `bar` as `bar2.go`:
    ```go
    package bar

    func Bar2() {

    }
    ```
8. Try to add `foo.Bar2()` to `foo`'s `main.go`, it would not autocomplete and will fail to compile until you restart the language server.

### What did you expect to see?
Adding new files to replaced packages should work seamlessly, auto-completing, compiling correctly, without requiring a restart of the language server.


### What did you see instead?
It fails to auto-complete, compile etc. (While working correctly with `go build`) until you restart the language server.