lua-language-server icon indicating copy to clipboard operation
lua-language-server copied to clipboard

From 3.6.5 on, luarc is not being modified properly

Open carlosala opened this issue 2 years ago • 35 comments

How are you using the lua-language-server?

NeoVim

Which OS are you using?

Linux

What is the issue affecting?

Libraries

Expected Behaviour

I expect my workspace libraries to be added to .luarc.json.

Actual Behaviour

.luarc.json is not being created nor modified at all. It also prompts for luassert addition to workspace, where I answer 1, yes and modify settings. It does not modifies them.

Reproduction steps

  1. Open a lua file having workspace setting set up.
  2. It will look for all workspace.
  3. It should write in .luarc.json all the content.

Additional Notes

I tried and 3.6.4 was working, 3.6.5 and so on not. Maybe due to https://github.com/sumneko/lua-language-server/blob/4a9ab5b1ae9889e9732b53ad8cdf3b6db5394c3b/changelog.md?plain=1#L33

This is my config on nvim lspconfig:

Lua = {
  runtime = { version = "LuaJIT" },
  diagnostics = { globals = { "vim" } },
  workspace = { library = vim.api.nvim_get_runtime_file("", true) },
},

Log File

No response

carlosala avatar Jan 30 '23 09:01 carlosala

I also see I'm getting this error, it looks it's related:

[ERROR][2023-01-30 10:00:03] .../vim/lsp/rpc.lua:733	"rpc"	"lua-language-server"	"stderr"	"script/json-edit.lua:408: attempt to index a userdata value (local 'ast')
stack traceback:
\tscript/json-edit.lua:408: in function <script/json-edit.lua:407>
\t(...tail calls...)
\tscript/json-edit.lua:578: in function <script/json-edit.lua:570>
\t(...tail calls...)
\tscript/client.lua:349: in upvalue 'editConfigJson'
\tscript/client.lua:401: in upvalue 'tryModifyRC'
\tscript/client.lua:499: in function <script/client.lua:485>
\t[C]: in function 'xpcall'
\tscript/client.lua:485: in function 'client.setConfig'
\tscript/library.lua:467: in upvalue 'apply3rd'
\tscript/library.lua:488: in upvalue 'askFor3rd'
\tscript/library.lua:548: in function <script/library.lua:547>
"

carlosala avatar Jan 30 '23 10:01 carlosala

Thanks @sumneko! Could we get a new release soon so this applies to everyone? Thanks!

carlosala avatar Jan 31 '23 07:01 carlosala

Should in these days.

sumneko avatar Jan 31 '23 08:01 sumneko

Thanks!

carlosala avatar Jan 31 '23 09:01 carlosala

@sumneko v3.6.8 do not solve the issue for me 😢

carlosala avatar Jan 31 '23 13:01 carlosala

@sumneko v3.6.8 do not solve the issue for me 😢

Is the error gone? Is the .luarc.json modified?

sumneko avatar Jan 31 '23 18:01 sumneko

The error is gone, but .luarc.json is not created nor modified (if existed before).

carlosala avatar Jan 31 '23 19:01 carlosala

@sumneko 3.6.9 do not solve the issue, and the error is still gone

carlosala avatar Feb 02 '23 10:02 carlosala

Please provide your .luarc.json

sumneko avatar Feb 02 '23 10:02 sumneko

It doesn't exist, I'd expect before to be created and filled due to my workspaces config, and also with luassert. If I create an empty .luarc.json with just {} inside it don't push there all my workspace stuff from workspaces config and only pushes luassert. Even though, it keeps asking for adding luassert to it, it seems that the issue is that is not adding the workspaces stuff.

carlosala avatar Feb 02 '23 11:02 carlosala

If I create an empty .luarc.json with just {} inside it don't push there all my workspace stuff from workspaces config and only pushes luassert.

It is in designed, different configs will be merged in order. I will check other issues you mentioned.

sumneko avatar Feb 02 '23 11:02 sumneko

Please check if this patch works

sumneko avatar Feb 02 '23 12:02 sumneko

With that patch, luarc is created and luassert is appended if I answer yes, but it's still missing all the information the server finds from my workspace config.

carlosala avatar Feb 02 '23 12:02 carlosala

but it's still missing all the information the server finds from my workspace config.

It is in design. Any other issues?

sumneko avatar Feb 02 '23 12:02 sumneko

but it was not like that until 3.6.4, it was adding all the info, which prevented the server to keep asking me if I want to add luassert (because the luassert is in those libraries)

carlosala avatar Feb 02 '23 12:02 carlosala

Preventing asking is nothing to do with adding all the info, since .luarc.json will be merged with your client config in design. It should be something else.

sumneko avatar Feb 02 '23 12:02 sumneko

not sure what else is missing, but until 3.6.4 was working as expected, I'm sure about that

carlosala avatar Feb 02 '23 12:02 carlosala

Try this patch

sumneko avatar Feb 02 '23 13:02 sumneko

now there's a first load of Loading workspace up to 100%, and then asks for luassert stuff, I answer and there's another load. Closing the editor and reopening asks another time, it doesn't recognizes that I answered yes the previous time, even though luarc is now

{
    "workspace.library": [
        "${3rd}/luassert/library"
    ]
}

carlosala avatar Feb 02 '23 13:02 carlosala

Strange, I still cannot reproduce it. I will look into it tomorrow.

sumneko avatar Feb 02 '23 13:02 sumneko

thank you, I'm sorry to not be able to provide so much information 😢

carlosala avatar Feb 02 '23 13:02 carlosala

Please apply this patch and provide the logs, see https://github.com/sumneko/lua-language-server/wiki/FAQ#where-can-i-find-the-log-file

sumneko avatar Feb 03 '23 07:02 sumneko

there you have, I added trace log level too file_home_carlo_Documents_dev_dotfiles.log

carlosala avatar Feb 03 '23 11:02 carlosala

Could you please provide a log with existing .luarc.json ?

sumneko avatar Feb 03 '23 19:02 sumneko

sure!

That's a log with a .luarc.json empty (well, with {}): file_home_carlo_Documents_dev_dotfiles.log

That's another round of entering the file, after being filled the first time: file_home_carlo_Documents_dev_dotfiles.log

carlosala avatar Feb 04 '23 08:02 carlosala

32cdecd solved the issue for me! 👏🏻

carlosala avatar Feb 04 '23 08:02 carlosala

The only corner case I can find is when workspace.library has something inside, then it's not updated. If initializing from a non-existing luarc I get the following one:

{
    "workspace.library": [
        "/home/carlo/.config/nvim",
        "/etc/xdg/nvim",
        "/home/carlo/.local/share/nvim/site",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/cmp-buffer",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/cmp-git",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/cmp-nvim-lsp",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/cmp-nvim-lsp-signature-help",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/cmp-path",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/cmp_luasnip",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/comment.nvim",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/editorconfig-vim",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/fidget.nvim",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/gitsigns.nvim",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/gruvbox-material",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/impatient.nvim",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/indent-blankline.nvim",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/jsonc.vim",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/lspkind.nvim",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/lualine.nvim",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/luasnip",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/mason-lspconfig.nvim",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/mason.nvim",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/neoformat",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/nvim-autopairs",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/nvim-cmp",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/nvim-lspconfig",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/nvim-r",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/nvim-surround",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/nvim-texlabconfig",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/nvim-tree.lua",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/nvim-treesitter",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/nvim-web-devicons",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/packer.nvim",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/plenary.nvim",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/rust-tools.nvim",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/schemastore.nvim",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/telescope-fzf-native.nvim",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/telescope.nvim",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/typescript.nvim",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/vim-fugitive",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/vim-kitty",
        "/home/carlo/.local/share/nvim/site/pack/packer/opt/nvim-treesitter-context",
        "/home/carlo/.local/share/nvim/site/pack/packer/opt/nvim-ts-autotag",
        "/usr/share/nvim/runtime",
        "/usr/share/nvim/runtime/pack/dist/opt/matchit",
        "/usr/lib/nvim",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/cmp-buffer/after",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/cmp-nvim-lsp/after",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/cmp-nvim-lsp-signature-help/after",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/cmp-path/after",
        "/home/carlo/.local/share/nvim/site/pack/packer/start/cmp_luasnip/after",
        "/home/carlo/.config/nvim/after",
        "/usr/share/vim/vimfiles",
        "${3rd}/luassert/library"
    ]
}

If I start lua with

{
  "workspace.library": []
}

then it doesn't get updated. If any other key is set, then workspace.library is appended as expected. The issue is to not update the array present in workspace.library. These are the logs: file_home_carlo_Documents_dev_dotfiles.log

carlosala avatar Feb 04 '23 08:02 carlosala

What confusing me is that in design, if the values of workspace/library are different between .luarc.json and client config, the value in .luarc.json should be applied and the value in client config should be dismiss.

sumneko avatar Feb 04 '23 08:02 sumneko

Please move the parameter --loglevel=trace into your command line instead of misc.parameters (it is used for VSCode only)

sumneko avatar Feb 04 '23 08:02 sumneko

If I start lua with

{
  "workspace.library": []
}

then it doesn't get updated. If any other key is set, then workspace.library is appended as expected. The issue is to not update the array present in workspace.library.

In this case, the real value of workspace.library is an empty list. (The value from your clien config should be coverred by .luarc.json) After you apply luassert, it should be modified to:

{
    "workspace.library": [
        "${3rd}/luassert/library"
    ]
}

sumneko avatar Feb 04 '23 09:02 sumneko