Skip to content

add: plugin ResolveRequire #31

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

Merged
merged 1 commit into from
Apr 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/content/wiki/plugins.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,36 @@ end
```

</Accordion>

### ResolveRequire

This function allows plugin to manually resolve `require('...')` file paths. Useful for environments that implement custom require resolution.

Return `nil` to use default LuaLS resolution. If you return an empty table - LuaLS will not resolve paths.

```Lua
---@param uri string # The URI of file
---@param name string # Argument of require()
---@return string[]?
function ResolveRequire(uri, name) end
```

<Accordion>
<span slot="summary" id="demo-example">Example</span>

```Lua
---@param uri string # The URI of file
---@param name string # Argument of require()
---@return string[]?
function ResolveRequire(uri, name)
-- Check if it's our custom name format
if name:byte(1) ~= 0x40 then -- '@' at beginning
return nil
end

-- Return path to real file location
return { "file:///path/to/mods/" .. name:sub(2) .. "/main.lua" }
end
```

</Accordion>