LuaLS / LuaLS/lua-language-server
VS Code variable resolution in @source annotations/relativity of paths
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 4.4k
- Forks
- 442
- PR merge metrics
- No merged PRs in 30d
Description
### How are you using the lua-language-server?
Visual Studio Code Extension (sumneko.lua)
### Which OS are you using?
Linux
### What is the issue affecting?
Diagnostics/Syntax Checking
### Expected Behaviour
Intuitively, I expected:
1. `---@source` annotations in meta files with relative paths to be resolved relative to the workspace
2. [VS Code variables](https://code.visualstudio.com/docs/reference/variables-reference#_predefined-variables) in the `@source` path to be resolved when resolving a path
### Actual Behaviour
1. `@source` paths are resolved relative to the meta file itself
2. VS Code variables in the path are not resolved
### Reproduction steps
1. Create `.vscode/luals/library/foo.d.lua` with:
```lua
---@meta
--- @class foo
_G.foo = {}
---@source grault/foo.lua:1
function bar() end
```
1. Create `baz.lua` with:
```lua
require("foo")
local quux = foo.bar()
```
3. In extension settings, set:
```json
{
"Lua.workspace.userThirdParty": ["${fileWorkspaceFolder}/LuaLS"]
}
```
> [!NOTE]
> The variable ${fileWorkspaceFolder} resolves correctly and adds the meta file to the list of search paths
4. Open `baz.lua` in VS Code editor
6. Right click `bar`
7. Select `Go to Definition`
8. Observe:
VS Code opens a non-existent source file tab to `.vscode/luals/library/grault/foo.lua`
### Additional Notes
This could be two separate issues, but they're tightly related -- one as a Documentation Issue that the relativity of the resolution of the path should be added to the docs, and two as a Bug/Feature Request that VS Code variables be resolved in the `@source` paths as they are in the settings
Attempting to work around this using [VS Code variables](https://code.visualstudio.com/docs/reference/variables-reference#_predefined-variables) has the variable unresolved and taken literally. For example, setting the `@source` path to `/${fileWorkspaceFolder}/grault/foo.lua:1` causes VS Code to open a tab to that literal string instead of the expected `/home/me/my_project/grault/foo.lua:1`
### Log File
_No response_
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the example with .vscode/luals/library/foo.d.lua, baz.lua, and the workspace.userThirdParty setting. Start by tracing how @source paths are resolved and how VS Code variables are expanded, then verify relative-path behavior and variable substitution against the expected Go to Definition target. Document the chosen path relativity if it remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua, vscode
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100