Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/gopls: declarations are not picked from new files #33729

Open
anjmao opened this issue Aug 20, 2019 · 4 comments

Comments

@anjmao
Copy link

commented Aug 20, 2019

What version of Go are you using (go version)?

go version go1.12.6 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/anjmao/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/anjmao/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/anjmao/s/hello/go.mod"
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/jc/q8b4yjwd5dvgc42xpg6yvm8c0000gn/T/go-build972815364=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

  1. In VSCode create main.go

main.go

package main

func main() {

}
  1. Add another file foo.go. It is important that you type it instead of copying. In most cases if I just copy and save it works.

foo.go

package main

func foo() {}
  1. Now try to use foo function inside main.

main.go

package main

func main() {
    foo()
}

What did you expect to see?

I expect to get completion for foo inside main.go

What did you see instead?

I do not get completion, instead I get error undeclared name: foo

Gopls starts to recognise foo only If a do more edits inside foo.go. Also If I delete foo.go in main.go I see no errors.

@gopherbot gopherbot added this to the Unreleased milestone Aug 20, 2019

@gopherbot gopherbot added the gopls label Aug 20, 2019

@gopherbot

This comment has been minimized.

Copy link

commented Aug 20, 2019

Thank you for filing a gopls issue! Please take a look at the Troubleshooting section of the gopls Wiki page, and make sure that you have provided all of the relevant information here.

@stamblerre stamblerre changed the title x/tools/gopls: Declarations are not picked from new files x/tools/gopls: declarations are not picked from new files Aug 20, 2019

@stamblerre

This comment has been minimized.

Copy link
Contributor

commented Aug 20, 2019

Thanks for filing this issue! I'm able to reproduce it.

I think we will need to re-run packages.Load if we detect a new file has been created, though I'm not sure how we will handle that considering we only see this as a textDocument/didOpen call. I'll investigate this further.

@anjmao

This comment has been minimized.

Copy link
Author

commented Aug 21, 2019

@stamblerre I saw in lsp spec there is workspace/didChangeWatchedFiles event which also contains file change type

interface DidChangeWatchedFilesParams {
	/**
	 * The actual file events.
	 */
	changes: FileEvent[];
}

interface FileEvent {
	/**
	 * The file's URI.
	 */
	uri: DocumentUri;
	/**
	 * The change type.
	 */
	type: number;
}

export namespace FileChangeType {
	/**
	 * The file got created.
	 */
	export const Created = 1;
	/**
	 * The file got changed.
	 */
	export const Changed = 2;
	/**
	 * The file got deleted.
	 */
	export const Deleted = 3;
}

This make sense as you can remove or add whole folder with bunch of files.

@anjmao

This comment has been minimized.

Copy link
Author

commented Aug 29, 2019

@stamblerre Hi, could you also add this to v1.0 milestone? Thanks.

@stamblerre stamblerre modified the milestones: Unreleased, gopls v1.0 Aug 29, 2019

@gopherbot gopherbot added the Tools label Sep 12, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.