From 3bed7b8f5dddb4e8f7cfc6d853ea3a5bbec99e76 Mon Sep 17 00:00:00 2001 From: Artem Dzhemesiuk Date: Sat, 30 Mar 2024 03:11:34 +0100 Subject: [PATCH] add: plugin ResolveRequire --- src/content/wiki/plugins.mdx | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/content/wiki/plugins.mdx b/src/content/wiki/plugins.mdx index f0ea896..4f44844 100644 --- a/src/content/wiki/plugins.mdx +++ b/src/content/wiki/plugins.mdx @@ -131,3 +131,36 @@ end ``` + +### 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 +``` + + +Example + +```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 +``` + +