From 9ec607a1c82a59d41c1dca0b01d82fff6e2fd3af Mon Sep 17 00:00:00 2001 From: tris203 Date: Thu, 29 Aug 2024 17:25:12 +0100 Subject: [PATCH] refactor(lsp): improve URI handling in References method --- cmd/templ/lspcmd/proxy/server.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/templ/lspcmd/proxy/server.go b/cmd/templ/lspcmd/proxy/server.go index 48f34677a..fe6689454 100644 --- a/cmd/templ/lspcmd/proxy/server.go +++ b/cmd/templ/lspcmd/proxy/server.go @@ -939,7 +939,6 @@ func (p *Server) RangeFormatting(ctx context.Context, params *lsp.DocumentRangeF func (p *Server) References(ctx context.Context, params *lsp.ReferenceParams) (result []lsp.Location, err error) { p.Log.Info("client -> server: References") defer p.Log.Info("client -> server: References end") - templURI := params.TextDocument.URI // Rewrite the request. var ok bool ok, params.TextDocument.URI, params.Position = p.updatePosition(params.TextDocument.URI, params.Position) @@ -954,9 +953,10 @@ func (p *Server) References(ctx context.Context, params *lsp.ReferenceParams) (r // Rewrite the response. for i := 0; i < len(result); i++ { r := result[i] - if strings.HasSuffix(r.URI.Filename(), "_templ.go") { - r.URI = templURI - r.Range = p.convertGoRangeToTemplRange(templURI, r.Range) + isTemplURI, templURI := convertTemplGoToTemplURI(r.URI) + if isTemplURI { + p.Log.Info(fmt.Sprintf("references-%d - range conversion for %s", i, r.URI)) + r.URI, r.Range = templURI, p.convertGoRangeToTemplRange(templURI, r.Range) } p.Log.Info(fmt.Sprintf("references-%d: %+v", i, r)) result[i] = r