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

LSP Fill struct code action doesn't work (golang) #1299

Closed
matoous opened this issue Dec 18, 2021 · 8 comments · Fixed by #1304
Closed

LSP Fill struct code action doesn't work (golang) #1299

matoous opened this issue Dec 18, 2021 · 8 comments · Fixed by #1304
Labels
A-language-server Area: Language server client C-bug Category: This is a bug

Comments

@matoous
Copy link
Contributor

matoous commented Dec 18, 2021

Fill XXX code action for golang doesn't do anything.

Reproduction steps

Create main.go file with following content:

package main

type X struct {
	Y string
}

func main() {
	x := X{}
}

place cursor inside the brackets of X{}, press space + a, select Fill X code action.

Environment

  • Platform: macOS
  • Helix version: helix 0.5.0
Helix log is empty. 2021-12-18T22:45:55.225 helix_lsp::transport [ERROR] err: <- StreamClosed

I tried to find more details but without much success so above reproduction steps is all I currently have. Will try to find out more.

@matoous matoous added the C-bug Category: This is a bug label Dec 18, 2021
@kirawi kirawi added the A-language-server Area: Language server client label Dec 18, 2021
@archseer
Copy link
Member

Can you run helix with the -v flag so more logs are available?

@matoous
Copy link
Contributor Author

matoous commented Dec 19, 2021

Sorry, here:

2021-12-19T10:11:07.440 globset [DEBUG] glob converted to regex: Glob { glob: "*.{zip,gz,bz2,zst,lzo,sz,tgz,tbz2,lz,lz4,lzma,lzo,z,Z,xz,7z,rar,cab}", re: "(?-u)^[^/]*\\.(cab|rar|7z|xz|Z|z|lzo|lzma|lz4|lz|tbz2|tgz|sz|lzo|zst|bz2|gz|zip)$", opts: GlobOptions { case_insensitive: false, literal_separator: true, backslash_escape: true }, tokens: Tokens([ZeroOrMore, Literal('.'), Alternates([Tokens([Literal('c'), Literal('a'), Literal('b')]), Tokens([Literal('r'), Literal('a'), Literal('r')]), Tokens([Literal('7'), Literal('z')]), Tokens([Literal('x'), Literal('z')]), Tokens([Literal('Z')]), Tokens([Literal('z')]), Tokens([Literal('l'), Literal('z'), Literal('o')]), Tokens([Literal('l'), Literal('z'), Literal('m'), Literal('a')]), Tokens([Literal('l'), Literal('z'), Literal('4')]), Tokens([Literal('l'), Literal('z')]), Tokens([Literal('t'), Literal('b'), Literal('z'), Literal('2')]), Tokens([Literal('t'), Literal('g'), Literal('z')]), Tokens([Literal('s'), Literal('z')]), Tokens([Literal('l'), Literal('z'), Literal('o')]), Tokens([Literal('z'), Literal('s'), Literal('t')]), Tokens([Literal('b'), Literal('z'), Literal('2')]), Tokens([Literal('g'), Literal('z')]), Tokens([Literal('z'), Literal('i'), Literal('p')])])]) }
2021-12-19T10:11:07.441 globset [DEBUG] built glob set; 0 literals, 0 basenames, 0 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 1 regexes
2021-12-19T10:11:07.441 globset [DEBUG] built glob set; 0 literals, 1 basenames, 0 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes
2021-12-19T10:11:07.442 mio::poll [TRACE] registering event source with poller: token=Token(1), interests=READABLE | WRITABLE
2021-12-19T10:11:07.442 mio::poll [TRACE] registering event source with poller: token=Token(2), interests=READABLE | WRITABLE
2021-12-19T10:11:07.442 mio::poll [TRACE] registering event source with poller: token=Token(0), interests=READABLE
2021-12-19T10:11:07.442 mio::poll [TRACE] registering event source with poller: token=Token(1), interests=READABLE
2021-12-19T10:11:09.225 mio::poll [TRACE] registering event source with poller: token=Token(3), interests=READABLE | WRITABLE
2021-12-19T10:11:09.225 mio::poll [TRACE] registering event source with poller: token=Token(4), interests=READABLE | WRITABLE
2021-12-19T10:11:09.225 mio::poll [TRACE] registering event source with poller: token=Token(5), interests=READABLE | WRITABLE
2021-12-19T10:11:09.225 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{"textDocument":{"codeAction":{"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}}},"completion":{"completionItem":{"snippetSupport":false},"completionItemKind":{}},"hover":{"contentFormat":["markdown"]}},"window":{"workDoneProgress":true}},"processId":26741,"rootUri":null},"id":0}
2021-12-19T10:11:09.285 helix_lsp::transport [INFO] <- {"jsonrpc":"2.0","result":{"capabilities":{"textDocumentSync":{"openClose":true,"change":2,"save":{}},"completionProvider":{"triggerCharacters":["."],"completionItem":{}},"hoverProvider":true,"signatureHelpProvider":{"triggerCharacters":["(",","]},"definitionProvider":true,"typeDefinitionProvider":true,"implementationProvider":true,"referencesProvider":true,"documentHighlightProvider":true,"documentSymbolProvider":true,"codeActionProvider":{"codeActionKinds":["quickfix","refactor.extract","refactor.rewrite","source.fixAll","source.organizeImports"]},"codeLensProvider":{},"documentLinkProvider":{},"workspaceSymbolProvider":true,"documentFormattingProvider":true,"documentOnTypeFormattingProvider":{"firstTriggerCharacter":""},"renameProvider":true,"foldingRangeProvider":true,"executeCommandProvider":{"commands":["gopls.add_dependency","gopls.add_import","gopls.apply_fix","gopls.check_upgrades","gopls.gc_details","gopls.generate","gopls.generate_gopls_mod","gopls.go_get_package","gopls.list_known_packages","gopls.regenerate_cgo","gopls.remove_dependency","gopls.run_tests","gopls.start_debugging","gopls.test","gopls.tidy","gopls.toggle_gc_details","gopls.update_go_sum","gopls.upgrade_dependency","gopls.vendor","gopls.workspace_metadata"]},"callHierarchyProvider":true,"workspace":{"workspaceFolders":{"supported":true,"changeNotifications":"workspace/didChangeWorkspaceFolders"}}},"serverInfo":{"name":"gopls","version":"{\"path\":\"golang.org/x/tools/gopls\",\"version\":\"v0.7.3\",\"sum\":\"h1:Lru57ht8vtDMouRskFC085VAjBAZRAISd/lwvwOOV0Q=\",\"deps\":[{\"path\":\"github.com/BurntSushi/toml\",\"version\":\"v0.3.1\",\"sum\":\"h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=\"},{\"path\":\"github.com/google/go-cmp\",\"version\":\"v0.5.6\",\"sum\":\"h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=\"},{\"path\":\"github.com/sergi/go-diff\",\"version\":\"v1.1.0\",\"sum\":\"h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=\"},{\"path\":\"golang.org/x/mod\",\"version\":\"v0.4.2\",\"sum\":\"h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=\"},{\"path\":\"golang.org/x/sync\",\"version\":\"v0.0.0-20210220032951-036812b2e83c\",\"sum\":\"h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=\"},{\"path\":\"golang.org/x/sys\",\"version\":\"v0.0.0-20210809222454-d867a43fc93e\",\"sum\":\"h1:WUoyKPm6nCo1BnNUvPGnFG3T5DUVem42yDJZZ4CNxMA=\"},{\"path\":\"golang.org/x/text\",\"version\":\"v0.3.6\",\"sum\":\"h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=\"},{\"path\":\"golang.org/x/tools\",\"version\":\"v0.1.8-0.20211014194737-fc98fb2abd48\",\"sum\":\"h1:hk7xRoeg0CG1nRLsd5BZLDUgVpA9bnKylGk1p2/BPH0=\"},{\"path\":\"golang.org/x/xerrors\",\"version\":\"v0.0.0-20200804184101-5ec99f83aff1\",\"sum\":\"h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=\"},{\"path\":\"honnef.co/go/tools\",\"version\":\"v0.2.0\",\"sum\":\"h1:ws8AfbgTX3oIczLPNPCu5166oBg9ST2vNs0rcht+mDE=\"},{\"path\":\"mvdan.cc/gofumpt\",\"version\":\"v0.1.1\",\"sum\":\"h1:bi/1aS/5W00E2ny5q65w9SnKpWEF/UIOqDYBILpo9rA=\"},{\"path\":\"mvdan.cc/xurls/v2\",\"version\":\"v2.3.0\",\"sum\":\"h1:59Olnbt67UKpxF1EwVBopJvkSUBmgtb468E4GVWIZ1I=\"}]}"}},"id":0}
2021-12-19T10:11:09.286 helix_lsp::transport [INFO] <- {"capabilities":{"callHierarchyProvider":true,"codeActionProvider":{"codeActionKinds":["quickfix","refactor.extract","refactor.rewrite","source.fixAll","source.organizeImports"]},"codeLensProvider":{},"completionProvider":{"completionItem":{},"triggerCharacters":["."]},"definitionProvider":true,"documentFormattingProvider":true,"documentHighlightProvider":true,"documentLinkProvider":{},"documentOnTypeFormattingProvider":{"firstTriggerCharacter":""},"documentSymbolProvider":true,"executeCommandProvider":{"commands":["gopls.add_dependency","gopls.add_import","gopls.apply_fix","gopls.check_upgrades","gopls.gc_details","gopls.generate","gopls.generate_gopls_mod","gopls.go_get_package","gopls.list_known_packages","gopls.regenerate_cgo","gopls.remove_dependency","gopls.run_tests","gopls.start_debugging","gopls.test","gopls.tidy","gopls.toggle_gc_details","gopls.update_go_sum","gopls.upgrade_dependency","gopls.vendor","gopls.workspace_metadata"]},"foldingRangeProvider":true,"hoverProvider":true,"implementationProvider":true,"referencesProvider":true,"renameProvider":true,"signatureHelpProvider":{"triggerCharacters":["(",","]},"textDocumentSync":{"change":2,"openClose":true,"save":{}},"typeDefinitionProvider":true,"workspace":{"workspaceFolders":{"changeNotifications":"workspace/didChangeWorkspaceFolders","supported":true}},"workspaceSymbolProvider":true},"serverInfo":{"name":"gopls","version":"{\"path\":\"golang.org/x/tools/gopls\",\"version\":\"v0.7.3\",\"sum\":\"h1:Lru57ht8vtDMouRskFC085VAjBAZRAISd/lwvwOOV0Q=\",\"deps\":[{\"path\":\"github.com/BurntSushi/toml\",\"version\":\"v0.3.1\",\"sum\":\"h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=\"},{\"path\":\"github.com/google/go-cmp\",\"version\":\"v0.5.6\",\"sum\":\"h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=\"},{\"path\":\"github.com/sergi/go-diff\",\"version\":\"v1.1.0\",\"sum\":\"h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=\"},{\"path\":\"golang.org/x/mod\",\"version\":\"v0.4.2\",\"sum\":\"h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=\"},{\"path\":\"golang.org/x/sync\",\"version\":\"v0.0.0-20210220032951-036812b2e83c\",\"sum\":\"h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=\"},{\"path\":\"golang.org/x/sys\",\"version\":\"v0.0.0-20210809222454-d867a43fc93e\",\"sum\":\"h1:WUoyKPm6nCo1BnNUvPGnFG3T5DUVem42yDJZZ4CNxMA=\"},{\"path\":\"golang.org/x/text\",\"version\":\"v0.3.6\",\"sum\":\"h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=\"},{\"path\":\"golang.org/x/tools\",\"version\":\"v0.1.8-0.20211014194737-fc98fb2abd48\",\"sum\":\"h1:hk7xRoeg0CG1nRLsd5BZLDUgVpA9bnKylGk1p2/BPH0=\"},{\"path\":\"golang.org/x/xerrors\",\"version\":\"v0.0.0-20200804184101-5ec99f83aff1\",\"sum\":\"h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=\"},{\"path\":\"honnef.co/go/tools\",\"version\":\"v0.2.0\",\"sum\":\"h1:ws8AfbgTX3oIczLPNPCu5166oBg9ST2vNs0rcht+mDE=\"},{\"path\":\"mvdan.cc/gofumpt\",\"version\":\"v0.1.1\",\"sum\":\"h1:bi/1aS/5W00E2ny5q65w9SnKpWEF/UIOqDYBILpo9rA=\"},{\"path\":\"mvdan.cc/xurls/v2\",\"version\":\"v2.3.0\",\"sum\":\"h1:59Olnbt67UKpxF1EwVBopJvkSUBmgtb468E4GVWIZ1I=\"}]}"}}
2021-12-19T10:11:09.286 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"initialized","params":{}}
2021-12-19T10:11:09.286 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"languageId":"go","text":"package main\n\ntype X struct {\n\tY string\n}\n\nfunc main() {\n\tx := X{}\n}\n","uri":"file:///Users/matousdzivjak/code/example/main.go","version":0}}}
2021-12-19T10:11:09.286 helix_lsp::transport [INFO] <- {"jsonrpc":"2.0","method":"window/workDoneProgress/create","params":{"token":"5577006791947779410"},"id":1}
2021-12-19T10:11:09.286 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","result":null,"id":1}
2021-12-19T10:11:09.286 helix_lsp::transport [INFO] <- {"jsonrpc":"2.0","method":"$/progress","params":{"token":"5577006791947779410","value":{"kind":"begin","title":"Setting up workspace","message":"Loading packages..."}}}
2021-12-19T10:11:09.317 helix_lsp::transport [INFO] <- {"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"2021/12/19 10:11:09 go env for /Users/matousdzivjak/code/example\n(root /Users/matousdzivjak/code/example)\n(go version go version go1.17.5 darwin/amd64)\n(valid build configuration = false)\n(build flags: [])\nGONOSUMDB=\nGOMODCACHE=/Users/matousdzivjak/go/pkg/mod\nGONOPROXY=\nGOPATH=/Users/matousdzivjak/go\nGOPROXY=https://proxy.golang.org,direct\nGOROOT=/usr/local/Cellar/go/1.17.5/libexec\nGOFLAGS=\nGOINSECURE=\nGOPRIVATE=\nGOSUMDB=sum.golang.org\nGO111MODULE=\nGOCACHE=/Users/matousdzivjak/Library/Caches/go-build\nGOMOD=/dev/null\n\n"}}
2021-12-19T10:11:09.317 helix_term::application [INFO] window/logMessage: LogMessageParams { typ: Info, message: "2021/12/19 10:11:09 go env for /Users/matousdzivjak/code/example\n(root /Users/matousdzivjak/code/example)\n(go version go version go1.17.5 darwin/amd64)\n(valid build configuration = false)\n(build flags: [])\nGONOSUMDB=\nGOMODCACHE=/Users/matousdzivjak/go/pkg/mod\nGONOPROXY=\nGOPATH=/Users/matousdzivjak/go\nGOPROXY=https://proxy.golang.org,direct\nGOROOT=/usr/local/Cellar/go/1.17.5/libexec\nGOFLAGS=\nGOINSECURE=\nGOPRIVATE=\nGOSUMDB=sum.golang.org\nGO111MODULE=\nGOCACHE=/Users/matousdzivjak/Library/Caches/go-build\nGOMOD=/dev/null\n\n" }
2021-12-19T10:11:09.408 helix_lsp::transport [INFO] <- {"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"2021/12/19 10:11:09 go/packages.Load\n\tsnapshot=0\n\tdirectory=/Users/matousdzivjak/code/example\n\tquery=[./ builtin]\n\tpackages=2\n"}}
2021-12-19T10:11:09.408 helix_term::application [INFO] window/logMessage: LogMessageParams { typ: Info, message: "2021/12/19 10:11:09 go/packages.Load\n\tsnapshot=0\n\tdirectory=/Users/matousdzivjak/code/example\n\tquery=[./ builtin]\n\tpackages=2\n" }
2021-12-19T10:11:09.408 helix_lsp::transport [INFO] <- {"jsonrpc":"2.0","method":"$/progress","params":{"token":"5577006791947779410","value":{"kind":"end","message":"Finished loading packages."}}}
2021-12-19T10:11:09.409 helix_lsp::transport [INFO] <- {"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///Users/matousdzivjak/code/example/main.go","diagnostics":[{"range":{"start":{"line":7,"character":1},"end":{"line":7,"character":2}},"severity":1,"code":"UnusedVar","codeDescription":{"href":"https://pkg.go.dev/golang.org/x/tools/internal/typesinternal?utm_source=gopls#UnusedVar"},"source":"compiler","message":"x declared but not used"}]}}
2021-12-19T10:11:14.088 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/codeAction","params":{"context":{"diagnostics":[]},"range":{"end":{"character":8,"line":7},"start":{"character":7,"line":7}},"textDocument":{"uri":"file:///Users/matousdzivjak/code/example/main.go"}},"id":1}
2021-12-19T10:11:14.090 helix_lsp::transport [INFO] <- {"jsonrpc":"2.0","result":[{"title":"Fill X","kind":"refactor.rewrite","edit":{},"command":{"title":"Fill X","command":"gopls.apply_fix","arguments":[{"Fix":"fill_struct","URI":"file:///Users/matousdzivjak/code/example/main.go","Range":{"start":{"line":7,"character":6},"end":{"line":7,"character":9}}}]}}],"id":1}
2021-12-19T10:11:14.090 helix_lsp::transport [INFO] <- [{"command":{"arguments":[{"Fix":"fill_struct","Range":{"end":{"character":9,"line":7},"start":{"character":6,"line":7}},"URI":"file:///Users/matousdzivjak/code/example/main.go"}],"command":"gopls.apply_fix","title":"Fill X"},"edit":{},"kind":"refactor.rewrite","title":"Fill X"}]
2021-12-19T10:11:15.349 helix_term::commands [DEBUG] code action: CodeAction { title: "Fill X", kind: Some(CodeActionKind("refactor.rewrite")), diagnostics: None, edit: Some(WorkspaceEdit { changes: None, document_changes: None, change_annotations: None }), command: Some(Command { title: "Fill X", command: "gopls.apply_fix", arguments: Some([Object({"Fix": String("fill_struct"), "Range": Object({"end": Object({"character": Number(9), "line": Number(7)}), "start": Object({"character": Number(6), "line": Number(7)})}), "URI": String("file:///Users/matousdzivjak/code/example/main.go")})]) }), is_preferred: None, disabled: None, data: None }
2021-12-19T10:11:44.111 helix_lsp::transport [INFO] <- {"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"2021/12/19 10:11:44 background imports cache refresh starting\n"}}
2021-12-19T10:11:44.111 helix_term::application [INFO] window/logMessage: LogMessageParams { typ: Info, message: "2021/12/19 10:11:44 background imports cache refresh starting\n" }
2021-12-19T10:11:44.122 helix_lsp::transport [INFO] <- {"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"2021/12/19 10:11:44 background refresh finished after 32.416329ms\n"}}
2021-12-19T10:11:44.123 helix_term::application [INFO] window/logMessage: LogMessageParams { typ: Info, message: "2021/12/19 10:11:44 background refresh finished after 32.416329ms\n" }

-v wasn't enough, but running with DEBUG log I think the issue is the empty edit in the CodeAction maybe? 🤔

2021-12-19T10:11:15.349 helix_term::commands [DEBUG] code action: CodeAction { title: "Fill X", kind: Some(CodeActionKind("refactor.rewrite")), diagnostics: None, edit: Some(WorkspaceEdit { changes: None, document_changes: None, change_annotations: None }), command: Some(Command { title: "Fill X", command: "gopls.apply_fix", arguments: Some([Object({"Fix": String("fill_struct"), "Range": Object({"end": Object({"character": Number(9), "line": Number(7)}), "start": Object({"character": Number(6), "line": Number(7)})}), "URI": String("file:///Users/matousdzivjak/code/example/main.go")})]) }), is_preferred: None, disabled: None, data: None }

@archseer
Copy link
Member

Ah I see, looks like it wants to execute LSP commands, we don't have that code path currently implemented. #183

Probably not that much work to add though, it would enable some other features too

@matoous
Copy link
Contributor Author

matoous commented Dec 19, 2021

I will give it a shot if I may. Also, close this in favor of the original issue?

@matoous
Copy link
Contributor Author

matoous commented Dec 19, 2021

So I tried with b86781f, but currently helix hands for 20s and times out when I try to apply code action with command

2021-12-19T14:12:34.537 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/codeAction","params":{"context":{"diagnostics":[]},"range":{"end":{"character":9,"line":7},"start":{"character":8,"line":7}},"textDocument":{"uri":"file:///Users/matousdzivjak/code/example/main.go"}},"id":1}
2021-12-19T14:12:34.538 helix_lsp::transport [INFO] <- {"jsonrpc":"2.0","result":[{"title":"Fill X","kind":"refactor.rewrite","edit":{},"command":{"title":"Fill X","command":"gopls.apply_fix","arguments":[{"Fix":"fill_struct","URI":"file:///Users/matousdzivjak/code/example/main.go","Range":{"start":{"line":7,"character":6},"end":{"line":7,"character":9}}}]}}],"id":1}
2021-12-19T14:12:34.539 helix_lsp::transport [INFO] <- [{"command":{"arguments":[{"Fix":"fill_struct","Range":{"end":{"character":9,"line":7},"start":{"character":6,"line":7}},"URI":"file:///Users/matousdzivjak/code/example/main.go"}],"command":"gopls.apply_fix","title":"Fill X"},"edit":{},"kind":"refactor.rewrite","title":"Fill X"}]
2021-12-19T14:12:35.143 helix_term::commands [DEBUG] code action: CodeAction { title: "Fill X", kind: Some(CodeActionKind("refactor.rewrite")), diagnostics: None, edit: Some(WorkspaceEdit { changes: None, document_changes: None, change_annotations: None }), command: Some(Command { title: "Fill X", command: "gopls.apply_fix", arguments: Some([Object({"Fix": String("fill_struct"), "Range": Object({"end": Object({"character": Number(9), "line": Number(7)}), "start": Object({"character": Number(6), "line": Number(7)})}), "URI": String("file:///Users/matousdzivjak/code/example/main.go")})]) }), is_preferred: None, disabled: None, data: None }
2021-12-19T14:12:35.143 helix_term::commands [DEBUG] edit: WorkspaceEdit { changes: None, document_changes: None, change_annotations: None }
2021-12-19T14:12:35.143 helix_term::commands [DEBUG] command: Command { title: "Fill X", command: "gopls.apply_fix", arguments: Some([Object({"Fix": String("fill_struct"), "Range": Object({"end": Object({"character": Number(9), "line": Number(7)}), "start": Object({"character": Number(6), "line": Number(7)})}), "URI": String("file:///Users/matousdzivjak/code/example/main.go")})]) }
2021-12-19T14:12:35.144 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"workspace/executeCommand","params":{"arguments":[{"Fix":"fill_struct","Range":{"end":{"character":9,"line":7},"start":{"character":6,"line":7}},"URI":"file:///Users/matousdzivjak/code/example/main.go"}],"command":"gopls.apply_fix"},"id":2}
2021-12-19T14:12:35.146 helix_lsp::transport [INFO] <- {"jsonrpc":"2.0","method":"workspace/applyEdit","params":{"edit":{"documentChanges":[{"textDocument":{"version":0,"uri":"file:///Users/matousdzivjak/code/example/main.go"},"edits":[{"range":{"start":{"line":7,"character":6},"end":{"line":7,"character":9}},"newText":"X{\n\t\tY: \"\",\n\t}"}]}]}},"id":2}
2021-12-19T14:12:55.146 helix_term::commands [ERROR] call LSP command: request timed out
2021-12-19T14:12:55.148 helix_term::application [DEBUG] Received workspace/applyEdit from LSP: ApplyWorkspaceEditParams { label: None, edit: WorkspaceEdit { changes: None, document_changes: Some(Edits([TextDocumentEdit { text_document: OptionalVersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/matousdzivjak/code/example/main.go", query: None, fragment: None }, version: Some(0) }, edits: [Left(TextEdit { range: Range { start: Position { line: 7, character: 6 }, end: Position { line: 7, character: 9 } }, new_text: "X{\n\t\tY: \"\",\n\t}" })] }])), change_annotations: None } }
2021-12-19T14:12:55.148 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","result":{"applied":true},"id":2}
2021-12-19T14:12:55.149 helix_lsp::transport [INFO] <- {"jsonrpc":"2.0","result":null,"id":2}
2021-12-19T14:12:55.149 helix_lsp::transport [INFO] <- null
2021-12-19T14:12:55.149 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(2)), original request likely timed out
2021-12-19T14:13:04.558 helix_lsp::transport [INFO] <- {"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"2021/12/19 14:13:04 background imports cache refresh starting\n"}}
2021-12-19T14:13:04.558 helix_term::application [INFO] window/logMessage: LogMessageParams { typ: Info, message: "2021/12/19 14:13:04 background imports cache refresh starting\n" }
2021-12-19T14:13:04.562 helix_lsp::transport [INFO] <- {"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"2021/12/19 14:13:04 background refresh finished after 22.867477ms\n"}}
2021-12-19T14:13:04.563 helix_term::application [INFO] window/logMessage: LogMessageParams { typ: Info, message: "2021/12/19 14:13:04 background refresh finished after 22.867477ms\n" }

@archseer
Copy link
Member

I think the problem is the block_on which will block the main application loop and stall, so the workspace/applyEdit isn't processed during that time.

You will want to change the command async fn to instead be a regular function that returns a future (similar to the other calls in client.rs) that way the future doesn't borrow lsp::Client for the duration of the call.

Then, for the time being simply tokio::spawn the resulting future. We want to use something similar to cx.callback later and process the response once it arrives, but there's no access to cx there yet. The command response seems to be null | any anyway.

@archseer
Copy link
Member

Also, close this in favor of the original issue?

I think it's okay to keep this one open so it tracks Command/CodeActionOrCommand :)

@matoous
Copy link
Contributor Author

matoous commented Dec 19, 2021

@archseer thanks a lot for the suggestion, it all looks fine with your suggestions I am just wondering how to handle the lifetimes for language server when using tokio::spawn. Currently I am failing

error[E0621]: explicit lifetime required in the type of `cx`
    --> helix-term/src/commands.rs:3294:33
     |
3294 | ...                   tokio::spawn(async move {
     |                       ^^^^^^^^^^^^ lifetime `'static` required

For more information about this error, try `rustc --explain E0621`.
error: failed to compile `helix-term v0.5.0 (/Users/matousdzivjak/code/github.com/helix-editor/helix/helix-term)`, intermediate artifacts can be found at `/Users/matousdzivjak/code/github.com/helix-editor/helix/target`

on #1304. Any help appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-language-server Area: Language server client C-bug Category: This is a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants