Skip to content

Commit

Permalink
Allow plugins to resolve require paths
Browse files Browse the repository at this point in the history
  • Loading branch information
zziger committed Mar 30, 2024
1 parent e930179 commit cf9e386
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
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

0 comments on commit cf9e386

Please sign in to comment.