Skip to content

feat: add support for starting gopls in shared daemon mode#1142

Merged
a-h merged 3 commits into
a-h:mainfrom
prathshenoy:shared-gopls
May 8, 2025
Merged

feat: add support for starting gopls in shared daemon mode#1142
a-h merged 3 commits into
a-h:mainfrom
prathshenoy:shared-gopls

Conversation

@prathshenoy
Copy link
Copy Markdown
Contributor

@prathshenoy prathshenoy commented May 1, 2025

Templ LSP currently creates its own instance of Gopls. Gopls supports a shared daemon mode via the -remote flag, enabling multiple clients to connect to a single, long-lived Gopls instance.

Add a -gopls-remote flag to the lsp command to create or connect to a shared Gopls instance, improving efficiency and reducing overhead.

Closes #1141.

@prathshenoy prathshenoy changed the title feat: Add support for starting gopls in shared daemon mode feat: add support for starting gopls in shared daemon mode May 1, 2025
@prathshenoy prathshenoy marked this pull request as ready for review May 1, 2025 21:40
@joerdav
Copy link
Copy Markdown
Collaborator

joerdav commented May 2, 2025

Nice, I had a look at this a while ago as a part of a solution for getting "goToDefinition" from a go file to a templ file to work.

I've tested this out locally, and works great.

This may be something that would be valuable for most users, as it could make the LSP more efficient by spinning up 1 gopls rather than 2? I wonder if a docs entry just to point people in the correct direction might be worth it?

Copy link
Copy Markdown
Collaborator

@joerdav joerdav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, looks good to me!

@prathshenoy
Copy link
Copy Markdown
Contributor Author

Thanks, @joerdav!

I noticed the CI is failing with an HTTP 418 error when trying to download from what looks like a legacy GitHub Actions cache service. The error message says the service was shut down on April 15, 2025, and suggests migrating to the new system.

Also, were you able to get navigation from Go to Templ working with these changes? I wasn't able to get it functioning on my end and had to use some internal tools to help bridge that gap in the developer experience.

@joerdav
Copy link
Copy Markdown
Collaborator

joerdav commented May 2, 2025

Yeah, I saw that! I'll take a look.

We didn't end up getting that to work no. However there is a solution that works by running templ lsp on go files too, it intercepts goToDefinition calls and transforms them if it's a templ file. That's here: #932

@a-h
Copy link
Copy Markdown
Owner

a-h commented May 4, 2025

This will need rebasing on top of main for the CI/CD pipelines to run.

@prathshenoy
Copy link
Copy Markdown
Contributor Author

prathshenoy commented May 4, 2025

Thanks for letting me know! Would it be possible to cut a new release that includes this change (in addition to a release for this change in the VS Code extension)? I realize there was a recent release, but it would be great to roll this out to our users.

@a-h a-h merged commit 9f9a1a3 into a-h:main May 8, 2025
4 checks passed
@a-h
Copy link
Copy Markdown
Owner

a-h commented May 8, 2025

Thanks for your work on the LSP, much appreciated.

@prathshenoy prathshenoy deleted the shared-gopls branch May 8, 2025 13:03
@prathshenoy
Copy link
Copy Markdown
Contributor Author

@a-h @joerdav
I hope y'all are doing well! We're really looking forward to getting this shipped out to our developers 🙂. Do you happen to have an ETA for when this can be included in a release?

Also, just a quick update on your request about how we're using templ internally—we haven't forgotten! We've followed up several times with our Open Source Program Office, but it looks like they're currently short-staffed and not responding to requests across the company. We'll be sure to reach out as soon as we hear back from them.

Thanks again!

@a-h
Copy link
Copy Markdown
Owner

a-h commented May 23, 2025

Got one more PR to review and merge. It's a good improvement to LSP functionality for partial templ files.

Should be this weekend, I think.

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

Successfully merging this pull request may close these issues.

Add support for starting gopls in shared daemon mode

3 participants