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

Support optional chaining

Open spider1987 opened this issue 2 years ago • 8 comments

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?

Formatting

Expected Behaviour

        if weaps[i]?.serial ~= tempInv[i].vars.serial then
            if weaps[i]?.obj then
                DeleteObject(weaps[i].obj)
                weaps[i] = nil
            end
            GiveWeap(tempInv[i])
        end

Actual Behaviour

syntax Problem '?'

Reproduction steps

  1. Go to '...'
  2. Click '...'
  3. See error '...'

Additional Notes

No response

Log File

No response

spider1987 avatar Apr 17 '23 12:04 spider1987

Are you trying to do optional chaining? As far as I know, that is not a feature in Lua. You would have to do something more like:

if weaps[i] and weaps[i].serial ~= tempInv[i].vars.serial then

carsakiller avatar Apr 18 '23 22:04 carsakiller

This is indeed optional chaining in LUA . For example in FiveM if you develop there in LUA it allows for optional chaining. Some extra LUA lib adds this feature to this. So I would be nice to have an option where you can allow for optional chaining to be a thing.

YpsilonTM avatar Apr 22 '23 21:04 YpsilonTM

Interesting! Do you have a link to documentation of the feature? I tried looking for more info on their documentation website but the search managed to allocate over 1GB of RAM and slam my CPU 😆 image

carsakiller avatar Apr 22 '23 22:04 carsakiller

I haven't found wich lib or how they changed it. LUA description here they are talking about a modified 5.3 lua called cfxlua but haven't seen whats under the hood.

YpsilonTM avatar Apr 23 '23 19:04 YpsilonTM

Maybe it's this one? https://github.com/citizenfx/lua/blob/luaglm-dev/cfx/README.md#safe-navigation

Adding all these features means that it's no longer Lua, so it seems like a better idea to fork the Language server specifically for that variant. It looks like that's what cfxlua-vscode is doing.

firas-assaad avatar Apr 24 '23 07:04 firas-assaad

See https://github.com/LuaLS/lua-language-server/wiki/Plugins

sumneko avatar Apr 24 '23 07:04 sumneko

Ok didn't know somebody already made a plugin for all those libs. Awesome.

YpsilonTM avatar Apr 24 '23 08:04 YpsilonTM

Maybe it would be good to support a form of this through a snippet like how ++? works right now

vurvdev avatar Dec 28 '23 18:12 vurvdev