Skip to content
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

Allow plugins to resolve require paths #2590

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion script/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function m.showError(scp, err)
client.showMessage('Error', lang.script('PLUGIN_RUNTIME_ERROR', scp:get('pluginPath'), err))
end

---@alias plugin.event 'OnSetText' | 'OnTransformAst'
---@alias plugin.event 'OnSetText' | 'OnTransformAst' | 'ResolveRequire'

---@param event plugin.event
function m.dispatch(event, uri, ...)
Expand Down
6 changes: 6 additions & 0 deletions script/workspace/require-path.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local workspace = require "workspace"
local config = require 'config'
local scope = require 'workspace.scope'
local util = require 'utility'
local plugin = require 'plugin'

---@class require-path
local m = {}
Expand Down Expand Up @@ -181,6 +182,11 @@ function mt:searchUrisByRequireName(name)
local searcherMap = {}
local excludes = {}

local pluginSuccess, pluginResults = plugin.dispatch('ResolveRequire', self.scp.uri, name)
if pluginSuccess and pluginResults ~= nil then
return pluginResults
end

for uri in files.eachFile(self.scp.uri) do
if vm.isMetaFileRequireable(uri) then
local metaName = vm.getMetaName(uri)
Expand Down
Loading