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

Waiting for shell command to finish infinite #356

Open
alecStewart1 opened this issue May 31, 2020 · 11 comments
Open

Waiting for shell command to finish infinite #356

alecStewart1 opened this issue May 31, 2020 · 11 comments

Comments

@alecStewart1
Copy link

This is based on an issue that was posted on Reddit recently on the Kakoune subreddit.

What happens is that kak-lsp starts a language server on either standalone files or a project, and upon trying to write a file Kakoune hangs on waiting for shell command to finish.

For me, this is happening on Nim files. Specifically on a Nim file that isn't part of a project and not in a directory that has a .nimble file or .git directory.

Here's is my configuration for kak-lsp

plug "ul/kak-lsp" do %{
   cargo install --force --path ~/.local/bin --locked
   cargo clean
} config %{
	
	set-option global lsp_cmd "kak-lsp -vvv -c ~/.config/kak-lsp/kak-lsp.toml -s %val{session} --log ~/.config/kak-lsp/kak-lsp.log"
	
	define-command lsp-restart %{ lsp-stop; lsp-start }
	
	set-option global lsp_completion_trigger "execute-keys 'h<a-h><a-k>\S[^\s,=;*(){}\[\]]\z<ret>'"
	set-option global lsp_diagnostic_line_error_sign "!"
	set-option global lsp_diagnostic_line_warning_sign "?"
	
	hook global WinSetOption filetype=(c|cpp|objc|d|rust|haskell|nim|elixir|latex|javascript) %{
		
		lsp-enable-window
		echo -debug "Enabling LSP for filtetype %opt{filetype}"
		
		lsp-auto-hover-enable
		lsp-auto-hover-insert-mode-disable
		set-option global lsp_auto_highlight_references true
		set-option global lsp_hover_anchor true
		
		# Semantic highlighting
		hook window -group semantic-tokens BufReload .* lsp-semantic-tokens
		hook window -group semantic-tokens NormalIdle .* lsp-semantic-tokens
		hook window -group semantic-tokens InsertIdle .* lsp-semantic-tokens
		hook -once -always window WinSetOption filetype=.* %{
			 remove-hooks window semantic-tokens
		}
		
		# Other things
		hook window BufWritePre .* lsp-formatting-sync 
		hook window BufWritePost .* lsp-diagnostics
		hook -always global KakEnd .* lsp-exit
	}

}

Here's my configuration for Nim:

hook global WinSetOption filetype=nim %{
	set-option window aligntab false
	set-option window tabstop 2
	set-option window indentwidth 2
	set-option window lintcmd 'sleep 0.3; nim check'
	hook -once window WinSetOption filetype=.* %{
		unset-option window lintcmd
	}
}

And here's why I have to use nimlsp with kak-lsp:

[language.nim]
filetypes = ["nim"]
roots = ["*.nimble", ".git"]
command = "nimlsp"

According to the linked Reddit post, this happens for other languages like Rust, Python, and Dart.

@JJK96
Copy link
Contributor

JJK96 commented Jun 1, 2020

Possibly related to #217

@alecStewart1
Copy link
Author

Well that's nice and all but one of the other problems is that I've failed to ever see a log created by kak-lsp.

I have this as my lsp_cmd:

set-option global lsp_cmd "kak-lsp -vvv -c ~/.config/kak-lsp/kak-lsp.toml -s %val{session} --log ~/.config/kak-lsp/kak-lsp.log"

But I've yet to see any log file in ~/.config/kak-lsp/kak-lsp.log.

I got this from ps aux | grep -v grep | grep -i -e VSZ -e kak:

sh -c  tmp=$(mktemp -q -d -t 'lsp-formatting.XXXXXX' 2>/dev/null || mktemp -q -d) pipe=${tmp}/fifo mkfifo ${pipe}  (printf ' session      = "%s" client       = "%s" buffile      = "%s" filetype     = "%s" version      = %d fifo         = "%s" method       = "textDocument/formatting" [params] tabSize      = %d insertSpaces = %s ' "${kak_session}" "${kak_client}" "${kak_buffile}" "${kak_opt_filetype}" "${kak_timestamp}" ${pipe} "${kak_opt_tabstop}" "${kak_opt_lsp_insert_spaces}" | ${kak_opt_lsp_cmd} --request) > /dev/null 2>&1 < /dev/null  cat ${pipe} rm -rf ${tmp}

Which I'm guessing is an issue with formatting? But I don't have a log file to know definitively.

And another problem is that kak-lsp is either ignoring the TOML file I'm pointing it to, and/or there's some bug where it starts a server even when the given roots specified in the kak-lsp.toml aren't present in the given directory.

@ul
Copy link
Collaborator

ul commented Jun 15, 2020

An alternative way to get a log is to run kak-lsp using this method https://github.com/ul/kak-lsp#crashes . kak-lsp -s foo -vvv for a verbose log.

and/or there's some bug where it starts a server even when the given roots specified in the kak-lsp.toml aren't present in the given directory.

This is expected, tho we perhaps want to consider changing this behaviour.

ul added a commit that referenced this issue Jun 15, 2020
@ul
Copy link
Collaborator

ul commented Jun 15, 2020

Would you mind trying the latest master to see if it resolves your problem? I suspect that something touches file during the save and language server responds with CONTENT_MODIFIED error which hangs synchronous request. If I'm right then the latest master should fix this part. However, it also means that your file will be not formatted because language server refuses to do so. And we don't retry requests automatically for this case at the moment.

@alecStewart1
Copy link
Author

I'm on the latest master and tried having hook window BufWritePre .* lsp-formatting-sync uncommented and still ended up in the infinite loop.

@ul
Copy link
Collaborator

ul commented Jun 15, 2020

Then my hypothesis was wrong =) Having logs would be really helpful to investigate the issue. Please let me know if I can help you with obtaining them. Have you tried to run kak-lsp in a separate terminal rather than as a daemon?

@alecStewart1
Copy link
Author

I would like to give you a log file, but I've never seen one in ~/.config/kak-lsp/.

@alecStewart1
Copy link
Author

alecStewart1 commented Jun 16, 2020

My issue in #363 fixed this issue with formatting. For now, at least.

EDIT: oh, well not for Nim at least.

Enabling LSP for filtetype nim

"""
, module: kak_lsp::editor_transport:125
Jun 15 19:59:41.018 DEBG Language server is not configured for filetype ``, module: kak_lsp::session:80
Jun 15 19:59:41.023 DEBG From editor:
session   = "3753"
client    = "client0"
buffile   = "*debug*"
filetype  = ""
version   = 23
method    = "textDocument/hover"
[params.position]
line      = 1
column    = 1
, module: kak_lsp::editor_transport:125
Jun 15 19:59:41.023 DEBG Language server is not configured for filetype ``, module: kak_lsp::session:80
Jun 15 19:59:49.029 DEBG From editor:
session   = "3753"
client    = "client0"
buffile   = "/home/bigdaddy/Projects/Nim/parallel_nim/src/parallel_nim.nim"
filetype  = "nim"
version   = 4
method    = "textDocument/hover"
[params.position]
line      = 4
column    = 1
, module: kak_lsp::editor_transport:125
Jun 15 19:59:49.029 DEBG Searching for vars starting with KAK_LSP_PROJECT_ROOT_NIM, module: kak_lsp::project_root:42
Jun 15 19:59:49.030 DEBG Routing editor request to Route { session: "3753", language: "nim", root: "/home/bigdaddy/Projects/Nim/parallel_nim" }, module: kak_lsp::session:95
Jun 15 19:59:49.030 DEBG To server: {"jsonrpc":"2.0","method":"textDocument/hover","params":{"position":{"character":0,"line":3},"textDocument":{"uri":"file:///home/bigdaddy/Projects/Nim/parallel_nim/src/parallel_nim.nim"}},"id":9}, module: kak_lsp::language_server_transport:175
Jun 15 19:59:49.038 DEBG From editor:
session   = "3753"
client    = "client0"
buffile   = "/home/bigdaddy/Projects/Nim/parallel_nim/src/parallel_nim.nim"
filetype  = "nim"
version   = 4
method    = "textDocument/documentHighlight"
[params.position]
line      = 4
column    = 1
, module: kak_lsp::editor_transport:125
Jun 15 19:59:49.039 DEBG Searching for vars starting with KAK_LSP_PROJECT_ROOT_NIM, module: kak_lsp::project_root:42
Jun 15 19:59:49.039 DEBG Routing editor request to Route { session: "3753", language: "nim", root: "/home/bigdaddy/Projects/Nim/parallel_nim" }, module: kak_lsp::session:95
Jun 15 19:59:49.039 DEBG To server: {"jsonrpc":"2.0","method":"textDocument/documentHighlight","params":{"position":{"character":0,"line":3},"textDocument":{"uri":"file:///home/bigdaddy/Projects/Nim/parallel_nim/src/parallel_nim.nim"}},"id":10}, module: kak_lsp::language_server_transport:175
Jun 15 19:59:49.064 DEBG From server: {"jsonrpc":"2.0","id":9,"result":null}, module: kak_lsp::language_server_transport:149
Jun 15 19:59:49.418 DEBG From editor:
session   = "3753"
client    = "client0"
buffile   = "/home/bigdaddy/Projects/Nim/parallel_nim/src/parallel_nim.nim"
filetype  = "nim"
version   = 4
method    = "textDocument/hover"
[params.position]
line      = 5
column    = 1
, module: kak_lsp::editor_transport:125
Jun 15 19:59:49.419 DEBG Searching for vars starting with KAK_LSP_PROJECT_ROOT_NIM, module: kak_lsp::project_root:42
Jun 15 19:59:49.419 DEBG Routing editor request to Route { session: "3753", language: "nim", root: "/home/bigdaddy/Projects/Nim/parallel_nim" }, module: kak_lsp::session:95
Jun 15 19:59:49.419 DEBG To server: {"jsonrpc":"2.0","method":"textDocument/hover","params":{"position":{"character":0,"line":4},"textDocument":{"uri":"file:///home/bigdaddy/Projects/Nim/parallel_nim/src/parallel_nim.nim"}},"id":11}, module: kak_lsp::language_server_transport:175
Jun 15 19:59:49.421 DEBG From server: {"jsonrpc":"2.0","id":11,"result":null}, module: kak_lsp::language_server_transport:149
Jun 15 19:59:49.423 DEBG From editor:
session   = "3753"
client    = "client0"
buffile   = "/home/bigdaddy/Projects/Nim/parallel_nim/src/parallel_nim.nim"
filetype  = "nim"
version   = 4
method    = "textDocument/documentHighlight"
[params.position]
line      = 5
column    = 1
, module: kak_lsp::editor_transport:125
Jun 15 19:59:49.423 DEBG Searching for vars starting with KAK_LSP_PROJECT_ROOT_NIM, module: kak_lsp::project_root:42
Jun 15 19:59:49.423 DEBG Routing editor request to Route { session: "3753", language: "nim", root: "/home/bigdaddy/Projects/Nim/parallel_nim" }, module: kak_lsp::session:95
Jun 15 19:59:49.423 DEBG To server: {"jsonrpc":"2.0","method":"textDocument/documentHighlight","params":{"position":{"character":0,"line":4},"textDocument":{"uri":"file:///home/bigdaddy/Projects/Nim/parallel_nim/src/parallel_nim.nim"}},"id":12}, module: kak_lsp::language_server_transport:175
Jun 15 19:59:49.505 DEBG From editor:
session   = "3753"
client    = "client0"
buffile   = "/home/bigdaddy/Projects/Nim/parallel_nim/src/parallel_nim.nim"
filetype  = "nim"
version   = 4
method    = "textDocument/hover"
[params.position]
line      = 4
column    = 1
, module: kak_lsp::editor_transport:125
Jun 15 19:59:49.505 DEBG Searching for vars starting with KAK_LSP_PROJECT_ROOT_NIM, module: kak_lsp::project_root:42
Jun 15 19:59:49.505 DEBG Routing editor request to Route { session: "3753", language: "nim", root: "/home/bigdaddy/Projects/Nim/parallel_nim" }, module: kak_lsp::session:95
Jun 15 19:59:49.506 DEBG To server: {"jsonrpc":"2.0","method":"textDocument/hover","params":{"position":{"character":0,"line":3},"textDocument":{"uri":"file:///home/bigdaddy/Projects/Nim/parallel_nim/src/parallel_nim.nim"}},"id":13}, module: kak_lsp::language_server_transport:175
Jun 15 19:59:49.508 DEBG From server: {"jsonrpc":"2.0","id":13,"result":null}, module: kak_lsp::language_server_transport:149
Jun 15 19:59:49.510 DEBG From editor:
session   = "3753"
client    = "client0"
buffile   = "/home/bigdaddy/Projects/Nim/parallel_nim/src/parallel_nim.nim"
filetype  = "nim"
version   = 4
method    = "textDocument/documentHighlight"
[params.position]
line      = 4
column    = 1
, module: kak_lsp::editor_transport:125
Jun 15 19:59:49.510 DEBG Searching for vars starting with KAK_LSP_PROJECT_ROOT_NIM, module: kak_lsp::project_root:42
Jun 15 19:59:49.511 DEBG Routing editor request to Route { session: "3753", language: "nim", root: "/home/bigdaddy/Projects/Nim/parallel_nim" }, module: kak_lsp::session:95
Jun 15 19:59:49.511 DEBG To server: {"jsonrpc":"2.0","method":"textDocument/documentHighlight","params":{"position":{"character":0,"line":3},"textDocument":{"uri":"file:///home/bigdaddy/Projects/Nim/parallel_nim/src/parallel_nim.nim"}},"id":14}, module: kak_lsp::language_server_transport:175
Jun 15 19:59:50.526 DEBG From editor:
session      = "3753"
client       = "client0"
buffile      = "/home/bigdaddy/Projects/Nim/parallel_nim/src/parallel_nim.nim"
filetype     = "nim"
version      = 4
fifo         = "/tmp/lsp-formatting.0WjQLr/fifo"
method       = "textDocument/formatting"
[params]
tabSize      = 2
insertSpaces = true
, module: kak_lsp::editor_transport:125
Jun 15 19:59:50.526 DEBG Searching for vars starting with KAK_LSP_PROJECT_ROOT_NIM, module: kak_lsp::project_root:42
Jun 15 19:59:50.527 DEBG Routing editor request to Route { session: "3753", language: "nim", root: "/home/bigdaddy/Projects/Nim/parallel_nim" }, module: kak_lsp::session:95
Jun 15 19:59:50.527 DEBG To server: {"jsonrpc":"2.0","method":"textDocument/formatting","params":{"options":{"insertSpaces":true,"tabSize":2},"textDocument":{"uri":"file:///home/bigdaddy/Projects/Nim/parallel_nim/src/parallel_nim.nim"}},"id":15}, module: kak_lsp::language_server_transport:175

@ul
Copy link
Collaborator

ul commented Jun 16, 2020

Is it the entire log? If yes then it seems that Nim language server just didn't respond to the formatting request at all.

@dpc
Copy link
Contributor

dpc commented Jun 16, 2020

@ul Similar to rust-analyzer issue I guess, it's just rust-analyzer will respond in 2-3 minutes. I guess from the perspective of the protocol it's a server's fault, but in practice it would be better if kak-lsp timeouted after some fixed amount of time and printed something warning somewhere.

@ul
Copy link
Collaborator

ul commented Jun 16, 2020

but in practice it would be better if kak-lsp timeouted after some fixed amount of time

It's a good suggestion, PR is welcome. I know you write and like Rust ;-)

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

4 participants