LuaLS / lua-language-server

A language server that offers Lua language support - programmed in Lua
https://luals.github.io
MIT License
3.38k stars 319 forks source link

Doc export format requirements break auto-completion, and vice-versa #2935

Open magneto538 opened 2 weeks ago

magneto538 commented 2 weeks ago

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

MacOS

What is the issue affecting?

Annotations, Completion, Hover, Other

Expected Behaviour

The format LLS expects to export documentation and handle autocompletion & hover should be the same. I'd like to export documentation from the same set of definition files I'm shipping as an Addon, and keeping them synced to the same source of truth seems the sensible way to go.

Actual Behaviour

This example is valid as far as documentation export, in that the JSON file generated as output contains references to the functions defined. However, this breaks tooltips/popovers/autocompletion, which require testLib to be defined and returned from this module to function:

---@meta cradle.basic.text

---This is test function 1.
---@param a number This is a number.
---@param b number This is another number.
---@return number This is the sum of a and b.
function testLib.add(a, b) end

---This is test function 2.
---@param a number This is a number.
---@param b number This is another number.
---@return number This is the difference of a and b.
function testLib.sub(a, b) end

Conversely, this other example allows tooltips/popovers/autocompletion to function properly, documentation generated via CLI seems to succeed with no errors, however the actual JSON containing the references is missing any reference to testLib entirely:

---@meta cradle.basic.text

local testLib = {}

---This is test function 1.
---@param a number This is a number.
---@param b number This is another number.
---@return number This is the sum of a and b.
function testLib.add(a, b) end

---This is test function 2.
---@param a number This is a number.
---@param b number This is another number.
---@return number This is the difference of a and b.
function testLib.sub(a, b) end

return testLib

Reproduction steps

  1. Save each of the two examples above as a Lua file somewhere
  2. Modify LLS config to include them
  3. Export documentation via CLI and try to require the library in the workspace
  4. Observe that depending on the example tested, either documentation exporting silently fails, or popovers don't work anymore

Additional Notes

No response

Log File

No response