Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Neovim LSP: vim.lsp.buf.code_action does not work #1075

Open
catgoose opened this issue Feb 20, 2025 · 0 comments
Open

Neovim LSP: vim.lsp.buf.code_action does not work #1075

catgoose opened this issue Feb 20, 2025 · 0 comments

Comments

@catgoose
Copy link

catgoose commented Feb 20, 2025

Before you begin

❯ templ version
v0.3.833

Describe the bug
calling vim.lsp.buf.code_action does not work.

Even trying to get results manually fails:

  local client = vim.lsp.get_clients({ name = "templ", bufnr = 0 })[1]
  if not client then
    vim.print("client not found")
    return
  end
  local params = vim.lsp.util.make_range_params(0, "utf-16")
  local result = client:request_sync("textDocument/codeAction", params, 1000, 0)
  vim.print(string.format("result: %s", vim.inspect(result)))

If you change "templ" to "gopls" and try that code snippet in a .go file, you can see code action is displayed

To Reproduce
A small, self-contained, complete reproduction, uploaded to a GitHub repo, containing the minimum amount of files required to reproduce the behaviour, along with a list of commands that need to be run. Keep it simple.

https://github.com/catgoose/templ_issue_repro/tree/main

I used this repo for a previous templ issue, but I have updated the readme with information on how to reproduce issue

Expected behavior
Code action should be displayed

Screenshots

Image

Logs
If the issue is related to IDE support, run through the LSP troubleshooting section at https://templ.guide/commands-and-tools/ide-support/#troubleshooting-1 and include logs from templ

this is from the ~/templ.log file created from the nvim repro, piped through jq

{
  "time": "2025-02-20T07:10:37.845340838-06:00",
  "level": "INFO",
  "msg": "client -> server: CodeAction",
  "params": {
    "textDocument": {
      "uri": "file:///home/catgoose/git/templ_issue_repro/views/index.templ"
    },
    "context": {
      "diagnostics": [
        {
          "range": {
            "start": {
              "line": 6,
              "character": 3
            },
            "end": {
              "line": 6,
              "character": 6
            }
          },
          "severity": 1,
          "code": "UndeclaredName",
          "codeDescription": {
            "href": "https://pkg.go.dev/golang.org/x/tools/internal/typesinternal#UndeclaredName"
          },
          "source": "compiler",
          "message": "undefined: fmt"
        }
      ]
    },
    "range": {
      "start": {
        "line": 6,
        "character": 3
      },
      "end": {
        "line": 6,
        "character": 3
      }
    }
  }
}
{
  "time": "2025-02-20T07:10:37.859051034-06:00",
  "level": "INFO",
  "msg": "client -> server: CodeAction end"
}

templ info output

❯ templ info
(✓) os [ goos=linux goarch=amd64 ]
(✓) go [ location=/usr/local/go/bin/go version=go version go1.24.0 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.3.833 ]

Desktop (please complete the following information):

  • OS: Ubuntu 24.04.2 LTS
  • templ CLI version v0.3.833
  • Go version go version go1.24.0 linux/amd64
  • gopls version golang.org/x/tools/gopls v0.16.2

Additional context
Add any other context about the problem here.
Link in bug_report.md to ide troubleshooting needs to be updated: https://templ.guide/commands-and-tools/ide-support/#troubleshooting-1

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

No branches or pull requests

1 participant