LuaLS / LuaLS/lua-language-server

Wrong edit range for param completions

Open
#3,273 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lua
Stars
4.4k
Forks
442
PR merge metrics
No merged PRs in 30d

Description

How are you using the lua-language-server?

NeoVim

Which OS are you using?

Linux

What is the issue affecting?

Completion

Expected Behaviour

For parameters that can either be a single value or a list T|T[], when already in a table, the completion range should not include surrounding curly braces.

Actual Behaviour

The completion edit range provided by lua-language-server for parameters seems to always include the entire parameter, which causes issues when completing params that can be either a single value or a list, for example, T|T[].

Reproduction steps
  1. Create test.lua in the test dir with the following content:
    ---@alias my_type 'a'|'b'
    
    ---@param arg my_type|my_type[]
    local function test_func(arg)
      return arg
    end
    
  2. Use neovim to edit test.lua
  3. Try to call test_func at the end of the file with a list parameter: test_func({ ... })
  4. Completions provided by lua-language-server are shown inside the curly braces
  5. Selecting one of the completions replaces the whole parameter, including the surrounding curly braces.

https://github.com/user-attachments/assets/d69214e9-b069-4554-b4ab-770e2fb50632

Additional Notes

I have also reported to the blink.cmp but the maintainer thinks that it is a lua-language-server's issue: https://github.com/Saghen/blink.cmp/issues/2179

Log File

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue using the test.lua example and Neovim, focusing on completion edit ranges for a parameter typed as my_type|my_type[]. Trace how the completion range is calculated when the argument is inside curly braces. Done means selecting a completion replaces only the value inside the braces and preserves the surrounding list syntax.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua, neovim
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.