feat: add experimental support for Go files#1384
Merged
Merged
Conversation
joerdav
reviewed
May 12, 2026
Collaborator
|
No game-changing comments here, happy to approve if we decide that they don't need to be addressed! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
See #387
LSP proxy: .go file support and bug fixes
Summary
The proxy now handles requests from
.gofiles (not just.templ), enabling cross-file navigation (e.g. "Go to Definition" on a templ component from a.gofile). Several broken LSP methods are fixed.How it works
Routing:
proxyPositionRequestReplaces the old
updatePositionmethod. For.templfiles, it converts the cursor position via source maps to the generated_templ.goposition. For.gofiles, it passes the position through unchanged. Returnsok=falseonly when a.templsource map lookup fails, causing the handler to return nil.Navigation methods (Definition, Declaration, References, TypeDefinition, Implementation, Rename, PrepareRename, PrepareCallHierarchy) all use this helper. After gopls responds,
_templ.goURIs and ranges in results are converted back to.templusingconvertLocationResultsorconvertCallHierarchyItem.Duplicative features return nil for .go files
Hover, Completion, Formatting, RangeFormatting, CodeAction, DocumentHighlight, DocumentLink, SignatureHelp, OnTypeFormatting, FoldingRanges, SemanticTokens, and Moniker return nil when the request URI is a non-templ
.gofile. The Go extension already provides these for.gofiles.Document sync forwards .go files
DidChange, DidOpen, and DidClose forward
.gofile notifications to gopls so it maintains accurate workspace state.Shared conversion helpers (
rewrite.go)convertGoRangeToTemplRange-- uses the source map cache to map a Go range back to templ source.convertLocationResults-- converts_templ.goURIs/ranges in[]lsp.Locationresults.convertCallHierarchyItem-- converts a call hierarchy item's URI, Range, and SelectionRange.convertWorkspaceEdit-- converts_templ.goURIs/ranges in bothDocumentChangesandChangesmaps.isNonTemplGoURI-- returns true for.gofiles that are not_templ.go.Client-side fixes (
client.go)ApplyEditnow callsconvertWorkspaceEditbefore forwarding to the editor.PublishDiagnosticssilently drops diagnostics for regular.gofiles (the Go extension publishes those) instead of returning an error.Bug fixes
convertLocationResultsinstead of hardcoding request URIconvertWorkspaceEditfor edits (was empty allowlist)_templ.golocations in response (was pass-through)Capability negotiation
The proxy advertises
experimental.templ.goFileSupport: truein its Initialize response. Editors can check this before routing.gofiles to the proxy, ensuring safe independent upgrades of extension and templ binary.Testing
New unit tests in
server_test.go,client_test.go, andrewrite_test.goverify each behavior using mock servers/clients. The integration test for CodeAction now asserts "Organize Imports" is returned.