Page 1 of 1

Autocomplete/Intellisense for VSCode and Neovim

Posted: Tue Jun 11, 2024 1:46 am
by bjerb
I spent a good while trying to get autocomplete to work correctly with the Love2d API. I typically use Neovim for editing for my day job, and I have Mason doing the automatic installation of language servers, so the typical language server setup was no big deal. However, I'm new to Lua, so I didn't know how to deal with that pesky "Undefined global `love`" error. Most suggestions seemed to say that you should simply put "love" in your language server's globals config. But that quite frankly sucks because you don't get any autocomplete of API methods or types.

After a couple of hours of googling and sadness I finally found a configuration that works with the lua language server, the most popular one by sumneko. Here's the config I landed on for Neovim that actually gives autocomplete for the love2d API:

Code: Select all

        Lua = {
            workspace = {
                library = {
                    "${3rd}/love2d/library",
                },
            },
        }
Additionally, for any folks out there that are using VSCode, here's the simplest settings snippet that got intellisense/autocomplete to work for me:

Code: Select all

{
    "Lua.runtime.version": "LuaJIT",
    "Lua.workspace.library": [
        "${3rd}/love2d/library"
    ]
}
You also need to install the lua language server extension, it's just titled "Lua" by sumneko.

Hope that helps someone else out there.

Re: Autocomplete/Intellisense for VSCode and Neovim

Posted: Thu Jul 04, 2024 9:12 am
by el_mariachi
Hey I just registered to let you know you helped me a lot with this post! I was in the same situation as you, I wasted a lot of time trying making love autocomplete on VSCode, so many thanks!