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

LuaLS autodoc is including global table in output md/json files #2977

Open
Riddle1001 opened this issue Dec 1, 2024 · 8 comments
Open

LuaLS autodoc is including global table in output md/json files #2977

Riddle1001 opened this issue Dec 1, 2024 · 8 comments

Comments

@Riddle1001
Copy link

How are you using the lua-language-server?

Command Line

Which OS are you using?

Windows

What is the issue affecting?

Other

Expected Behaviour

I expect to have only annotations defined with the lua file/directory be generated as docs

Actual Behaviour

The whole _G table is being generated as docs

Reproduction steps

Create a file test.lua with the contents of

---@class Car
---@field color table<number, number>
---@field engine string
local car = {
    color = { 255, 0, 0 },
    engine = "V8",
}

Run the command: ./lua-language-server.exe --doc "./test.lua" --doc_out_path .

Observe the output:
image

Additional Notes

I am using lua-language-server-3.13.2-win32-x64 that I downloaded on github from the releases file

Log File

file_c%3A_Users_test1_Desktop_lua-language-server-3.13.2-win32-x64_bin_test.lua.log

@Riddle1001 Riddle1001 changed the title LuaLS autodoc including global table LuaLS autodoc is including global table in output md/json files Dec 1, 2024
@rhys-vdw
Copy link

rhys-vdw commented Dec 8, 2024

My workaround for this (cc @Luke100000 - #2954 (comment))

lua-language-server --configpath .luarc.doc.json --doc ../.. --doc_out_path _data
// .luarc.doc.json
{
  "$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
  "runtime.version": "Lua 5.1",
  "runtime.builtin": {
    "basic": "disable",
    "bit": "disable",
    "bit32": "disable",
    "builtin": "disable",
    "coroutine": "disable",
    "debug": "disable",
    "ffi": "disable",
    "io": "disable",
    "jit": "disable",
    "math": "disable",
    "os": "disable",
    "package": "disable",
    "string": "disable",
    "table": "disable",
    "table.clear": "disable",
    "table.new": "disable",
    "utf8": "disable"
  }
}

Surprisingly simply adding: "runtime.builtin": {} does not exclude all built-ins.

@Mc-GrowlR
Copy link

My workaround for this (cc @Luke100000 - #2954 (comment))我的解决方法 (cc - #2954 (comment)

lua-language-server --configpath .luarc.doc.json --doc ../.. --doc_out_path _data
// .luarc.doc.json
{
  "$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
  "runtime.version": "Lua 5.1",
  "runtime.builtin": {
    "basic": "disable",
    "bit": "disable",
    "bit32": "disable",
    "builtin": "disable",
    "coroutine": "disable",
    "debug": "disable",
    "ffi": "disable",
    "io": "disable",
    "jit": "disable",
    "math": "disable",
    "os": "disable",
    "package": "disable",
    "string": "disable",
    "table": "disable",
    "table.clear": "disable",
    "table.new": "disable",
    "utf8": "disable"
  }
}

Surprisingly simply adding: "runtime.builtin": {} does not exclude all built-ins.令人惊讶的是,简单地添加: “runtime.builtin”: {} 并不能排除所有内置函数。

Thanks for the method, this is more efficient than I directly changed the doc.lua file in the lsp

@rhys-vdw
Copy link

rhys-vdw commented Dec 15, 2024

Turns my fix is not sufficient. I'm still getting methods like table.insert assert and so on.

Adding these options to .luarc.json works, but it seems as though --configpath is ignored.

@rhys-vdw
Copy link

rhys-vdw commented Dec 15, 2024

Actually, the best fix is to use an older version 3.10.5.

See discussion: #2971 (comment)

It seems doc generation may have been broken by #2821

Sorry, I'm mistaken. The older version has this same problem. It just emits the builtins later in the file so I missed them. My mistake!

At present I have no good solution for this because configpath is not respected. It seems I need to actually modify the config file before generating and then restore it afterwards.

@dizzyi
Copy link

dizzyi commented Dec 18, 2024

So for now just use a script to gen docs? Is it a sensible way to do it?

lua_doc_gen.sh

mv ./.luarc.json ./.luarc.temp.json
mv ./.luarc.docs.json ./.luarc.json

lua-language-server --doc . --doc_out_path .

mv "./.luarc.json" "./.luarc.docs.json"
mv "./.luarc.temp.json" "./.luarc.json"

lua_doc_gen.ps1

Rename-Item -Path ".\.luarc.json" -NewName ".\.luarc.temp.json"
Rename-Item -Path ".\.luarc.docs.json" -NewName ".\.luarc.json"

& 'lua-language-server.exe' --doc . --doc_out_path .

Rename-Item -Path ".\.luarc.json" -NewName ".\.luarc.docs.json"
Rename-Item -Path ".\.luarc.temp.json" -NewName ".\.luarc.json"

@rhys-vdw
Copy link

So for now just use a script to gen docs? Is it a sensible way to do it?

This is my plan too. I made an issue for this problem: #2997

@tomlau10
Copy link
Contributor

I guess the two comments / workarounds below should be posted on this issue instead:

@Mc-GrowlR
Copy link

Hello, my PR seems to be able to help you solve this problem, after testing, the luarc configuration file you provided can be read normally, and the lua module can also be filtered in the exported document.

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

5 participants