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

VSCode LSP request failed #956

Open
morigs opened this issue Oct 10, 2024 · 5 comments
Open

VSCode LSP request failed #956

morigs opened this issue Oct 10, 2024 · 5 comments

Comments

@morigs
Copy link

morigs commented Oct 10, 2024

Describe the bug
When opening minimal templ project in VSCode I get the following error: Request textDocument/prepareCallHierarchy failed

To Reproduce

// main.go
package main

import (
	"context"
	"os"
)

func main() {
	component := hello("john")
	component.Render(context.Background(), os.Stdout)
}
package main

templ hello(name string) {
	<div>{ name }</div>
}

Expected behavior
No error

Screenshots
image

Logs

[Error - 15:12:51] Request textDocument/prepareCallHierarchy failed.
  Message: no package metadata for file file:///~/templ-tests/hello.templ
  Code: 0

I replace path to file from absolute to relative.

templ info output

(✓) os [ goos=darwin goarch=arm64 ]
(✓) go [ location=/opt/homebrew/bin/go version=go version go1.23.2 darwin/arm64 ]
(✓) gopls [ location=/Users/morigs/go/bin/gopls version=golang.org/x/tools/gopls v0.16.2 ]
(✓) templ [ location=/Users/morigs/go/bin/templ version=v0.2.778 ]

Desktop (please complete the following information):

  • OS: MacOS
  • templ CLI version: v0.2.778
  • Go version go version go1.23.2 darwin/arm64
  • gopls version (golang.org/x/tools/gopls v0.16.2)

Additional context

I've tried to restart vscode, close other apps, killing all gopls and templ instances, but no luck

@a-h
Copy link
Owner

a-h commented Dec 28, 2024

Did you create a go.mod file by running go mod init github.com/morigs/templ-tests? Without a go.mod file, the Go language server won't be able to run.

If you can create an example and share it, I'd be able to look at it.

@morigs
Copy link
Author

morigs commented Jan 9, 2025

Yes, I have the go.mod. The problem is still present on the latest version of VSCode and Templ extension.
Here's the reproduction:
https://github.com/morigs/templ-tests

@lllama
Copy link

lllama commented Feb 13, 2025

I'm seeing the same thing - my VS Code workspace is a level higher than my go.mod file. Don't know if that could be related.

@a-h
Copy link
Owner

a-h commented Feb 14, 2025

I've been unable to reproduce this. I cloned the repo, and ran go get -u github.com/a-h/templ to update the templ runtime in the project to match the version of templ I've got in my LSP.

go get -u github.com/a-h/templ
go: downloading github.com/a-h/templ v0.3.833
go: upgraded github.com/a-h/templ v0.2.778 => v0.3.833
(✓) os [ goos=darwin goarch=arm64 ]
(✓) go [ location=/run/current-system/sw/bin/go version=go version go1.23.4 darwin/arm64 ]
(✓) gopls [ location=/Users/adrian/go/bin/gopls version=golang.org/x/tools/gopls v0.17.1 ]
(✓) templ [ location=/Users/adrian/go/bin/templ version=v0.3.833 ]

No error messages for me, everything works fine. It might only show up if a particular set of features is enabled etc.

This issue references v0.2.778. https://github.com/a-h/templ/releases/tag/v0.2.793 added workspace folder initialization (see #912), which might have had an effect, but not sure.

@a-h
Copy link
Owner

a-h commented Feb 21, 2025

Not sure if this is relevant...

https://gophers.slack.com/archives/C2B4L99RS/p1739463683666309?thread_ts=1739435803.589139&cid=C2B4L99RS

Image

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