Oops, that was a last second untested change and it exposed a second problem. The first problem is that I returned "" from get_function_calltip() instead of nil but then tested for nil. The second problem (and why this happened) was the iterative loop never terminated on a successful match. So it would find the right match, show it, then it would search the next file, receive an empty string and display that and so forth. Here is a fixed version. I also added in debugging code. It's off by default but can be quickly toggled to provide diagnostics in the future. MouseHoverCallTips = EventClass:new(Common)
-- If you are experiencing problems with this script then set the following
-- variable to true to enable diagnostic messages.
MouseHoverCallTips.Debug = false
--------------------------------------------------------------------------------
-- OnSwitchFile
--
--------------------------------------------------------------------------------
function MouseHoverCallTips:OnSwitchFile(path)
self:initialize_mouse_dwell()
return false
end
--------------------------------------------------------------------------------
-- initialize_mouse_dwell
--
--------------------------------------------------------------------------------
function MouseHoverCallTips:initialize_mouse_dwell()
--if (self:IsAu3File(path)) then
local mousehover_calltips_dwelltime = tonumber(props["mousehover.calltips.dwelltime"])
if (mousehover_calltips_dwelltime == nil) then mousehover_calltips_dwelltime = 700 end -- default
scite.SendEditor(SCI_SETMOUSEDWELLTIME, mousehover_calltips_dwelltime)
--end
return true
end
--------------------------------------------------------------------------------
-- IsAu3File
--
--------------------------------------------------------------------------------
function MouseHoverCallTips:IsAu3File(path)
if (string.lower(string.sub(path, -4)) == string.lower(string.sub(props["au3"], -4))) then
return true
end
return false
end
--------------------------------------------------------------------------------
-- find_instance
--
--------------------------------------------------------------------------------
function MouseHoverCallTips:find_instance(source, pattern)
local function find_first_instance(source, pattern, acc)
if (source == '') then return 0 end
if (pattern == '') then return 0 end
if (acc == string.len(source)) then return 0 end
if (string.sub(source, acc, acc) == pattern) then
return acc
else
acc = acc + 1
return find_first_instance(source, pattern, acc)
end
end
return find_first_instance(source, pattern, 1)
end
--------------------------------------------------------------------------------
-- get_func_def
--
--------------------------------------------------------------------------------
function MouseHoverCallTips:get_func_def(line, word, style)
local var = string.gsub(line, " (", '(', 1)
local position = self:find_instance(var, '(')
if (position ~= 0) then
local func_name = string.sub(var, 1, position - 1)
if (style == 14) then func_name = string.gsub(func_name, "_AutoItObject_", '') end
func_name = string.lower(func_name)
word = string.lower(word)
if (func_name == word) then return string.gsub(line, "%)(.)", "%)n%1") end -- changed: was adding a trailing empty line in some cases.
end
return nil
end
--------------------------------------------------------------------------------
-- get_function_calltip
--
--------------------------------------------------------------------------------
function MouseHoverCallTips:get_function_calltip(directory, style, word)
local file = io.open(directory, 'r')
if file == nil then return nil end
local function_calltip = nil
for line in file:lines() do
-- filter out constants
if (style == 4) then
local string_end = string.sub(line, -2)
for i = 1, 4 do
if (string_end == '?' .. i) then break end
end
end
function_calltip = self:get_func_def(line, word, style)
if (function_calltip ~= nil) then break end
end
file:close()
return function_calltip
end
--------------------------------------------------------------------------------
-- OnDwellStart
--
--------------------------------------------------------------------------------
function MouseHoverCallTips:OnDwellStart(position, word)
if (word == "") then
if (scite.SendEditor(SCI_CALLTIPACTIVE)) then scite.SendEditor(SCI_CALLTIPCANCEL) end
return true
end
local style = scite.SendEditor(SCI_GETSTYLEAT, position)
if (style == 4 or style == 14 or style == 15) then
local directories = props["api.$(au3)"]
if (directories ~= nil) then
self:DebugPrint("API files: " .. directories)
for directory in directories:gmatch("([^;rn]+)") do
self:DebugPrint("Searching API file: " .. directory)
local function_calltip = self:get_function_calltip(directory, style, word)
if (function_calltip ~= nil) then
self:DebugPrint("Found calltip in API file: " .. directory)
scite.SendEditor(SCI_CALLTIPSHOW, position, function_calltip)
return true
end
end
else
self:DebugPrint("The api.$(au3) is missing or empty.")
end
else
self:DebugPrint("Unsupported style detected.")
end
return true
end Edit: Oops, it was the line mentioned above. Returning "" when the file didn't open was wrong, too, though.