You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Error when exporting Lua language server documentation #3170
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
Install sumneko.lua-3.14.0 extension in VS Code
Create a simple Lua project with documentation comments
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 errorlocalDOC=DOCor (ws.rootUriandfs.path(furi.decode(ws.rootUri)) orfs.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>
changed the title [-]Issue: Error when exporting Lua language server documentation[/-][+]Error when exporting Lua language server documentation[/+]on Apr 30, 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.
Thanks for the workaround! For me, on Linux Mint, this didn't quite work though. Here's what did:
Original error:
script/cli/doc/export.lua:63: bad argument #1 to 'canonical' (std::filesystem::__cxx11::path expected, got nil)
stack traceback:
[C]: in function 'bee.filesystem.canonical'
script/cli/doc/export.lua:63: in field 'getLocalPath'
script/cli/doc/export.lua:152: in field '?'
script/cli/doc/export.lua:120: in field 'documentObject'
script/cli/doc/export.lua:268: in field 'variable'
script/cli/doc/export.lua:241: in field '?'
script/cli/doc/export.lua:120: in field 'documentObject'
script/cli/doc/export.lua:294: 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:1013: in function <script/provider/provider.lua:991>
[C]: in function 'xpcall'
script/proto/proto.lua:202: in function <script/proto/proto.lua:177>
Open export.lua, e.g. /home/markw/.vscode/extensions/sumneko.lua-3.16.0-linux-x64/server/script/cli/doc/export.lua
In VS Code, you can find the extension path by viewing the extension and then clicking "Installation > Size > 12.34MB" (it's weird)
Make the following changes:
...
function export.getLocalPath(uri)
local file_canonical = fs.canonical(furi.decode(uri)):string()
+ -- Define DOC variable to avoid nil error, original workaround+ local DOC = DOC or (ws.rootUri and fs.path(furi.decode(ws.rootUri)) or fs.current_path())
local doc_canonical = fs.canonical(DOC):string()
...
function export.getLualsConfig()
+ -- Define DOC variable to avoid nil error, secondary workaround+ local DOC = DOC or (ws.rootUri and fs.path(furi.decode(ws.rootUri)) or fs.current_path())
return {
name = "LuaLS",
type = "luals.config",
DOC = fs.canonical(fs.path(DOC)):string(),
defines = {},
fields = {},
}
end
...
Restart extensions and wait a few seconds for Lua language server to start again
Run Export Document
Without secondary workaround:
script/cli/doc/export.lua:306: bad argument #1 to 'path' (std::filesystem::__cxx11::path expected, got nil)
stack traceback:
[C]: in function 'bee.filesystem.path'
script/cli/doc/export.lua:306: in field 'getLualsConfig'
script/cli/doc/export.lua:297: 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:1013: in function <script/provider/provider.lua:991>
[C]: in function 'xpcall'
script/proto/proto.lua:202: in function <script/proto/proto.lua:177>
With both original and secondary workaround, the docs were exported successfully :)
Activity
[-]Issue: Error when exporting Lua language server documentation[/-][+]Error when exporting Lua language server documentation[/+]tomlau10 commentedon 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
DOCglobal variable in thegetLocalPath(). 🤔https://github.com/LuaLS/lua-language-server/blame/115a518ad995bfc6ae8dabf216451055e1633898/script/cli/doc/export.lua#L57-L60
DOChere is a global variable representing the--docCLI argument, it should not benilwhen called from CLI:lua-language-server/script/cli/doc/init.lua
Lines 175 to 186 in 606ea70
DOCglobal insidedoc.makeDoc(), and unset after finish?Something like this:
GeTechG commentedon 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.
mark-wiemer commentedon Dec 6, 2025
Thanks for the workaround! For me, on Linux Mint, this didn't quite work though. Here's what did:
Original error:
Open
export.lua, e.g./home/markw/.vscode/extensions/sumneko.lua-3.16.0-linux-x64/server/script/cli/doc/export.luaMake the following changes:
... function export.getLocalPath(uri) local file_canonical = fs.canonical(furi.decode(uri)):string() + -- Define DOC variable to avoid nil error, original workaround + local DOC = DOC or (ws.rootUri and fs.path(furi.decode(ws.rootUri)) or fs.current_path()) local doc_canonical = fs.canonical(DOC):string() ... function export.getLualsConfig() + -- Define DOC variable to avoid nil error, secondary workaround + local DOC = DOC or (ws.rootUri and fs.path(furi.decode(ws.rootUri)) or fs.current_path()) return { name = "LuaLS", type = "luals.config", DOC = fs.canonical(fs.path(DOC)):string(), defines = {}, fields = {}, } end ...Restart extensions and wait a few seconds for Lua language server to start again
Run
Export DocumentWithout secondary workaround:
With both original and secondary workaround, the docs were exported successfully :)