Skip to content

Commit

Permalink
add: plugin ResolveRequire (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
zziger authored Apr 28, 2024
1 parent da37c24 commit 5030762
Showing 1 changed file with 33 additions and 0 deletions.
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>

0 comments on commit 5030762

Please sign in to comment.