I was more playing with the thought of concatenating all files into a single string and passing that to the analyzer - that should, theoretically, allow it to do a better job with those functions. I might give it a try later on, for now I'm content with what ZBS does and will recommend it to anyone doing plugin development for MCS, especially when on Linux / MacOS. For Windows, Decoda is still my favorite IDE because it allows me to see stack traces in both the Lua code as well as C++ code.
Hmm, I just couldn't keep off of it. I've tried the following snippet and it seems to do what I want, now only it needs converting from the big blob linenumbers back to original files' names and line numbers
-- packages/analyzeall.lua:
local G = ...
local id = G.ID("analyzeall.analyzeall")
local menuid
local function analyzeProject()
local frame = ide:GetMainFrame()
local menubar = ide:GetMenuBar()
if menubar:IsChecked(ID_CLEAROUTPUT) then ClearOutput() end
DisplayOutputLn("Analyzing the project code.")
frame:Update()
local projectPath = ide:GetProject()
local src = {}
local files = {}
if projectPath then
for _, filePath in ipairs(FileSysGetRecursive(projectPath, true, "*.lua")) do
files[#files + 1] = filePath
end
table.sort(files)
for _, fileName in ipairs(files) do
src[#src + 1] = FileRead(fileName)
end
local warn, err, line = AnalyzeString(table.concat(src, "\n"))
if err then
DisplayOutputNoMarker("Error: " .. err .. "\n")
elseif (#warn > 0) then
DisplayOutputNoMarker(table.concat(warn, "\n") .. "\n")
end
frame:Update() -- refresh the output with new results
end
end
return {
name = "Analyze all files as a single blob",
description = "Analyzes all files in a project.",
author = "Paul Kulchenko",
version = 0.1,
onRegister = function(self)
local menu = ide:GetMenuBar():GetMenu(ide:GetMenuBar():FindMenu(TR("&Project")))
local _, analyzepos = ide:FindMenuItem(menu, ID_ANALYZE)
if analyzepos then
menu:Insert(analyzepos+1, id, TR("Analyze All")..KSC(id), TR("Analyze the project source code"))
end
ide:GetMainFrame():Connect(id, wx.wxEVT_COMMAND_MENU_SELECTED, analyzeProject)
end,
onUnRegister = function(self)
local menu = ide:GetMenuBar():GetMenu(ide:GetMenuBar():FindMenu(TR("&Project")))
ide:GetMainFrame():Disconnect(id, wx.wxID_ANY, wx.wxEVT_COMMAND_MENU_SELECTED)
if menuid then menu:Destroy(menuid) end
end,
}
-- Add this to src/editor/inspect.lua:
function AnalyzeString(src)
local warn, err, line, pos = M.warnings_from_string(src, "src")
if err then
err = err:gsub("line %d+, char %d+", "syntax error")
end
return warn, err, line, pos
end
Of course I'm just messing around, the code will need proper massaging if we want it production-grade.