Skip to content

Commit

Permalink
refactor(lsp): improve URI handling in References method
Browse files Browse the repository at this point in the history
  • Loading branch information
tris203 committed Sep 5, 2024
1 parent d813668 commit 2c255c9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions cmd/templ/lspcmd/proxy/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 2c255c9

Please sign in to comment.