Skip to content

Neovim/Template goto definition returns error: index out of range #911

@catgoose

Description

@catgoose

Before you begin

❯ templ version
v0.2.778

Describe the bug
Attempting to use Neovim templ LSP to go to the definition of a templ template inside of a .templ file will produce error:

Error executing vim.schedule lua callback: /usr/local/share/nvim/runtime/lua/vim/lsp/util.lua:17
98: index out of range
stack traceback:
        [C]: in function '_str_byteindex_enc'
        /usr/local/share/nvim/runtime/lua/vim/lsp/util.lua:1798: in function 'locations_to_items
'
        /usr/local/share/nvim/runtime/lua/vim/lsp/handlers.lua:436: in function 'handler'
        /usr/local/share/nvim/runtime/lua/vim/lsp/client.lua:687: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>
Press ENTER or type command to continue

To Reproduce
https://github.com/catgoose/templ_issue_repro

Follow steps in readme

Expected behavior
Issuing vim.lsp.buf.definition on a templ template reference in a templ file should go to that templates definition

Screenshots
image

Taken from the reproduction repo above

Logs
Log file templ.log included in repro repo

templ info output

❯ templ info
(✓) os [ goos=linux goarch=amd64 ]
(✓) go [ location=/usr/local/go/bin/go version=go version go1.23.1 linux/amd64 ]
(✓) gopls [ location=/home/catgoose/go/bin/gopls version=golang.org/x/tools/gopls v0.16.2 ]
(✓) templ [ location=/home/catgoose/go/bin/templ version=v0.2.778 ]

Desktop (please complete the following information):

  • OS: Ubuntu 24.04.1
  • templ version: v0.2.778
  • Go version: go version go1.23.1 linux/amd64
  • gopls version: golang.org/x/tools/gopls v0.16.2

Additional context
This seems to have been fixed here #893 but the issue persists
Reported here catgoose/templ-goto-definition#1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions