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: panic on codeAction #771

Closed
xab3r opened this issue Jun 2, 2024 · 6 comments
Closed

lsp: panic on codeAction #771

xab3r opened this issue Jun 2, 2024 · 6 comments

Comments

@xab3r
Copy link

xab3r commented Jun 2, 2024

Hi,
I'm using SublimeText with LSP plugin. The Templ LSP always throws the error. Looks like it's happening on codeAction

$ templ version
v0.2.707
:: [20:00:01.561] --> templ textDocument/codeAction (4): {'textDocument': {'uri': 'file:///<...>/components/layout.templ'}, 'range': {'start': {'line': 8, 'character': 0}, 'end': {'line': 8, 'character': 0}}, 'context': {'diagnostics': [], 'triggerKind': 2}}
templ: panic: runtime error: invalid memory address or nil pointer dereference
templ: [signal SIGSEGV: segmentation violation code=0x2 addr=0x10 pc=0x104b0cd98]
templ: 
templ: goroutine 25 [running]:
templ: github.com/a-h/templ/cmd/templ/lspcmd/proxy.(*Server).CodeAction(0x140001b2050, {0x104cf1470, 0x140001b2230}, 0x14000200f00)
templ:  /Users/yevhen/developing/go/pkg/mod/github.com/a-h/templ@v0.2.707/cmd/templ/lspcmd/proxy/server.go:294 +0x358
templ: github.com/a-h/protocol.serverDispatch({0x104cf1470, 0x140001b2230}, {0x104cf6880, 0x140001b2050}, 0x140003e29c0, {0x104cf1748, 0x140001964c0})
templ:  /Users/yevhen/developing/go/pkg/mod/github.com/a-h/protocol@v0.0.0-20230224160810-b4eec67c1c22/server.go:158 +0x3e14
templ: github.com/a-h/protocol.NewServer.ServerHandler.func1({0x104cf1470, 0x140001b2230}, 0x140003e29c0, {0x104cf1748, 0x140001964c0})
templ:  /Users/yevhen/developing/go/pkg/mod/github.com/a-h/protocol@v0.0.0-20230224160810-b4eec67c1c22/server.go:36 +0x6c
templ: github.com/a-h/protocol.Handlers.ReplyHandler.func1({0x104cf1470, 0x140001b2230}, 0x1400019c300, {0x104cf1748, 0x140001964c0})
templ:  /Users/yevhen/developing/go/pkg/mod/go.lsp.dev/jsonrpc2@v0.10.0/handler.go:35 +0xc0
templ: github.com/a-h/protocol.Handlers.AsyncHandler.func2.2()
templ:  /Users/yevhen/developing/go/pkg/mod/go.lsp.dev/jsonrpc2@v0.10.0/handler.go:114 +0x78
templ: created by github.com/a-h/protocol.Handlers.AsyncHandler.func2 in goroutine 22
templ:  /Users/yevhen/developing/go/pkg/mod/go.lsp.dev/jsonrpc2@v0.10.0/handler.go:112 +0x164
@xab3r xab3r changed the title LSP panic lsp: panic on codeAction Jun 2, 2024
@a-h
Copy link
Owner

a-h commented Jun 2, 2024

Looks like we're missing a nil check at

for dci := 0; dci < len(r.Edit.DocumentChanges); dci++ {
dc := r.Edit.DocumentChanges[0]
for ei := 0; ei < len(dc.Edits); ei++ {
dc.Edits[ei].Range = p.convertGoRangeToTemplRange(templURI, dc.Edits[ei].Range)
}
dc.TextDocument.URI = templURI
}

@a-h
Copy link
Owner

a-h commented Jun 2, 2024

It seems that r.Edit can be nil, and there's no check.

@a-h a-h closed this as completed in 73474f6 Jun 2, 2024
@a-h
Copy link
Owner

a-h commented Jun 2, 2024

If you can try the commit above, that would be great.

@a-h a-h reopened this Jun 2, 2024
@xab3r
Copy link
Author

xab3r commented Jun 3, 2024

@a-h Yeah, it doesn't panic with this commit. Thanks!

@a-h a-h closed this as completed Jun 3, 2024
@saada
Copy link

saada commented Jun 21, 2024

In case others run into this, I had to patch the global templ installation to get this working

go install github.com/a-h/templ/cmd/templ@73474f65da4509c02aa0666f3277629c8c75e176

@tim-rus
Copy link

tim-rus commented Jun 22, 2024

#800 (comment)

Rolled back to gopls@v0.15.3 and that fixed the problem.

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