Skip to content

Running Language Server in --doc mode should not truncate output #3049

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

Closed
emuell opened this issue Jan 22, 2025 · 2 comments · Fixed by #3052
Closed

Running Language Server in --doc mode should not truncate output #3049

emuell opened this issue Jan 22, 2025 · 2 comments · Fixed by #3052

Comments

@emuell
Copy link
Contributor

emuell commented Jan 22, 2025

How are you using the lua-language-server?

Command Line

Which OS are you using?

Windows

What is the issue affecting?

Other

Expected Behaviour

We're using the language server to generate a Lua API reference for mdbooks in the project: https://github.com/emuell/luals-docs-gen

In this project, the language server is only used as a raw JSON document generator, not as a language server. We run it via lua-language-server --doc PATH_TO_LIBRARY --doc_out_path =OUT_PATH ... and capture the output.

Apart from the need to adjust a few other settings to optimize the output for our document generator, the output of the language server is in general truncated to ~200 lines for large enums displays and other things. This may be useful when running the language server as, well, a language server, but not when using it as a document generator.

Actual Behaviour

When running the language server in --doc mode, no output should be magically truncated.

Optionally, there should be a user-definable setting/option to tweak this behavior.

Reproduction steps

See Expected Behaviour above...

Additional Notes

It seems that this part of the code is causing the problem:
https://github.com/LuaLS/lua-language-server/blob/master/script/vm/infer.lua#L476

Log File

No response

@tomlau10
Copy link
Contributor

Based on your description and additional notes, the easiest fix that I can come up with would be like this:

-    if #view > 200 then
+    -- do not truncate if exporting doc
+    if not DOC and #view > 200 then
         view = view:sub(1, 180) .. '...(too long)...' .. view:sub(-10)
     end
  • extra launch options are turned into UPPER_SNAKE_CASE during server init
    local function loadArgs()
    ---@type string?
    local lastKey
    for _, v in ipairs(arg) do
    ---@type string?
    local key, tail = v:match '^%-%-([%w_]+)(.*)$'
    local value
    if key then
    value = tail:match '=(.+)'
    lastKey = nil
    if not value then
    lastKey = key
    end
    else
    if lastKey then
    key = lastKey
    value = v
    lastKey = nil
    end
    end
    if key then
    _G[key:upper():gsub('-', '_')] = getValue(value)
    end
  • so when running with --doc, there will be a non nil DOC global variable
  • finally only do the truncate if we are not in DOC mode 🤔

You may test it and open a PR, I believe contributions are welcomed 😄

@emuell
Copy link
Contributor Author

emuell commented Jan 23, 2025

That's indeed a nice fix. PR is here: #3052

Thanks!

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

Successfully merging a pull request may close this issue.

2 participants