feat: add socket (luasocket) library annotations
Did you check the docs?
- [X] I have read all the docs
Is your feature request related to a problem? Please describe.
love2d contains an implementation of the luasocket library (see https://www.love2d.org/wiki/socket), however the annotations for it are not included in LuaCATS/love2d.
Describe the solution you'd like
The plugin should add the luasocket annotations (LuaCATS/luasocket) to the lua language server libraries. Probably by also adding it as a submodule to this repo. I'm not sure what the config should look like exactly.
Describe alternatives you've considered
I've made a fork of this plugin with some personal changes. The structure is somewhat different but here's how i'm handling it:
- docs: https://github.com/ColdMacaroni/love2d.nvim/blob/main/doc/love2d.txt#L72-L79
- usr config: https://github.com/ColdMacaroni/love2d.nvim/blob/main/plugin/love2d.lua
- lsp conguration: https://github.com/ColdMacaroni/love2d.nvim/blob/main/ftplugin/lua.lua#L30-L51 hopefully that's helpful, though it is a breaking change for user config.
Another alternative would be to get upstream LuaCATS/love2d to include the socket library (and others), but i don't know if that's in scope for that project.
Additional context
love2d also bundles lua-enet and utf8, but i couldn't find LuaCATS annotations for them :(
I'd like to include only LuaCATS for the lib bundled with LÖVE. According to the LÖVE documentation, the bundled libraries are: luasocket, lua-enet, and utf8.
Since this plugin was written in a rush and does not support proper semver, I suggest keeping it simple and avoiding breaking changes, such as modifying existing options in the setup table.
A possible solution is to add path_to_*_library options and ship those libraries with love2d.nvim as git submodules. However, as you mentioned, LuaCATS for lua-enet and utf8 do not exist. Therefore, I propose adding only path_to_luasocket_library for now.
Example config table:
{
path_to_love_bin = "love",
path_to_love_library = vim.fn.globpath(vim.o.runtimepath, "love2d/library"),
path_to_luasocket_library = vim.fn.globpath(vim.o.runtimepath, "luasocket/library"),
restart_on_save = false,
}
I look forward to merging a PR which implements the following:
- [x] add LuaCATS/luasocket to this repo as a git submodule
- [x] update lua/love2d/config.lua setup_lsp function so it takes library_paths (anarray of library paths) as input and configures those libs for LSP.
- [x] add
path_to_luasocket_libraryto the default config - [x] document the option in the help file (doc/love2d.txt) (same behaviour as
path_to_love_libraryifpath_to_luasocket_libraryis set to"", do not set up LSP for luasocket)
(sorry for the late response, ive been quite busy lately)
@ColdMacaroni, I've tried to implement this feature. For now it's the dev branch.
If you are using lazy.nvim you should be able to test by setting the branch option as follow:
{
"S1M0N38/love2d.nvim",
branch = "dev", -- this is the important setting for using the dev branch
event = "VeryLazy",
opts = { },
keys = {
{ "<leader>v", ft = "lua", desc = "LÖVE" },
{ "<leader>vv", "<cmd>LoveRun<cr>", ft = "lua", desc = "Run LÖVE" },
{ "<leader>vs", "<cmd>LoveStop<cr>", ft = "lua", desc = "Stop LÖVE" },
},
}
If you can confirm that this implementation solve this issue, I'll merge dev into main.
#13