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: organizeImports does not find package after changing its name #67973

Open
stapelberg opened this issue Jun 13, 2024 · 3 comments
Labels
gopls/imports gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@stapelberg
Copy link
Contributor

gopls version

% gopls -v version
Build info
----------
golang.org/x/tools/gopls v0.15.3
    golang.org/x/tools/[email protected] h1:zbdOidFrPTc8Bx0YrN5QKgJ0zCjyGi0L27sKQ/bDG5o=
    github.com/BurntSushi/[email protected] h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
    github.com/google/[email protected] h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
    golang.org/x/exp/[email protected] h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y=
    golang.org/x/[email protected] h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8=
    golang.org/x/[email protected] h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
    golang.org/x/[email protected] h1:vcVnuftN4J4UKLRcgetjzfU9FjjgXUUYUc3JhFplgV4=
    golang.org/x/[email protected] h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
    golang.org/x/[email protected] h1:uH9jJYgeLCvblH0S+03kFO0qUDxRkbLRLFiKVVDl7ak=
    golang.org/x/[email protected] h1:KUas02EjQK5LTuIx1OylBQdKKZ9jeugs+HiqO5HormU=
    honnef.co/go/[email protected] h1:oFEHCKeID7to/3autwsWfnuv69j3NsfcXbvJKuIcep8=
    mvdan.cc/[email protected] h1:G3QvahNDmpD+Aek/bNOLrFR2XC6ZAdo62dZu65gmwGo=
    mvdan.cc/xurls/[email protected] h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8=
go: go1.22.3

go env

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/stapelberg/.cache/go-build'
GOENV='/home/stapelberg/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/stapelberg/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/stapelberg/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/go-1.22'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/lib/go-1.22/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.3'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build4255810886=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I created a tiny Go project with the following 3 files:

go.mod:

module hello

go 1.22

hello1.go:

package main

import (
	"fmt"
)

func main() {
	fmt.Println("hey, what’s up?")
}

internal/foo/foo.go:

package bar                  
 
func Bar() {}
func Baz() {}

Note how internal/foo/foo.go contains “package bar”, which I’ll later correct.

What did you see happen?

I opened Emacs on hello1.go, then:

  1. Added foo.Bar() to func main(), save the file to trigger organizeImports
    • This has no visible effect, but is a necessary step to reproduce the bug.
  2. Opened internal/foo/foo.go as well
  3. Changed “package bar” to “package foo”
  4. Switched to the hello1.go buffer
  5. Save hello1.go again to trigger organizeImports
  6. The expected internal/foo/foo import is not added.

What did you expect to see?

I would have expected gopls to add the internal/foo/foo import.

Restarting gopls using M-x eglot helps — afterwards the organizeImports action succeeds.

Editor and settings

Emacs 29 with go-ts-mode and eglot

Logs

[internal] Thu Jun 13 14:21:58 2024:
(:message "Running language server: gopls")
[client-request] (id:1) Thu Jun 13 14:21:58 2024:
(:jsonrpc "2.0" :id 1 :method "initialize" :params
	  (:processId 87532 :rootPath "/home/stapelberg/repro-emacs/hello1/" :rootUri "file:///home/stapelberg/repro-emacs/hello1" :initializationOptions #s(hash-table size 1 test eql rehash-size 1.5 rehash-threshold 0.8125 data
																					())
		      :capabilities
		      (:workspace
		       (:applyEdit t :executeCommand
				   (:dynamicRegistration :json-false)
				   :workspaceEdit
				   (:documentChanges t)
				   :didChangeWatchedFiles
				   (:dynamicRegistration t)
				   :symbol
				   (:dynamicRegistration :json-false)
				   :configuration t :workspaceFolders t)
		       :textDocument
		       (:synchronization
			(:dynamicRegistration :json-false :willSave t :willSaveWaitUntil t :didSave t)
			:completion
			(:dynamicRegistration :json-false :completionItem
					      (:snippetSupport :json-false :deprecatedSupport t :resolveSupport
							       (:properties
								["documentation" "details" "additionalTextEdits"])
							       :tagSupport
							       (:valueSet
								[1]))
					      :contextSupport t)
			:hover
			(:dynamicRegistration :json-false :contentFormat
					      ["plaintext"])
			:signatureHelp
			(:dynamicRegistration :json-false :signatureInformation
					      (:parameterInformation
					       (:labelOffsetSupport t)
					       :activeParameterSupport t))
			:references
			(:dynamicRegistration :json-false)
			:definition
			(:dynamicRegistration :json-false :linkSupport t)
			:declaration
			(:dynamicRegistration :json-false :linkSupport t)
			:implementation
			(:dynamicRegistration :json-false :linkSupport t)
			:typeDefinition
			(:dynamicRegistration :json-false :linkSupport t)
			:documentSymbol
			(:dynamicRegistration :json-false :hierarchicalDocumentSymbolSupport t :symbolKind
					      (:valueSet
					       [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26]))
			:documentHighlight
			(:dynamicRegistration :json-false)
			:codeAction
			(:dynamicRegistration :json-false :codeActionLiteralSupport
					      (:codeActionKind
					       (:valueSet
						["quickfix" "refactor" "refactor.extract" "refactor.inline" "refactor.rewrite" "source" "source.organizeImports"]))
					      :isPreferredSupport t)
			:formatting
			(:dynamicRegistration :json-false)
			:rangeFormatting
			(:dynamicRegistration :json-false)
			:rename
			(:dynamicRegistration :json-false)
			:inlayHint
			(:dynamicRegistration :json-false)
			:publishDiagnostics
			(:relatedInformation :json-false :codeDescriptionSupport :json-false :tagSupport
					     (:valueSet
					      [1 2])))
		       :window
		       (:workDoneProgress t)
		       :general
		       (:positionEncodings
			["utf-32" "utf-8" "utf-16"])
		       :experimental #s(hash-table size 1 test eql rehash-size 1.5 rehash-threshold 0.8125 data
						   ()))
		      :workspaceFolders
		      [(:uri "file:///home/stapelberg/repro-emacs/hello1" :name "~/repro-emacs/hello1/")]))
[server-reply] (id:1) Thu Jun 13 14:21:58 2024:
(:jsonrpc "2.0" :result
	  (:capabilities
	   (:textDocumentSync
	    (:openClose t :change 2 :save nil)
	    :completionProvider
	    (:triggerCharacters
	     ["."])
	    :hoverProvider t :signatureHelpProvider
	    (:triggerCharacters
	     ["(" ","])
	    :definitionProvider t :typeDefinitionProvider t :implementationProvider t :referencesProvider t :documentHighlightProvider t :documentSymbolProvider t :codeActionProvider
	    (:codeActionKinds
	     ["quickfix" "refactor.extract" "refactor.inline" "refactor.rewrite" "source.fixAll" "source.organizeImports"]
	     :resolveProvider t)
	    :codeLensProvider nil :documentLinkProvider nil :workspaceSymbolProvider t :documentFormattingProvider t :renameProvider t :foldingRangeProvider t :selectionRangeProvider t :executeCommandProvider
	    (:commands
	     ["gopls.add_dependency" "gopls.add_import" "gopls.add_telemetry_counters" "gopls.apply_fix" "gopls.change_signature" "gopls.check_upgrades" "gopls.diagnose_files" "gopls.edit_go_directive" "gopls.fetch_vulncheck_result" "gopls.gc_details" "gopls.generate" "gopls.go_get_package" "gopls.list_imports" "gopls.list_known_packages" "gopls.maybe_prompt_for_telemetry" "gopls.mem_stats" "gopls.regenerate_cgo" "gopls.remove_dependency" "gopls.reset_go_mod_diagnostics" "gopls.run_go_work_command" "gopls.run_govulncheck" "gopls.run_tests" "gopls.start_debugging" "gopls.start_profile" "gopls.stop_profile" "gopls.test" "gopls.tidy" "gopls.toggle_gc_details" "gopls.update_go_sum" "gopls.upgrade_dependency" "gopls.vendor" "gopls.views" "gopls.workspace_stats"])
	    :callHierarchyProvider t :semanticTokensProvider
	    (:legend
	     (:tokenTypes
	      []
	      :tokenModifiers
	      [])
	     :range t :full t)
	    :inlayHintProvider nil :workspace
	    (:workspaceFolders
	     (:supported t :changeNotifications "workspace/didChangeWorkspaceFolders")))
	   :serverInfo
	   (:name "gopls" :version "{\"GoVersion\":\"go1.22.3\",\"Path\":\"golang.org/x/tools/gopls\",\"Main\":{\"Path\":\"golang.org/x/tools/gopls\",\"Version\":\"v0.15.3\",\"Sum\":\"h1:zbdOidFrPTc8Bx0YrN5QKgJ0zCjyGi0L27sKQ/bDG5o=\",\"Replace\":null},\"Deps\":[{\"Path\":\"github.com/BurntSushi/toml\",\"Version\":\"v1.2.1\",\"Sum\":\"h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=\",\"Replace\":null},{\"Path\":\"github.com/google/go-cmp\",\"Version\":\"v0.6.0\",\"Sum\":\"h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=\",\"Replace\":null},{\"Path\":\"golang.org/x/exp/typeparams\",\"Version\":\"v0.0.0-20221212164502-fae10dda9338\",\"Sum\":\"h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y=\",\"Replace\":null},{\"Path\":\"golang.org/x/mod\",\"Version\":\"v0.15.0\",\"Sum\":\"h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8=\",\"Replace\":null},{\"Path\":\"golang.org/x/sync\",\"Version\":\"v0.6.0\",\"Sum\":\"h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=\",\"Replace\":null},{\"Path\":\"golang.org/x/telemetry\",\"Version\":\"v0.0.0-20240209200032-7b892fcb8a78\",\"Sum\":\"h1:vcVnuftN4J4UKLRcgetjzfU9FjjgXUUYUc3JhFplgV4=\",\"Replace\":null},{\"Path\":\"golang.org/x/text\",\"Version\":\"v0.14.0\",\"Sum\":\"h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=\",\"Replace\":null},{\"Path\":\"golang.org/x/tools\",\"Version\":\"v0.18.1-0.20240412183611-d92ae0781217\",\"Sum\":\"h1:uH9jJYgeLCvblH0S+03kFO0qUDxRkbLRLFiKVVDl7ak=\",\"Replace\":null},{\"Path\":\"golang.org/x/vuln\",\"Version\":\"v1.0.1\",\"Sum\":\"h1:KUas02EjQK5LTuIx1OylBQdKKZ9jeugs+HiqO5HormU=\",\"Replace\":null},{\"Path\":\"honnef.co/go/tools\",\"Version\":\"v0.4.6\",\"Sum\":\"h1:oFEHCKeID7to/3autwsWfnuv69j3NsfcXbvJKuIcep8=\",\"Replace\":null},{\"Path\":\"mvdan.cc/gofumpt\",\"Version\":\"v0.6.0\",\"Sum\":\"h1:G3QvahNDmpD+Aek/bNOLrFR2XC6ZAdo62dZu65gmwGo=\",\"Replace\":null},{\"Path\":\"mvdan.cc/xurls/v2\",\"Version\":\"v2.5.0\",\"Sum\":\"h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8=\",\"Replace\":null}],\"Settings\":[{\"Key\":\"-buildmode\",\"Value\":\"exe\"},{\"Key\":\"-compiler\",\"Value\":\"gc\"},{\"Key\":\"DefaultGODEBUG\",\"Value\":\"httplaxcontentlength=1,httpmuxgo121=1,panicnil=1,tls10server=1,tlsrsakex=1,tlsunsafeekm=1\"},{\"Key\":\"CGO_ENABLED\",\"Value\":\"1\"},{\"Key\":\"CGO_CFLAGS\",\"Value\":\"\"},{\"Key\":\"CGO_CPPFLAGS\",\"Value\":\"\"},{\"Key\":\"CGO_CXXFLAGS\",\"Value\":\"\"},{\"Key\":\"CGO_LDFLAGS\",\"Value\":\"\"},{\"Key\":\"GOARCH\",\"Value\":\"amd64\"},{\"Key\":\"GOOS\",\"Value\":\"linux\"},{\"Key\":\"GOAMD64\",\"Value\":\"v1\"}],\"Version\":\"v0.15.3\"}"))
	  :id 1)
[client-notification] Thu Jun 13 14:21:58 2024:
(:jsonrpc "2.0" :method "initialized" :params #s(hash-table size 1 test eql rehash-size 1.5 rehash-threshold 0.8125 data
							    ()))
[client-notification] Thu Jun 13 14:21:58 2024:
(:jsonrpc "2.0" :method "textDocument/didOpen" :params
	  (:textDocument
	   (:uri "file:///home/stapelberg/repro-emacs/hello1/hello1.go" :version 0 :languageId "go-ts" :text "package main\n\nimport (\n	\"fmt\"\n)\n\nfunc main() {\n	fmt.Println(\"hey, what’s up?\")\n	foo.Bar()\n}\n")))
[client-notification] Thu Jun 13 14:21:58 2024:
(:jsonrpc "2.0" :method "textDocument/didOpen" :params
	  (:textDocument
	   (:uri "file:///home/stapelberg/repro-emacs/hello1/internal/foo/foo.go" :version 0 :languageId "go-ts" :text "package foo\n\nfunc Bar() {}\nfunc Baz() {}\n")))
[client-notification] Thu Jun 13 14:21:58 2024:
(:jsonrpc "2.0" :method "workspace/didChangeConfiguration" :params
	  (:settings #s(hash-table size 1 test eql rehash-size 1.5 rehash-threshold 0.8125 data
				   ())))
[client-request] (id:2) Thu Jun 13 14:21:58 2024:
(:jsonrpc "2.0" :id 2 :method "textDocument/inlayHint" :params
	  (:textDocument
	   (:uri "file:///home/stapelberg/repro-emacs/hello1/hello1.go")
	   :range
	   (:start
	    (:line 0 :character 0)
	    :end
	    (:line 10 :character 0))))
[server-request] (id:1) Thu Jun 13 14:21:58 2024:
(:jsonrpc "2.0" :method "window/workDoneProgress/create" :params
	  (:token "2507239544109948792")
	  :id 1)
[client-reply] (id:1) Thu Jun 13 14:21:58 2024:
(:jsonrpc "2.0" :id 1 :result nil)
[server-notification] Thu Jun 13 14:21:58 2024:
(:jsonrpc "2.0" :method "$/progress" :params
	  (:token "2507239544109948792" :value
		  (:kind "begin" :title "Setting up workspace" :message "Loading packages...")))
[server-request] (id:2) Thu Jun 13 14:21:58 2024:
(:jsonrpc "2.0" :method "workspace/configuration" :params
	  (:items
	   [(:scopeUri "file:///home/stapelberg/repro-emacs/hello1" :section "gopls")])
	  :id 2)
[client-reply] (id:2) Thu Jun 13 14:21:58 2024:
(:jsonrpc "2.0" :id 2 :result
	  [nil])
[server-notification] Thu Jun 13 14:21:58 2024:
(:jsonrpc "2.0" :method "window/logMessage" :params
	  (:type 3 :message "2024/06/13 14:21:58 go info for /home/stapelberg/repro-emacs/hello1\n(view type GoModView)\n(root dir /home/stapelberg/repro-emacs/hello1)\n(go version go version go1.22.3 linux/amd64)\n(build flags: [])\n(go env: {GOOS:linux GOARCH:amd64 GOCACHE:/home/stapelberg/.cache/go-build GOMODCACHE:/home/stapelberg/go/pkg/mod GOPATH:/home/stapelberg/go GOPRIVATE: GOFLAGS: GO111MODULE: GoVersion:22 GoVersionOutput:go version go1.22.3 linux/amd64\n GOWORK: GOPACKAGESDRIVER:})\n(env overlay: map[])\n\n"))
[server-notification] Thu Jun 13 14:21:58 2024:
(:jsonrpc "2.0" :method "window/logMessage" :params
	  (:type 3 :message "2024/06/13 14:21:58 go/packages.Load #1\n	snapshot=0\n	directory=file:///home/stapelberg/repro-emacs/hello1\n	query=[/home/stapelberg/repro-emacs/hello1/... builtin]\n	packages=3\n"))
[server-notification] Thu Jun 13 14:21:58 2024:
(:jsonrpc "2.0" :method "window/logMessage" :params
	  (:type 3 :message "2024/06/13 14:21:58 go/packages.Load #1: updating metadata for 47 packages\n"))
[server-notification] Thu Jun 13 14:21:58 2024:
(:jsonrpc "2.0" :method "$/progress" :params
	  (:token "2507239544109948792" :value
		  (:kind "end" :message "Finished loading packages.")))
[server-request] (id:3) Thu Jun 13 14:21:58 2024:
(:jsonrpc "2.0" :method "client/registerCapability" :params
	  (:registrations
	   [(:id "workspace/didChangeWatchedFiles-0" :method "workspace/didChangeWatchedFiles" :registerOptions
		 (:watchers
		  [(:globPattern "**/*.{mod,work}" :kind 7)
		   (:globPattern "/home/stapelberg/repro-emacs/hello1/**/*.{go,mod,sum,work}" :kind 7)]))])
	  :id 3)
[client-reply] (id:3) Thu Jun 13 14:21:58 2024:
(:jsonrpc "2.0" :id 3 :result nil)
[server-notification] Thu Jun 13 14:21:58 2024:
(:jsonrpc "2.0" :method "textDocument/publishDiagnostics" :params
	  (:uri "file:///home/stapelberg/repro-emacs/hello1/hello1.go" :diagnostics
		[(:range
		  (:start
		   (:line 8 :character 1)
		   :end
		   (:line 8 :character 4))
		  :severity 1 :code "UndeclaredName" :codeDescription
		  (:href "https://pkg.go.dev/golang.org/x/tools/internal/typesinternal#UndeclaredName")
		  :source "compiler" :message "undefined: foo")]))
[server-request] (id:4) Thu Jun 13 14:21:58 2024:
(:jsonrpc "2.0" :method "workspace/configuration" :params
	  (:items
	   [(:section "gopls")])
	  :id 4)
[client-reply] (id:4) Thu Jun 13 14:21:58 2024:
(:jsonrpc "2.0" :id 4 :result
	  [nil])
[server-request] (id:5) Thu Jun 13 14:21:58 2024:
(:jsonrpc "2.0" :method "workspace/configuration" :params
	  (:items
	   [(:scopeUri "file:///home/stapelberg/repro-emacs/hello1" :section "gopls")])
	  :id 5)
[client-reply] (id:5) Thu Jun 13 14:21:58 2024:
(:jsonrpc "2.0" :id 5 :result
	  [nil])
[server-reply] (id:2) Thu Jun 13 14:21:58 2024:
(:jsonrpc "2.0" :result nil :id 2)
[server-notification] Thu Jun 13 14:21:58 2024:
(:jsonrpc "2.0" :method "textDocument/publishDiagnostics" :params
	  (:uri "file:///home/stapelberg/repro-emacs/hello1/internal/foo/foo.go" :diagnostics
		[]))
[client-request] (id:3) Thu Jun 13 14:21:59 2024:
(:jsonrpc "2.0" :id 3 :method "textDocument/signatureHelp" :params
	  (:textDocument
	   (:uri "file:///home/stapelberg/repro-emacs/hello1/hello1.go")
	   :position
	   (:line 8 :character 10)))
[client-request] (id:4) Thu Jun 13 14:21:59 2024:
(:jsonrpc "2.0" :id 4 :method "textDocument/hover" :params
	  (:textDocument
	   (:uri "file:///home/stapelberg/repro-emacs/hello1/hello1.go")
	   :position
	   (:line 8 :character 10)))
[client-request] (id:5) Thu Jun 13 14:21:59 2024:
(:jsonrpc "2.0" :id 5 :method "textDocument/documentHighlight" :params
	  (:textDocument
	   (:uri "file:///home/stapelberg/repro-emacs/hello1/hello1.go")
	   :position
	   (:line 8 :character 10)))
[server-reply] (id:3) Thu Jun 13 14:21:59 2024:
(:jsonrpc "2.0" :result nil :id 3)
[server-notification] Thu Jun 13 14:21:59 2024:
(:jsonrpc "2.0" :method "window/logMessage" :params
	  (:type 1 :message "2024/06/13 14:21:59 no signature help: cannot find an enclosing function\n	position=8:10\n"))
[server-reply] (id:4) Thu Jun 13 14:21:59 2024:
(:jsonrpc "2.0" :result nil :id 4)
[server-reply] (id:5) Thu Jun 13 14:21:59 2024:
(:jsonrpc "2.0" :result
	  []
	  :id 5)
[server-notification] Thu Jun 13 14:21:59 2024:
(:jsonrpc "2.0" :method "textDocument/publishDiagnostics" :params
	  (:uri "file:///home/stapelberg/repro-emacs/hello1/hello1.go" :diagnostics
		[(:range
		  (:start
		   (:line 8 :character 1)
		   :end
		   (:line 8 :character 4))
		  :severity 1 :code "UndeclaredName" :codeDescription
		  (:href "https://pkg.go.dev/golang.org/x/tools/internal/typesinternal#UndeclaredName")
		  :source "compiler" :message "undefined: foo")]))
[client-notification] Thu Jun 13 14:22:00 2024:
(:jsonrpc "2.0" :method "workspace/didChangeWatchedFiles" :params
	  (:changes
	   [(:uri "file:///home/stapelberg/repro-emacs/hello1/[email protected]%3A1718262049" :type 1)]))
[client-notification] Thu Jun 13 14:22:00 2024:
(:jsonrpc "2.0" :method "textDocument/didChange" :params
	  (:textDocument
	   (:uri "file:///home/stapelberg/repro-emacs/hello1/hello1.go" :version 1)
	   :contentChanges
	   [(:range
	     (:start
	      (:line 8 :character 10)
	      :end
	      (:line 8 :character 10))
	     :rangeLength 0 :text " ")]))
[client-request] (id:6) Thu Jun 13 14:22:00 2024:
(:jsonrpc "2.0" :id 6 :method "textDocument/formatting" :params
	  (:textDocument
	   (:uri "file:///home/stapelberg/repro-emacs/hello1/hello1.go")
	   :options
	   (:tabSize 8 :insertSpaces :json-false :insertFinalNewline t :trimFinalNewlines t)))
[server-reply] (id:6) Thu Jun 13 14:22:00 2024:
(:jsonrpc "2.0" :result
	  [(:range
	    (:start
	     (:line 8 :character 10)
	     :end
	     (:line 8 :character 11))
	    :newText "")]
	  :id 6)
[client-notification] Thu Jun 13 14:22:00 2024:
(:jsonrpc "2.0" :method "textDocument/didChange" :params
	  (:textDocument
	   (:uri "file:///home/stapelberg/repro-emacs/hello1/hello1.go" :version 2)
	   :contentChanges
	   [(:range
	     (:start
	      (:line 8 :character 10)
	      :end
	      (:line 8 :character 11))
	     :rangeLength 1 :text "")]))
[client-request] (id:7) Thu Jun 13 14:22:00 2024:
(:jsonrpc "2.0" :id 7 :method "textDocument/codeAction" :params
	  (:textDocument
	   (:uri "file:///home/stapelberg/repro-emacs/hello1/hello1.go")
	   :range
	   (:start
	    (:line 8 :character 8)
	    :end
	    (:line 8 :character 10))
	   :context
	   (:diagnostics
	    []
	    :only
	    ["source.organizeImports"])))
[server-notification] Thu Jun 13 14:22:00 2024:
(:jsonrpc "2.0" :method "textDocument/publishDiagnostics" :params
	  (:uri "file:///home/stapelberg/repro-emacs/hello1/hello1.go" :version 2 :diagnostics
		[(:range
		  (:start
		   (:line 8 :character 1)
		   :end
		   (:line 8 :character 4))
		  :severity 1 :code "UndeclaredName" :codeDescription
		  (:href "https://pkg.go.dev/golang.org/x/tools/internal/typesinternal#UndeclaredName")
		  :source "compiler" :message "undefined: foo")]))
[server-reply] (id:7) Thu Jun 13 14:22:00 2024:
(:jsonrpc "2.0" :result
	  [(:title "Organize Imports" :kind "source.organizeImports" :edit
		   (:documentChanges
		    [(:textDocument
		      (:version 2 :uri "file:///home/stapelberg/repro-emacs/hello1/hello1.go")
		      :edits
		      [(:range
			(:start
			 (:line 3 :character 4)
			 :end
			 (:line 3 :character 4))
			:newText "t\"\n	\"hello/in")
		       (:range
			(:start
			 (:line 3 :character 5)
			 :end
			 (:line 3 :character 5))
			:newText "ernal/foo")])]))]
	  :id 7)
[internal] (id:8) Thu Jun 13 14:22:00 2024:
(:deferring :textDocument/signatureHelp :id 8 :params
	    (:textDocument
	     (:uri "file:///home/stapelberg/repro-emacs/hello1/hello1.go")
	     :position
	     (:line 9 :character 10)))
[internal] (id:9) Thu Jun 13 14:22:00 2024:
(:deferring :textDocument/hover :id 9 :params
	    (:textDocument
	     (:uri "file:///home/stapelberg/repro-emacs/hello1/hello1.go")
	     :position
	     (:line 9 :character 10)))
[internal] (id:10) Thu Jun 13 14:22:00 2024:
(:deferring :textDocument/documentHighlight :id 10 :params
	    (:textDocument
	     (:uri "file:///home/stapelberg/repro-emacs/hello1/hello1.go")
	     :position
	     (:line 9 :character 10)))
[client-notification] Thu Jun 13 14:22:00 2024:
(:jsonrpc "2.0" :method "textDocument/didChange" :params
	  (:textDocument
	   (:uri "file:///home/stapelberg/repro-emacs/hello1/hello1.go" :version 4)
	   :contentChanges
	   [(:range
	     (:start
	      (:line 3 :character 5)
	      :end
	      (:line 3 :character 5))
	     :rangeLength 0 :text "ernal/foo")
	    (:range
	     (:start
	      (:line 3 :character 4)
	      :end
	      (:line 3 :character 4))
	     :rangeLength 0 :text "t\"\n	\"hello/in")]))
[internal] Thu Jun 13 14:22:00 2024:
(:maybe-run-deferred
 (10 9 8))
[client-request] (id:10) Thu Jun 13 14:22:00 2024:
(:jsonrpc "2.0" :id 10 :method "textDocument/documentHighlight" :params
	  (:textDocument
	   (:uri "file:///home/stapelberg/repro-emacs/hello1/hello1.go")
	   :position
	   (:line 9 :character 10)))
[client-request] (id:9) Thu Jun 13 14:22:00 2024:
(:jsonrpc "2.0" :id 9 :method "textDocument/hover" :params
	  (:textDocument
	   (:uri "file:///home/stapelberg/repro-emacs/hello1/hello1.go")
	   :position
	   (:line 9 :character 10)))
[client-request] (id:8) Thu Jun 13 14:22:00 2024:
(:jsonrpc "2.0" :id 8 :method "textDocument/signatureHelp" :params
	  (:textDocument
	   (:uri "file:///home/stapelberg/repro-emacs/hello1/hello1.go")
	   :position
	   (:line 9 :character 10)))
[client-notification] Thu Jun 13 14:22:00 2024:
(:jsonrpc "2.0" :method "textDocument/didSave" :params
	  (:text "package main\n\nimport (\n	\"fmt\"\n	\"hello/internal/foo\"\n)\n\nfunc main() {\n	fmt.Println(\"hey, what’s up?\")\n	foo.Bar()\n}\n" :textDocument
		 (:uri "file:///home/stapelberg/repro-emacs/hello1/hello1.go")))
[client-notification] Thu Jun 13 14:22:00 2024:
(:jsonrpc "2.0" :method "workspace/didChangeWatchedFiles" :params
	  (:changes
	   [(:uri "file:///home/stapelberg/repro-emacs/hello1/hello1.go" :type 2)]))
[client-notification] Thu Jun 13 14:22:00 2024:
(:jsonrpc "2.0" :method "workspace/didChangeWatchedFiles" :params
	  (:changes
	   [(:uri "file:///home/stapelberg/repro-emacs/hello1/.%23hello1.go" :type 3)]))
[server-notification] Thu Jun 13 14:22:00 2024:
(:jsonrpc "2.0" :method "window/logMessage" :params
	  (:type 3 :message "2024/06/13 14:22:00 go/packages.Load #3\n	snapshot=6\n	directory=file:///home/stapelberg/repro-emacs/hello1\n	query=[file=/home/stapelberg/repro-emacs/hello1/hello1.go]\n	packages=1\n"))
[server-notification] Thu Jun 13 14:22:00 2024:
(:jsonrpc "2.0" :method "window/logMessage" :params
	  (:type 3 :message "2024/06/13 14:22:00 go/packages.Load #3\n	snapshot=6\n	directory=file:///home/stapelberg/repro-emacs/hello1\n	package=\"hello\"\n	files=[/home/stapelberg/repro-emacs/hello1/hello1.go]\n"))
[server-notification] Thu Jun 13 14:22:00 2024:
(:jsonrpc "2.0" :method "window/logMessage" :params
	  (:type 3 :message "2024/06/13 14:22:00 go/packages.Load #3: updating metadata for 1 packages\n"))
[server-reply] (id:10) Thu Jun 13 14:22:00 2024:
(:jsonrpc "2.0" :result
	  []
	  :id 10)
[server-reply] (id:9) Thu Jun 13 14:22:00 2024:
(:jsonrpc "2.0" :result nil :id 9)
[server-reply] (id:8) Thu Jun 13 14:22:00 2024:
(:jsonrpc "2.0" :result nil :id 8)
[server-notification] Thu Jun 13 14:22:00 2024:
(:jsonrpc "2.0" :method "window/logMessage" :params
	  (:type 1 :message "2024/06/13 14:22:00 no signature help: cannot find an enclosing function\n	position=9:10\n"))
[client-request] (id:11) Thu Jun 13 14:22:01 2024:
(:jsonrpc "2.0" :id 11 :method "textDocument/signatureHelp" :params
	  (:textDocument
	   (:uri "file:///home/stapelberg/repro-emacs/hello1/hello1.go")
	   :position
	   (:line 9 :character 10)))
[client-request] (id:12) Thu Jun 13 14:22:01 2024:
(:jsonrpc "2.0" :id 12 :method "textDocument/hover" :params
	  (:textDocument
	   (:uri "file:///home/stapelberg/repro-emacs/hello1/hello1.go")
	   :position
	   (:line 9 :character 10)))
[client-request] (id:13) Thu Jun 13 14:22:01 2024:
(:jsonrpc "2.0" :id 13 :method "textDocument/documentHighlight" :params
	  (:textDocument
	   (:uri "file:///home/stapelberg/repro-emacs/hello1/hello1.go")
	   :position
	   (:line 9 :character 10)))
[client-request] (id:14) Thu Jun 13 14:22:01 2024:
(:jsonrpc "2.0" :id 14 :method "textDocument/inlayHint" :params
	  (:textDocument
	   (:uri "file:///home/stapelberg/repro-emacs/hello1/hello1.go")
	   :range
	   (:start
	    (:line 3 :character 4)
	    :end
	    (:line 11 :character 0))))
[server-reply] (id:11) Thu Jun 13 14:22:01 2024:
(:jsonrpc "2.0" :result nil :id 11)
[server-notification] Thu Jun 13 14:22:01 2024:
(:jsonrpc "2.0" :method "window/logMessage" :params
	  (:type 1 :message "2024/06/13 14:22:01 no signature help: cannot find an enclosing function\n	position=9:10\n"))
[server-reply] (id:12) Thu Jun 13 14:22:01 2024:
(:jsonrpc "2.0" :result nil :id 12)
[server-reply] (id:13) Thu Jun 13 14:22:01 2024:
(:jsonrpc "2.0" :result
	  []
	  :id 13)
[server-reply] (id:14) Thu Jun 13 14:22:01 2024:
(:jsonrpc "2.0" :result nil :id 14)
[server-notification] Thu Jun 13 14:22:01 2024:
(:jsonrpc "2.0" :method "textDocument/publishDiagnostics" :params
	  (:uri "file:///home/stapelberg/repro-emacs/hello1/hello1.go" :version 4 :diagnostics
		[]))
[server-notification] Thu Jun 13 14:22:01 2024:
(:jsonrpc "2.0" :method "textDocument/publishDiagnostics" :params
	  (:uri "file:///home/stapelberg/repro-emacs/hello1/[email protected]:1718262049" :diagnostics
		[]))
[server-notification] Thu Jun 13 14:22:01 2024:
(:jsonrpc "2.0" :method "textDocument/publishDiagnostics" :params
	  (:uri "file:///home/stapelberg/repro-emacs/hello1/.%23hello1.go" :diagnostics
		[]))
[internal] (id:8) Thu Jun 13 14:22:10 2024:
(:timed-out :textDocument/signatureHelp :id 8 :params
	    (:textDocument
	     (:uri "file:///home/stapelberg/repro-emacs/hello1/hello1.go")
	     :position
	     (:line 9 :character 10)))
[internal] (id:9) Thu Jun 13 14:22:10 2024:
(:timed-out :textDocument/hover :id 9 :params
	    (:textDocument
	     (:uri "file:///home/stapelberg/repro-emacs/hello1/hello1.go")
	     :position
	     (:line 9 :character 10)))
[internal] (id:10) Thu Jun 13 14:22:10 2024:
(:timed-out :textDocument/documentHighlight :id 10 :params
	    (:textDocument
	     (:uri "file:///home/stapelberg/repro-emacs/hello1/hello1.go")
	     :position
	     (:line 9 :character 10)))
@stapelberg stapelberg added gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. labels Jun 13, 2024
@gopherbot gopherbot added this to the Unreleased milestone Jun 13, 2024
@findleyr
Copy link
Member

I believe that this is fixed by https://go.dev/cl/590377, albeit only if you wait 30s.

The real fix is to have gopls itself provide package metadata, since maintaining the active graph of packages is one of gopls' core competencies. This is one of the unfortunate areas where the bolted-on goimports integration suffers.

@pjweinb
Copy link

pjweinb commented Feb 13, 2025

The new imports integration will fix this, but it requires that the metadata graph be up to date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls/imports gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

5 participants