forked from qt-creator/qt-creator
Lua: Add "printToOutputPane" plugin option
Allows a plugin to automatically forward the "print" command to the output pane instead of only to qDebug() Change-Id: I10fb8063bc1713eaaf77368ea7f760270df190b3 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -5,7 +5,11 @@
|
||||
|
||||
#include "luapluginspec.h"
|
||||
|
||||
#include <coreplugin/messagemanager.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/stringutils.h>
|
||||
#include <utils/theme/theme.h>
|
||||
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
@@ -95,10 +99,6 @@ expected_str<LuaPluginSpec *> LuaEngine::loadPlugin(const Utils::FilePath &path)
|
||||
|
||||
sol::state lua;
|
||||
|
||||
lua["print"] = [prefix = path.fileName()](sol::variadic_args va) {
|
||||
qDebug().noquote() << "[" << prefix << "]" << variadicToStringList(va).join("\t");
|
||||
};
|
||||
|
||||
auto result = lua.safe_script(
|
||||
std::string_view(contents->data(), contents->size()),
|
||||
sol::script_pass_on_error,
|
||||
@@ -135,6 +135,19 @@ expected_str<void> LuaEngine::prepareSetup(
|
||||
sol::lib::table,
|
||||
sol::lib::utf8);
|
||||
|
||||
const bool printToOutputPane = pluginSpec.printToOutputPane();
|
||||
const QString prefix = pluginSpec.filePath().fileName();
|
||||
lua["print"] = [prefix, printToOutputPane](sol::variadic_args va) {
|
||||
const QString msg = variadicToStringList(va).join("\t");
|
||||
|
||||
qDebug().noquote() << "[" << prefix << "]" << msg;
|
||||
if (printToOutputPane) {
|
||||
static const QString p
|
||||
= ansiColoredText("[" + prefix + "]", creatorTheme()->color(Theme::Token_Text_Muted));
|
||||
Core::MessageManager::writeSilently(QString("%1 %2").arg(p, msg));
|
||||
}
|
||||
};
|
||||
|
||||
const QString searchPath = (pluginSpec.location() / "?.lua").toUserOutput();
|
||||
lua["package"]["path"] = searchPath.toStdString();
|
||||
|
||||
|
@@ -138,4 +138,9 @@ ExtensionSystem::IPlugin::ShutdownFlag LuaPluginSpec::stop()
|
||||
|
||||
void LuaPluginSpec::kill() {}
|
||||
|
||||
bool LuaPluginSpec::printToOutputPane() const
|
||||
{
|
||||
return d->pluginTable.get_or("printToOutputPane", false);
|
||||
}
|
||||
|
||||
} // namespace Lua
|
||||
|
@@ -52,6 +52,9 @@ public:
|
||||
bool delayedInitialize() override;
|
||||
ExtensionSystem::IPlugin::ShutdownFlag stop() override;
|
||||
void kill() override;
|
||||
|
||||
public:
|
||||
bool printToOutputPane() const;
|
||||
};
|
||||
|
||||
} // namespace Lua
|
||||
|
@@ -23,6 +23,7 @@ Qtc = {}
|
||||
---@field hooks? Hooks The hooks of the plugin.
|
||||
---@field Mimetypes? string XML MIME-info for registering additional or adapting built-in MIME types.
|
||||
---@field JsonWizardPaths? string[] A list of paths relative to the plugin location or paths to the Qt resource system that are searched for template-based wizards.
|
||||
---@field printToOutputPane? boolean Whether the `print(...)` function should print to the output pane or not. ( Default: false )
|
||||
QtcPlugin = {}
|
||||
|
||||
---@class QtcPluginDependency
|
||||
|
@@ -17,4 +17,5 @@ return {
|
||||
{ Name = "Lua", Version = "13.0.82", Required = true }
|
||||
},
|
||||
setup = function() require 'tests'.setup() end,
|
||||
printToOutputPane = true,
|
||||
} --[[@as QtcPlugin]]
|
||||
|
Reference in New Issue
Block a user