1
#include "script/ScriptDocumentOperation.h"
2
#include "simodo/inout/reporter/StreamReporter.h"
3
#include "simodo/engine/Executor.h"
4
#include "simodo/engine/FrameBody.h"
6
#include "simodo/inout/convert/functions.h"
10
variable::Value makeSimodoCommandResult(
11
const std::u16string & id,
12
const std::u16string & title,
13
lsp::SimodoCommandReportType type,
14
const std::u16string & text
16
return variable::Object{{
19
{ u"type", static_cast<int64_t>(type) },
20
{ u"text", inout::encodeSpecialChars(text) },
24
variable::Value makeSimodoCommandResponse(const std::u16string & uri, const variable::Value & commandResult) {
25
return variable::Object{{
27
{ u"commandResult", commandResult }
31
variable::Value ScriptDocumentOperation::produceSimodoCommandResponse(const std::u16string & command_name, std::u16string text) const
33
_doc.server().log().debug("ScriptDocumentOperation::produceSimodoCommandResponse " + simodo::inout::toU8(command_name)
34
+ " '" + _doc.file_name() + "'");
36
if (command_name.empty() || command_name != execution_report)
39
const std::string initial_contract_file = engine::makeInitialContractFile(_factory.loom_dir());
40
std::ostringstream outputStream;
41
inout::StreamReporter reporter(outputStream);
42
InputSupplier file_supplier(_doc.server(), _doc.file_name(), text);
43
engine::Executor engine(
47
_doc.file_name() == initial_contract_file ? "" : initial_contract_file,
51
// _doc.server().log().debug("ScriptDocumentOperation::produceSimodoCommandResponse created");
53
if (engine.prepare()) {
54
// _doc.server().log().debug("ScriptDocumentOperation::produceSimodoCommandResponse prepared");
56
// _doc.server().log().debug("ScriptDocumentOperation::produceSimodoCommandResponse ran");
59
// _doc.server().log().debug("ScriptDocumentOperation::produceSimodoCommandResponse wrong");
61
return makeSimodoCommandResponse(
62
/* uri = */ inout::toU16(_doc.file_name()),
63
/* commandResult = */ makeSimodoCommandResult(
64
/* id = */ u"grammar-report",
65
/* title = */ u"'" + fs::path(_doc.file_name()).filename().u16string() + u"' " + command_name,
66
/* type = */ lsp::SimodoCommandReportType::plainText,
67
/* text = */ inout::toU16(outputStream.str())