LuaLS / lua-language-server

A language server that offers Lua language support - programmed in Lua
https://luals.github.io
MIT License
3.29k stars 305 forks source link

Support optional chaining #2076

Open spider1987 opened 1 year ago

spider1987 commented 1 year ago

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

carsakiller commented 1 year ago

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
YpsilonTM commented 1 year ago

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.

carsakiller commented 1 year ago

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

YpsilonTM commented 1 year ago

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.

firas-assaad commented 1 year ago

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.

sumneko commented 1 year ago

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

YpsilonTM commented 1 year ago

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

Vurv78 commented 9 months ago

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