Skip to content

Error when exporting Lua language server documentation #3170

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

Open
GeTechG opened this issue Apr 30, 2025 · 2 comments
Open

Error when exporting Lua language server documentation #3170

GeTechG opened this issue Apr 30, 2025 · 2 comments

Comments

@GeTechG
Copy link

GeTechG commented Apr 30, 2025

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

Windows

What is the issue affecting?

Other

Expected Behaviour

documentation export

Actual Behaviour

I encountered an error when trying to export documentation using the Lua language server (sumneko.lua-3.14.0):
[error]: script\cli\doc\export.lua:61: bad argument #1 to 'canonical' (bee::path expected, got nil)

Reproduction steps

  1. Install sumneko.lua-3.14.0 extension in VS Code
  2. Create a simple Lua project with documentation comments
  3. Try to export documentation (through command palette)

Additional Notes

This appears to be a regression or oversight in the extension where it attempts to use a variable before it's defined. The fix is straightforward and might help other users encountering the same issue.

Solution

I fixed this by modifying script\cli\doc\export.lua to define the DOC variable with a simpler fallback approach that doesn't rely on non-existent functions:

-- Define DOC variable to avoid nil error
local DOC = DOC or (ws.rootUri and fs.path(furi.decode(ws.rootUri)) or fs.current_path())

This simple fix ensures that DOC is always defined with a valid path value before it's used in the getLocalPath function, allowing the documentation export functionality to work properly.

Log File

[00:02:10.453][error][#0]: script\cli\doc\export.lua:61: bad argument #1 to 'canonical' (bee::path expected, got nil)
stack traceback:
[C]: in function 'bee.filesystem.canonical'
script\cli\doc\export.lua:61: in field 'getLocalPath'
script\cli\doc\export.lua:170: in field '?'
script\cli\doc\export.lua:118: in field 'documentObject'
script\cli\doc\export.lua:261: in field 'variable'
script\cli\doc\export.lua:235: in field '?'
script\cli\doc\export.lua:118: in field 'documentObject'
script\cli\doc\export.lua:287: in field 'makeDocs'
script\cli\doc\init.lua:162: in function 'cli.doc.makeDoc'
script\core\command\exportDocument.lua:10: in function 'core.command.exportDocument'
script\provider\provider.lua:1009: in function <script\provider\provider.lua:987>
[C]: in function 'xpcall'
script\proto\proto.lua:202: in function <script\proto\proto.lua:177>

@GeTechG GeTechG changed the title Issue: Error when exporting Lua language server documentation Error when exporting Lua language server documentation Apr 30, 2025
@tomlau10
Copy link
Contributor

tomlau10 commented May 1, 2025

This is surely a regression issue, as the export feature undergoes a heavy refactor before in the PR #2821.
Since then it uses the DOC global variable in the getLocalPath(). 🤔
https://github.com/LuaLS/lua-language-server/blame/115a518ad995bfc6ae8dabf216451055e1633898/script/cli/doc/export.lua#L57-L60

  • AFAIK the DOC here is a global variable representing the --doc CLI argument, it should not be nil when called from CLI:
    ---CLI call for documentation (parameter '--DOC=...' is passed to server)
    function doc.runCLI()
    lang(LOCALE)
    if DOC_UPDATE then
    DOC_OUT_PATH, DOC = getPathDocUpdate()
    end
    if type(DOC) ~= 'string' then
    print(lang.script('CLI_CHECK_ERROR_TYPE', type(DOC)))
    return
    end
  • A better way might be to set this DOC global inside doc.makeDoc(), and unset after finish?
    Something like this:
    DOC = ws.rootUri and fs.path(furi.decode(ws.rootUri)) or fs.current_path()
    local docs = dirty_export.makeDocs(globals, function (i, max)
        prog:setMessage(('%d/%d'):format(i, max))
        prog:setPercentage((i) / max * 100)
    end)
    DOC = nil

@GeTechG
Copy link
Author

GeTechG commented May 1, 2025

@tomlau10 Yes definitely, I would like to point out that I was not running through cli but through the vscode palette suggesting that I may not have accurately pointed out the problem, and the problem is how vscode is called. Since through cli it seems to complete successfully without any problems.

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

2 participants