Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix config.root() so it returns a string or nil #192

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jonathannerat
Copy link

@jonathannerat jonathannerat commented Apr 29, 2024

config.root() should return string?, but vim.loop.fs_realpath returns a 3-tuple (see :help vim.uv.fs_realpath and :help luv-error-handling). By adding parentheses around the function call, we force the function to return the first value of the tuple, which also fixes config.types() so it returns string? as well.

This fixes an error when trying to use rocks.nvim to install neodev.nvim. Since the types/ folder is nowhere to be found when installing neodev.nvim with luarocks, the call to fs_realpath returns an error, and stops the execution after any call to config.types() (which happens when trying to setup library folders for the LSP. This creates a bunch of Undefined global 'vim' appear on my init.lua config.

Although this looks like a fix specifically for my use case with rocks.nvim, it makes the function comply with it's signature, which I see as a good thing in the long run.

config.root() should return either string or nil, but
vim.loop.fs_realpath returns a 3-tuple (see `:help vim.uv.fs_realpath`
and `:help luv-error-handling`). By adding parentheses around the
function call, we force root() to return a string or nil, and also
types() to return string or nil.

This fixes an error when trying to use rocks.nvim [1] to install
neodev.nvim. Since the `types/` folder is nowhere to be found when
installing neodev.nvim with luarocks, the call to fs_realpath returns an
error, and stops the execution after any call to config.types().

[1] https://github.com/nvim-neorocks/rocks.nvim
@jonathannerat
Copy link
Author

Oops, my bad, I thought the signature for config.root() meant that it returned a string?, but it's actually for it's argument. Still, I think the fix should be considered, since luals.library() calls config.types(), which calls config.root(), and when root() returns the error mentioned before, the call to luals.library() suddenly stops without errors, and the Undefined global vim error appears.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant