Skip to content

importing packages hangs emacs in lsp-go #903

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

Closed
seagle0128 opened this issue Jun 23, 2019 · 11 comments
Closed

importing packages hangs emacs in lsp-go #903

seagle0128 opened this issue Jun 23, 2019 · 11 comments

Comments

@seagle0128
Copy link
Collaborator

seagle0128 commented Jun 23, 2019

When import some packages with lsp-go and gopls, the Emacs hangs.

  • macOS, Linux
  • Emacs 26.2/27.0.50
  • the latest lsp-mode
@yyoncho
Copy link
Member

yyoncho commented Jun 23, 2019

Can you do toggle-debug-on-quit and press C-g when emacs hangs and paste the callstack?

@seagle0128
Copy link
Collaborator Author

seagle0128 commented Jun 23, 2019

  • Backtrace:
Debugger entered--Lisp error: (quit)
  process-send-string(#<process gopls> "Content-Length: 194\15\n\15\n{\"jsonrpc\":\"2.0\",\"method\":\"...")
  lsp--send-no-wait("Content-Length: 194\15\n\15\n{\"jsonrpc\":\"2.0\",\"method\":\"..." #<process gopls>)
  lsp--send-request-async((:jsonrpc "2.0" :method "textDocument/documentHighlight" :params (:textDocument (:uri "file:///Users/vincent/go/src/dpim/cli/ui/deploy.go") :position (:line 15 :character 12)) :id 370) #f(compiled-function (highlights) #<bytecode 0x1fe9cadcc065>) nil nil nil)
  lsp-request-async("textDocument/documentHighlight" (:textDocument (:uri "file:///Users/vincent/go/src/dpim/cli/ui/deploy.go") :position (:line 15 :character 12)) #f(compiled-function (highlights) #<bytecode 0x1fe9cadcc065>))
  lsp--document-highlight()
  #f(compiled-function () #<bytecode 0x1fe9cc41a531>)()
  apply(#f(compiled-function () #<bytecode 0x1fe9cc41a531>) nil)
  timer-event-handler([t 0 0 200000 nil #f(compiled-function () #<bytecode 0x1fe9cc41a531>) nil idle 0])
  process-send-string(#<process gopls> "Content-Length: 151\15\n\15\n{\"jsonrpc\":\"2.0\",\"method\":\"...")
  lsp--send-no-wait("Content-Length: 151\15\n\15\n{\"jsonrpc\":\"2.0\",\"method\":\"..." #<process gopls>)
  lsp--send-request-async((:jsonrpc "2.0" :method "textDocument/documentLink" :params (:textDocument (:uri "file:///Users/vincent/go/src/dpim/cli/ui/deploy.go")) :id 369) #f(compiled-function (links) #<bytecode 0x1fe9cba11ff1>) alive nil nil)
  lsp-request-async("textDocument/documentLink" (:textDocument (:uri "file:///Users/vincent/go/src/dpim/cli/ui/deploy.go")) #f(compiled-function (links) #<bytecode 0x1fe9cba11ff1>) :mode alive)
  lsp--update-document-links(#<buffer deploy.go>)
  apply(lsp--update-document-links #<buffer deploy.go>)
  timer-event-handler([t 0 0 100000 nil lsp--update-document-links (#<buffer deploy.go>) idle 0])
  • lsp-log:
no signature help for file:///Users/vincent/go/src/dpim/cli/ui/deploy.go:15:1 : cannot find an enclosing function
no signature help for file:///Users/vincent/go/src/dpim/cli/ui/deploy.go:14:20 : cannot find an enclosing function
no signature help for file:///Users/vincent/go/src/dpim/cli/ui/deploy.go:15:1 : cannot find an enclosing function
no signature help for file:///Users/vincent/go/src/dpim/cli/ui/deploy.go:15:2 : cannot find an enclosing function
Buffer switched - ignoring reponse. Method textDocument/hover

@yyoncho
Copy link
Member

yyoncho commented Jun 23, 2019

AFAIK process-send-string is async and it should not block. Can you confirm that you get this call stack each time you press C-g when emacs hangs in lsp-mode? Also, are you able to reproduce the issue if you disable lsp-enable-symbol-highlighting ? Can you check the process explorer for processes that are taking the system resources? Does the hanging disappear if you wait some time? If it disappears, can you provide a performance report? Were you able to isolate some steps to reproduce?

@seagle0128
Copy link
Collaborator Author

seagle0128 commented Jun 23, 2019

This time I got this backtrace:

Debugger entered--Lisp error: (quit)
  company-dabbrev--search("\\(?:\\sw\\)+" 0.1 all)
  company-dabbrev(candidates "git")
  apply(company-dabbrev (candidates "git"))
  company-call-backend-raw(candidates "git")
  company--fetch-candidates("git")
  company-calculate-candidates("git" nil)
  company--begin-new()
  company--perform()
  company-auto-begin()
  company-idle-begin(#<buffer deploy.go> #<window 3 on deploy.go> 908 304)
  apply(company-idle-begin (#<buffer deploy.go> #<window 3 on deploy.go> 908 304))
  timer-event-handler([t 23823 36130 975307 nil company-idle-begin (#<buffer deploy.go> #<window 3 on deploy.go> 908 304) nil 0])

I suspect the server is hung. Because after I press C-g, then continue inputing the Emacs hangs again, C-g got the backtrace I provided in last comment. And it was unable to open another go files in the project. I had to kill the gopls process and reopen the files. But I didn't encounter hang issue with gopls in VSCode. In the emacs-china forum, someone encounter the same issue with Emacs.

Updated: It only exists in a big go project with many modules.

@yyoncho
Copy link
Member

yyoncho commented Jun 23, 2019

I suspect the server is hung. Because after I press C-g

If the server is hung, this should not hang emacs since lsp-mode is doing async calls. To investigate further, can you exclude company-dabbrev from the company backends? We have to find out the root cause.

@seagle0128
Copy link
Collaborator Author

seagle0128 commented Jun 23, 2019

I use (setq company-backends '(company-lsp)), but the same issue.

I noticed the messages below while typing `import "github.com/xxx"

LSP :: no import for ""
LSP :: no import for "g"
LSP :: no import for "gi"
LSP :: no import for "git"
LSP :: no import for "gith"
LSP :: no import for "githu"
LSP :: no import for "github"
LSP :: no import for "github"
LSP :: no import for "github."
LSP :: no import for "github.c"
LSP :: no import for "github.co"
LSP :: no import for "github.com"

It seems very slow to search. Is it related?

@yyoncho
Copy link
Member

yyoncho commented Jun 23, 2019

Once you have removed company-dabbrev you should reproduce the issue and do C-g until we find out what is causing the issue. Also, can you post a performance report?

It seems very slow to search. Is it related?

I am not familiar with gopls internals.

@muirdm
Copy link
Contributor

muirdm commented Jun 24, 2019

Could be golang/go#32750.

@seagle0128
Copy link
Collaborator Author

Thanks for the information, @muirrn .

It's definitely the same issue.

@muirdm
Copy link
Contributor

muirdm commented Sep 16, 2019

The usptream issue has been closed. @seagle0128 can you confirm this is resolved with latest gopls?

@seagle0128
Copy link
Collaborator Author

Yep, I can confirm the issue has been resolved. Close it. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants