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

Behavior of Lua.runtime.path not as expected (bug/question) #847

Closed
flrgh opened this issue Dec 6, 2021 · 0 comments
Closed

Behavior of Lua.runtime.path not as expected (bug/question) #847

flrgh opened this issue Dec 6, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@flrgh
Copy link
Contributor

flrgh commented Dec 6, 2021

Describe the bug

Starting with 2.5.0, I noticed that the language server no longer loaded files that correspond to require()-ed modules.

My neovim scripts generate the language server config at startup, which includes populating Lua.runtime.path and Lua.workspace.library with some custom locations, which includes the current working directory and/or workspace directory (repository root). It adds the following paths to Lua.runtime.path:

  • /absolute/path/to/workspace/?.lua
  • /absolute/path/to/workspace/?/init.lua
  • ./?.lua
  • ./?/init.lua

I have discovered that having ?.lua and ?/init.lua (the defaults in the vscode plugin) makes things work properly, but It's odd that the other versions (absolute and relative paths) do not. Is this intended?

To Reproduce

Note: Lua.runtime.pathStrict is set to false

~/git/scratch $ tree
.
├── mod.lua
├── subdir
│   └── sub_module.lua
└── test.lua

contents of subdir/sub_module.lua:

--- my submodule
local _M = {
  --- module name
  name = "sub_module",

  --- some important attribute
  attr = 456,
}

return _M

contents of test.lua:

local mod = require "mod"
print(mod.attr)

local submod = require "subdir.sub_module"
print(submod.attr)

local other = require "other.mod"
print(other.value)

With Lua.runtime.path set to ["?.lua", "?/init.lua"], files are correctly located and loaded:

Screenshot from 2021-12-06 08-59-22

Using relative path (./?.lua|./?/init.lua) or absolute path (/path/to/git/scratch/?.lua|/path/to/git/scratch/?/init.lua) leads to the module not being resolved/loaded:

Screenshot from 2021-12-06 09-00-49

I've also noted that files outside the workspace cannot be loaded via Lua.runtime.path. For instance, if a file exists at /path/to/other/mod.lua, and I add /path/to/other/?.lua to Lua.runtime.path, it is not discovered. I understand that adding /path/to/other to Lua.workspace.library solves this, but all of this makes me wonder: what is the purpose of Lua.runtime.path if only the default values (?.lua|?/init.lua) actually do anything?

Expected behavior

I expected ?.lua, ./?.lua, and /absolute/path/to/?.lua to be equal/equivalent in behavior, but as of 2.5.0 it seems that only ?.lua has any effect.

Ideally I would like to add certain paths to Lua.runtime.path so that files will be discovered when require()-ed but without adding them to Lua.workspace.library (since that causes the full directory to be scanned and pre-loaded, which leads to a slower startup time).

Environment (please complete the following information):

  • OS: Linux
  • Is WSL remote?
  • Client: VSCode and Neovim
@sumneko sumneko added the bug Something isn't working label Dec 7, 2021
sumneko added a commit that referenced this issue Dec 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants