Skip to content

Commit 5030762

Browse files
authored
add: plugin ResolveRequire (#31)
1 parent da37c24 commit 5030762

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/content/wiki/plugins.mdx

+33
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,36 @@ end
131131
```
132132

133133
</Accordion>
134+
135+
### ResolveRequire
136+
137+
This function allows plugin to manually resolve `require('...')` file paths. Useful for environments that implement custom require resolution.
138+
139+
Return `nil` to use default LuaLS resolution. If you return an empty table - LuaLS will not resolve paths.
140+
141+
```Lua
142+
---@param uri string # The URI of file
143+
---@param name string # Argument of require()
144+
---@return string[]?
145+
function ResolveRequire(uri, name) end
146+
```
147+
148+
<Accordion>
149+
<span slot="summary" id="demo-example">Example</span>
150+
151+
```Lua
152+
---@param uri string # The URI of file
153+
---@param name string # Argument of require()
154+
---@return string[]?
155+
function ResolveRequire(uri, name)
156+
-- Check if it's our custom name format
157+
if name:byte(1) ~= 0x40 then -- '@' at beginning
158+
return nil
159+
end
160+
161+
-- Return path to real file location
162+
return { "file:///path/to/mods/" .. name:sub(2) .. "/main.lua" }
163+
end
164+
```
165+
166+
</Accordion>

0 commit comments

Comments
 (0)