29 #include "wasphit/HITInterpreter.h" 30 #include "waspcore/utils.h" 31 #include "waspplot/CustomPlotSerialization.h" 39 : _moose_app(moose_app),
40 _connection(
std::make_shared<wasp::lsp::IOStreamConnection>(this)),
41 _formatting_tab_size(0)
51 enableExtension(
"plotting");
62 std::string parse_file_path = document_path;
63 pcrecpp::RE(
"(.*://)(.*)").Replace(
"\\2", &parse_file_path);
68 const auto diagnostic = [
this, &diagnosticsList, &pass](
const std::string & message,
70 const int start_column,
71 const std::optional<int> end_line = {},
72 const std::optional<int> end_column = {})
74 diagnosticsList.push_back(wasp::DataObject());
75 auto & diagnostic = *diagnosticsList.back().to_object();
76 pass &= wasp::lsp::buildDiagnosticObject(diagnostic,
80 end_line ? *end_line : start_line,
81 end_column ? *end_column : start_column,
89 const auto zero_line_diagnostic = [&diagnostic](
const std::string & message)
90 { diagnostic(message, 0, 0); };
93 const auto hit_node_diagnostic = [&zero_line_diagnostic, &diagnostic, &parse_file_path](
94 const hit::Node *
const node,
const std::string & message)
97 if (!node || node->isRoot() || node->filename() != parse_file_path || !node->line() ||
99 zero_line_diagnostic(message);
102 diagnostic(message, node->line() - 1, node->column() - 1);
106 const auto hit_error_message_diagnostic =
107 [&diagnostic, &zero_line_diagnostic, &parse_file_path](
const hit::ErrorMessage &
err)
113 if (*
err.filename == parse_file_path)
116 if (
err.lineinfo &&
err.lineinfo->start_line &&
err.lineinfo->start_column &&
117 err.lineinfo->end_line &&
err.lineinfo->end_column)
119 diagnostic(
err.message,
120 err.lineinfo->start_line - 1,
121 err.lineinfo->start_column - 1,
122 err.lineinfo->end_line - 1,
123 err.lineinfo->end_column - 1);
133 zero_line_diagnostic(
err.prefixed_message);
139 const auto try_catch = [&hit_error_message_diagnostic,
140 &hit_node_diagnostic,
141 &zero_line_diagnostic](
const auto & action) ->
bool 155 for (
const auto & error_message :
err.error_messages)
156 hit_error_message_diagnostic(error_message);
162 hit_node_diagnostic(
err.getNode(),
err.what());
165 catch (std::exception &
err)
167 zero_line_diagnostic(
err.what());
175 if (command_line->hasArgument(
"--language-server"))
176 command_line->removeArgument(
"--language-server");
177 command_line->addArgument(
"--check-input");
178 command_line->addArgument(
"--error-unused");
179 command_line->addArgument(
"--error");
180 command_line->addArgument(
"--color=off");
181 command_line->addArgument(
"--disable-perf-graph-live");
182 command_line->parse();
185 auto parser = std::make_shared<Parser>(parse_file_path, document_text);
186 mooseAssert(parser->getInputFileNames()[0] == parse_file_path,
"Should be consistent");
187 parser->setCommandLineParams(command_line->buildHitParams());
188 parser->setThrowOnError(
true);
191 const bool parse_success = try_catch([&parser]() { parser->parse(); });
195 if (
auto parser_root_ptr = parser->queryRoot())
196 if (!parser_root_ptr->getNodeView().is_null())
198 auto it_inserted_pair =
_check_state.emplace(document_path, parser);
199 mooseAssert(it_inserted_pair.second,
"Should not already exist");
200 state = &it_inserted_pair.first->second;
210 app_params.
set<std::shared_ptr<Parser>>(
"_parser") = parser;
211 app_params.
set<std::shared_ptr<CommandLine>>(
"_command_line") = std::move(command_line);
214 std::unique_ptr<MooseApp> app =
nullptr;
215 const auto do_build_app = [
this, &app_params, &app]()
222 if (!try_catch(do_build_app))
230 state->app = std::move(app);
234 if (!try_catch(do_run_app))
249 document_text = replacement_text;
256 bool & is_incomplete,
264 return addSubblocksToList(completionItems,
"/", line, character, line, character,
"",
false);
265 auto & root = *root_ptr;
268 auto is_request_in_open_block = [](wasp::HITNodeView request_context) {
269 return request_context.type() == wasp::OBJECT || request_context.type() == wasp::DOCUMENT_ROOT;
271 auto is_request_on_param_decl = [](wasp::HITNodeView request_context)
273 return request_context.type() == wasp::DECL && request_context.has_parent() &&
274 (request_context.parent().type() == wasp::KEYED_VALUE ||
275 request_context.parent().type() == wasp::ARRAY);
277 auto is_request_on_block_decl = [](wasp::HITNodeView request_context)
279 return request_context.type() == wasp::DECL && request_context.has_parent() &&
280 request_context.parent().type() == wasp::OBJECT;
284 wasp::HITNodeView view_root = root.getNodeView();
285 wasp::HITNodeView request_context;
288 if (line + 1 < (
int)view_root.last_line() ||
289 (line + 1 == (
int)view_root.last_line() && character <= (
int)view_root.last_column()))
290 request_context = wasp::findNodeUnderLineColumn(view_root, line + 1, character + 1);
296 wasp::findNodeUnderLineColumn(view_root, view_root.last_line(), view_root.last_column());
299 wasp::HITNodeView object_context = request_context;
300 while (object_context.type() != wasp::OBJECT && object_context.has_parent())
301 object_context = object_context.parent();
302 if (request_context.type() == wasp::OBJECT_TERM && object_context.has_parent())
303 object_context = object_context.parent();
304 request_context = object_context;
308 if (is_request_in_open_block(request_context))
310 wasp::HITNodeView backup_context = request_context;
311 for (
int backup_char = character; backup_context == request_context && --backup_char > 0;)
312 backup_context = wasp::findNodeUnderLineColumn(request_context, line + 1, backup_char + 1);
313 if (backup_context.type() == wasp::ASSIGN || backup_context.type() == wasp::OVERRIDE_ASSIGN)
314 request_context = backup_context;
318 int replace_line_beg = line;
319 int replace_char_beg = character;
320 int replace_line_end = line;
321 int replace_char_end = character;
322 std::string filtering_prefix;
323 if (request_context.type() == wasp::DECL || request_context.type() == wasp::VALUE)
326 replace_line_beg = request_context.line() - 1;
327 replace_char_beg = request_context.column() - 1;
328 replace_line_end = request_context.last_line() - 1;
329 replace_char_end = request_context.last_column();
330 filtering_prefix = request_context.data();
333 if (is_request_on_block_decl(request_context) && filtering_prefix.empty())
341 const auto & parent_name = request_context.has_parent() ? request_context.parent().name() :
"";
344 wasp::HITNodeView object_context = request_context;
345 while (object_context.type() != wasp::OBJECT && object_context.has_parent())
346 object_context = object_context.parent();
347 if (is_request_on_block_decl(request_context))
348 object_context = object_context.parent();
349 const std::string & object_path = object_context.path();
350 wasp::HITNodeView type_node = object_context.first_child_by_name(
"type");
351 const std::string & object_type =
352 type_node.is_null() ?
"" : wasp::strip_quotes(hit::extractValue(type_node.data()));
355 std::set<std::string> existing_params, existing_subblocks;
362 std::set<std::string> obj_act_tasks;
370 if (is_request_in_open_block(request_context) || is_request_on_param_decl(request_context))
381 if (is_request_in_open_block(request_context) || is_request_on_param_decl(request_context) ||
382 is_request_on_block_decl(request_context))
390 is_request_on_block_decl(request_context));
393 if ((request_context.type() == wasp::VALUE || request_context.type() == wasp::ASSIGN ||
394 request_context.type() == wasp::OVERRIDE_ASSIGN) &&
408 is_incomplete = !pass;
415 std::set<std::string> & existing_params,
416 std::set<std::string> & existing_subblocks)
419 for (
auto itr = parent_node.begin(); itr != parent_node.end(); itr.next())
421 auto child_node = itr.get();
424 if (child_node.type() == wasp::KEYED_VALUE || child_node.type() == wasp::ARRAY)
425 existing_params.insert(child_node.name());
426 else if (child_node.type() == wasp::OBJECT)
427 existing_subblocks.insert(child_node.name());
433 const std::string & object_path,
434 const std::string & object_type,
435 std::set<std::string> & obj_act_tasks)
445 const std::string & object_path,
446 std::set<std::string> & obj_act_tasks)
453 std::string registered_syntax = syntax.
isAssociated(object_path, &is_parent);
459 auto action_range = syntax.
getActions(registered_syntax);
462 for (
auto action_iter = action_range.first; action_iter != action_range.second; action_iter++)
464 const std::string & action_name = action_iter->second._action;
472 if (action_params.
get<
bool>(
"isObjectAction"))
474 std::set<std::string> tasks_by_actions = action_factory.
getTasksByAction(action_name);
475 obj_act_tasks.insert(tasks_by_actions.begin(), tasks_by_actions.end());
479 action_params.
remove(
"isObjectAction");
483 valid_params += action_params;
490 std::string object_type,
491 const std::set<std::string> & obj_act_tasks)
497 if (object_type.empty() && valid_params.
have_parameter<std::string>(
"type") &&
498 !valid_params.
get<std::string>(
"type").empty())
500 object_type = valid_params.
get<std::string>(
"type");
515 const std::string & moose_base = object_params.
getBase();
517 for (
const auto & obj_act_task : obj_act_tasks)
522 valid_params += object_params;
530 if (valid_params.
have_parameter<std::vector<std::string>>(
"_object_params_set_by_action"))
532 auto names = valid_params.
get<std::vector<std::string>>(
"_object_params_set_by_action");
533 for (
const auto &
name : names)
537 valid_params.
remove(
"_object_params_set_by_action");
544 const std::set<std::string> & existing_params,
545 int replace_line_beg,
546 int replace_char_beg,
547 int replace_line_end,
548 int replace_char_end,
549 const std::string & filtering_prefix)
554 for (
const auto & valid_params_iter : valid_params)
556 const std::string & param_name = valid_params_iter.first;
557 bool deprecated = valid_params.isParamDeprecated(param_name);
558 bool is_private = valid_params.isPrivate(param_name);
561 if (deprecated || is_private || existing_params.count(param_name))
565 if (param_name.rfind(filtering_prefix, 0) != 0)
569 std::string dirty_type = valid_params.type(param_name);
572 std::string doc_string = valid_params.getDocString(param_name);
576 bool is_array = basic_type.compare(0, 6,
"Array:") == 0;
579 pcrecpp::RE(
"(Array:)*(.*)").GlobalReplace(
"\\2", &basic_type);
582 pcrecpp::RE(
".+<([A-Za-z0-9_' ':]*)>.*").GlobalReplace(
"\\1", &clean_type);
588 std::string default_value;
591 if (valid_params.isParamValid(param_name))
598 else if (valid_params.hasDefaultCoupledValue(param_name))
600 std::ostringstream oss;
601 oss << valid_params.defaultCoupledValue(param_name);
602 default_value = oss.str();
606 if (basic_type ==
"Boolean" && default_value ==
"1")
607 default_value =
"true";
608 else if (basic_type ==
"Boolean" && default_value ==
"0")
609 default_value =
"false";
612 std::string array_quote = is_array && !default_value.empty() ?
"'" :
"";
616 std::string insert_text;
617 if (client_snippet_support && !default_value.empty())
619 text_format = wasp::lsp::m_text_format_snippet;
620 insert_text = param_name +
" = " + array_quote +
"${1:" + default_value +
"}" + array_quote;
624 text_format = wasp::lsp::m_text_format_plaintext;
625 insert_text = param_name +
" = " + array_quote + default_value + array_quote;
630 completionItems.push_back(wasp::DataObject());
631 wasp::DataObject * item = completionItems.back().to_object();
632 pass &= wasp::lsp::buildCompletionObject(*item,
653 const std::string & object_path,
654 int replace_line_beg,
655 int replace_char_beg,
656 int replace_line_end,
657 int replace_char_end,
658 const std::string & filtering_prefix,
659 bool request_on_block_decl)
664 std::set<std::string> syntax_paths_processed;
671 std::string syntax_path =
"/" + syntax_path_iter.first;
674 if (!syntax_paths_processed.insert(syntax_path).second)
678 for (std::size_t last_sep; (last_sep = syntax_path.find_last_of(
"/")) != std::string::npos;)
680 std::string subblock_name = syntax_path.substr(last_sep + 1);
681 syntax_path = syntax_path.substr(0, last_sep);
693 if (!registered_syntax.empty() || object_path ==
"/")
696 int text_format = client_snippet_support ? wasp::lsp::m_text_format_snippet
697 : wasp::lsp::m_text_format_plaintext;
702 if (subblock_name !=
"*" && subblock_name.rfind(filtering_prefix, 0) != 0)
705 std::string doc_string;
706 std::string insert_text;
710 const std::string full_block_path = object_path +
"/" + subblock_name;
714 if (subblock_name ==
"*")
716 doc_string =
"custom user named block";
717 insert_text = (request_on_block_decl ?
"" :
"[") +
718 (filtering_prefix.size() ? filtering_prefix :
"block_name") +
"]" +
719 req_params +
"\n " + (client_snippet_support ?
"$0" :
"") +
"\n[]";
720 complete_kind = wasp::lsp::m_comp_kind_variable;
724 doc_string =
"application named block";
725 insert_text = (request_on_block_decl ?
"" :
"[") + subblock_name +
"]" + req_params +
726 "\n " + (client_snippet_support ?
"$0" :
"") +
"\n[]";
727 complete_kind = wasp::lsp::m_comp_kind_struct;
731 completionItems.push_back(wasp::DataObject());
732 wasp::DataObject * item = completionItems.back().to_object();
733 pass &= wasp::lsp::buildCompletionObject(*item,
756 const std::set<std::string> & existing_params,
757 const std::set<std::string> & existing_subblocks,
758 const std::string & param_name,
759 const std::set<std::string> & obj_act_tasks,
760 const std::string & object_path,
761 int replace_line_beg,
762 int replace_char_beg,
763 int replace_line_end,
764 int replace_char_end)
770 std::string dirty_type = valid_params.
type(param_name);
775 pcrecpp::RE(
"(Array:)*(.*)").GlobalReplace(
"\\2", &basic_type);
778 pcrecpp::RE(
".+<([A-Za-z0-9_' ':]*)>.*").GlobalReplace(
"\\1", &clean_type);
784 std::map<std::string, std::string> options_and_descs;
787 if (param_name ==
"active" || param_name ==
"inactive")
788 for (
const auto & subblock_name : existing_subblocks)
789 options_and_descs[subblock_name] =
"subblock name";
792 else if (basic_type ==
"Boolean")
794 options_and_descs[
"true"];
795 options_and_descs[
"false"];
805 else if (valid_params.
have_parameter<std::vector<MooseEnum>>(param_name))
806 getEnumsAndDocs(valid_params.
get<std::vector<MooseEnum>>(param_name)[0], options_and_descs);
809 else if (param_name ==
"type")
814 const std::string & object_name = objects_iter.first;
815 const InputParameters & object_params = objects_iter.second->buildParameters();
819 req_params += req_params.size() ?
"\n" + std::string(client_snippet_support ?
"$0" :
"") :
"";
824 const std::string & moose_base = object_params.
getBase();
827 for (
const auto & obj_act_task : obj_act_tasks)
833 options_and_descs[object_name + req_params] = type_description;
847 const std::string &
type = associated_types_iter.second;
848 const std::string & path = associated_types_iter.first;
858 wasp::HITNodeView view_root =
getRoot().getNodeView();
861 for (
const auto & input_path : input_path_iter->second)
864 wasp::SIRENInterpreter<> selector;
865 if (!selector.parseString(input_path))
867 wasp::SIRENResultSet<wasp::HITNodeView> results;
868 std::size_t count = selector.evaluate(view_root, results);
871 for (std::size_t i = 0; i < count; i++)
872 if (results.adapted(i).type() == wasp::OBJECT)
873 options_and_descs[results.adapted(i).name()] =
"from /" + input_path;
879 int text_format = client_snippet_support ? wasp::lsp::m_text_format_snippet
880 : wasp::lsp::m_text_format_plaintext;
885 for (
const auto & option_and_desc : options_and_descs)
887 const std::string & insert_text = option_and_desc.first;
888 const std::string & option_name = insert_text.substr(0, insert_text.find(
'\n'));
889 const std::string & description = option_and_desc.second;
892 completionItems.push_back(wasp::DataObject());
893 wasp::DataObject * item = completionItems.back().to_object();
894 pass &= wasp::lsp::buildCompletionObject(*item,
913 template <
typename MooseEnumType>
916 std::map<std::string, std::string> & options_and_descs)
919 const auto & enum_docs = moose_enum_param.getItemDocumentation();
922 for (
const auto & item : moose_enum_param.items())
923 options_and_descs[item.name()] = enum_docs.count(item) ? enum_docs.at(item) :
"";
937 auto & root = *root_ptr;
940 wasp::HITNodeView view_root = root.getNodeView();
941 wasp::HITNodeView request_context =
942 wasp::findNodeUnderLineColumn(view_root, line + 1, character + 1);
945 if (request_context.type() != wasp::VALUE)
949 std::string param_name = request_context.has_parent() ? request_context.parent().name() :
"";
950 std::string val_string = request_context.last_as_string();
953 if (param_name ==
"type" && factory.
isRegistered(val_string))
959 if (!file_line_info.
isValid() ||
964 auto location_uri = wasp::lsp::m_uri_prefix + file_line_info.
file();
967 definitionLocations.push_back(wasp::DataObject());
968 wasp::DataObject * location = definitionLocations.back().to_object();
969 return wasp::lsp::buildLocationObject(*location,
972 file_line_info.
line() - 1,
974 file_line_info.
line() - 1,
979 wasp::HITNodeView object_context = request_context;
980 while (object_context.type() != wasp::OBJECT && object_context.has_parent())
981 object_context = object_context.parent();
982 const std::string & object_path = object_context.path();
983 wasp::HITNodeView type_node = object_context.first_child_by_name(
"type");
984 const std::string & object_type =
985 type_node.is_null() ?
"" : wasp::strip_quotes(hit::extractValue(type_node.data()));
991 std::set<std::string> obj_act_tasks;
998 [](
const wasp::HITNodeView & l,
const wasp::HITNodeView & r)
1000 const std::string & l_file = l.node_pool()->stream_name();
1001 const std::string & r_file = r.node_pool()->stream_name();
1002 return (l_file < r_file || (l_file == r_file && l.line() < r.line()) ||
1003 (l_file == r_file && l.line() == r.line() && l.column() < r.column()));
1007 for (
const auto & valid_params_iter : valid_params)
1009 if (valid_params_iter.first == param_name)
1012 std::string dirty_type = valid_params.type(param_name);
1014 pcrecpp::RE(
".+<([A-Za-z0-9_' ':]*)>.*").GlobalReplace(
"\\1", &clean_type);
1023 if (location_nodes.empty() && request_context.has_parent() &&
1024 request_context.parent().child_count_by_name(
"decl"))
1025 location_nodes.insert(request_context.parent().first_child_by_name(
"decl"));
1033 const std::string & clean_type,
1034 const std::string & val_string)
1043 const std::string &
type = associated_types_iter.second;
1044 const std::string & path = associated_types_iter.first;
1057 wasp::HITNodeView view_root =
getRoot().getNodeView();
1060 for (
const auto & input_path : input_path_iter->second)
1063 wasp::SIRENInterpreter<> selector;
1064 if (!selector.parseString(input_path))
1066 wasp::SIRENResultSet<wasp::HITNodeView> results;
1067 std::size_t count = selector.evaluate(view_root, results);
1070 for (std::size_t i = 0; i < count; i++)
1071 if (results.adapted(i).type() == wasp::OBJECT && results.adapted(i).name() == val_string &&
1072 results.adapted(i).child_count_by_name(
"decl"))
1073 location_nodes.insert(results.adapted(i).first_child_by_name(
"decl"));
1084 for (
const auto & location_nodes_iter : location_nodes)
1087 auto location_uri = wasp::lsp::m_uri_prefix + location_nodes_iter.node_pool()->stream_name();
1090 defsOrRefsLocations.push_back(wasp::DataObject());
1091 wasp::DataObject * location = defsOrRefsLocations.back().to_object();
1092 pass &= wasp::lsp::buildLocationObject(*location,
1095 location_nodes_iter.line() - 1,
1096 location_nodes_iter.column() - 1,
1097 location_nodes_iter.last_line() - 1,
1098 location_nodes_iter.last_column());
1114 auto & root = *root_ptr;
1117 wasp::HITNodeView view_root = root.getNodeView();
1118 wasp::HITNodeView request_context =
1119 wasp::findNodeUnderLineColumn(view_root, line + 1, character + 1);
1122 if ((request_context.type() != wasp::DECL && request_context.type() != wasp::VALUE) ||
1123 !request_context.has_parent() ||
1124 (request_context.parent().type() != wasp::KEYED_VALUE &&
1125 request_context.parent().type() != wasp::ARRAY))
1129 std::string paramkey = request_context.parent().name();
1130 std::string paramval = request_context.last_as_string();
1133 wasp::HITNodeView object_context = request_context;
1134 while (object_context.type() != wasp::OBJECT && object_context.has_parent())
1135 object_context = object_context.parent();
1136 const std::string object_path = object_context.path();
1137 wasp::HITNodeView type_node = object_context.first_child_by_name(
"type");
1138 const std::string object_type =
1139 type_node.is_null() ?
"" : wasp::strip_quotes(hit::extractValue(type_node.data()));
1143 std::set<std::string> obj_act_tasks;
1147 if (request_context.type() == wasp::VALUE && paramkey ==
"type" && factory.
isRegistered(paramval))
1152 const std::string & moose_base = object_params.
getBase();
1153 for (
const auto & obj_act_task : obj_act_tasks)
1165 else if (request_context.type() == wasp::VALUE)
1167 std::map<std::string, std::string> options_and_descs;
1174 else if (valid_params.
have_parameter<std::vector<MooseEnum>>(paramkey))
1175 getEnumsAndDocs(valid_params.
get<std::vector<MooseEnum>>(paramkey)[0], options_and_descs);
1176 if (options_and_descs.count(paramval))
1177 display_text = options_and_descs.find(paramval)->second;
1181 else if (request_context.type() == wasp::DECL && valid_params.
getParametersList().count(paramkey))
1192 bool include_declaration)
1200 auto & root = *root_ptr;
1203 wasp::HITNodeView view_root = root.getNodeView();
1204 wasp::HITNodeView request_context =
1205 wasp::findNodeUnderLineColumn(view_root, line + 1, character + 1);
1208 if ((request_context.type() != wasp::DECL && request_context.type() != wasp::DOT_SLASH &&
1209 request_context.type() != wasp::LBRACKET && request_context.type() != wasp::RBRACKET) ||
1210 !request_context.has_parent() || request_context.parent().type() != wasp::OBJECT)
1214 const std::string & block_path = request_context.parent().path();
1215 const std::string & block_name = request_context.parent().name();
1221 const std::string & path = associated_types_iter.first;
1222 const std::string &
type = associated_types_iter.second;
1239 [](
const wasp::HITNodeView & l,
const wasp::HITNodeView & r)
1241 const std::string & l_file = l.node_pool()->stream_name();
1242 const std::string & r_file = r.node_pool()->stream_name();
1243 return (l_file < r_file || (l_file == r_file && l.line() < r.line()) ||
1244 (l_file == r_file && l.line() == r.line() && l.column() < r.column()));
1251 if (match_nodes.empty())
1255 if (include_declaration && request_context.parent().child_count_by_name(
"decl"))
1256 match_nodes.insert(request_context.parent().first_child_by_name(
"decl"));
1264 wasp::HITNodeView view_parent,
1265 const std::string & target_value,
1266 const std::set<std::string> & target_types)
1269 for (
const auto & view_child : view_parent)
1272 if (view_child.type() == wasp::VALUE && view_child.to_string() == target_value)
1275 wasp::HITNodeView object_context = view_child;
1276 while (object_context.type() != wasp::OBJECT && object_context.has_parent())
1277 object_context = object_context.parent();
1278 const std::string object_path = object_context.path();
1279 wasp::HITNodeView type_node = object_context.first_child_by_name(
"type");
1280 const std::string object_type =
1281 type_node.is_null() ?
"" : wasp::strip_quotes(hit::extractValue(type_node.data()));
1285 std::set<std::string> obj_act_tasks;
1289 std::string param_name = view_child.has_parent() ? view_child.parent().name() :
"";
1292 std::string dirty_type = valid_params.
type(param_name);
1294 pcrecpp::RE(
".+<([A-Za-z0-9_' ':]*)>.*").GlobalReplace(
"\\1", &clean_type);
1297 if (target_types.count(clean_type))
1298 match_nodes.insert(view_child);
1302 if (!view_child.is_leaf())
1313 std::string parse_file_path = document_path;
1314 pcrecpp::RE(
"(.*://)(.*)").Replace(
"\\2", &parse_file_path);
1318 wasp::DefaultHITInterpreter interpreter(input_errors);
1321 if (!interpreter.parseStream(input_stream, parse_file_path))
1325 if (interpreter.root().is_null())
1329 wasp::HITNodeView view_root = interpreter.root();
1330 int document_start_line = view_root.line() - 1;
1331 int document_start_char = view_root.column() - 1;
1332 int document_last_line = view_root.last_line() - 1;
1333 int document_last_char = view_root.last_column();
1337 std::size_t starting_line = view_root.line() - 1;
1338 std::string document_format =
formatDocument(view_root, starting_line, 0);
1341 formattingTextEdits.push_back(wasp::DataObject());
1342 wasp::DataObject * item = formattingTextEdits.back().to_object();
1343 bool pass = wasp::lsp::buildTextEditObject(*item,
1345 document_start_line,
1346 document_start_char,
1360 auto collapse_spaces = [](std::string string_copy)
1362 pcrecpp::RE(
"\\s+").Replace(
" ", &string_copy);
1367 std::string format_string;
1370 for (
const auto i :
make_range(parent.child_count()))
1373 wasp::HITNodeView child = parent.child_at(i);
1376 std::string blank = child.line() > prev_line + 1 ?
"\n" :
"";
1379 if (child.type() == wasp::FILE)
1380 format_string += blank + newline_indent +
MooseUtils::trim(collapse_spaces(child.data()));
1383 else if (child.type() == wasp::COMMENT)
1384 format_string += (child.line() == prev_line ?
" " : blank + newline_indent) +
1388 else if (child.type() == wasp::OBJECT)
1389 format_string += blank + newline_indent +
"[" + child.name() +
"]" +
1390 formatDocument(child, prev_line, level + 1) + newline_indent +
"[]";
1393 else if (child.type() == wasp::KEYED_VALUE || child.type() == wasp::ARRAY)
1395 const std::string prefix = newline_indent + child.name() +
" = ";
1397 const std::string render_val = hit::extractValue(child.data());
1398 std::size_t val_column = child.child_count() > 2 ? child.child_at(2).column() : 0;
1399 std::size_t prefix_len = prefix.size() - 1;
1401 format_string += blank + prefix + hit::formatValue(render_val, val_column, prefix_len);
1405 prev_line = child.last_line();
1409 return level != 0 ? format_string : format_string.substr(1);
1419 auto & root = *root_ptr;
1421 wasp::HITNodeView view_root = root.getNodeView();
1426 for (
const auto i :
make_range(view_root.child_count()))
1429 wasp::HITNodeView view_child = view_root.child_at(i);
1432 std::string
name = view_child.name();
1433 int line = view_child.line() - 1;
1434 int column = view_child.column() - 1;
1435 int last_line = view_child.last_line() - 1;
1436 int last_column = view_child.last_column();
1438 std::string detail =
1439 !view_child.first_child_by_name(
"type").is_null()
1440 ? wasp::strip_quotes(hit::extractValue(view_child.first_child_by_name(
"type").data()))
1444 documentSymbols.push_back(wasp::DataObject());
1445 wasp::DataObject * data_child = documentSymbols.back().to_object();
1446 pass &= wasp::lsp::buildDocumentSymbolObject(*data_child,
1470 wasp::DataObject & data_parent)
1473 if (wasp::is_nested_file(view_parent))
1479 for (
const auto i :
make_range(view_parent.child_count()))
1482 wasp::HITNodeView view_child = view_parent.child_at(i);
1485 std::string
name = view_child.name();
1486 int line = view_child.line() - 1;
1487 int column = view_child.column() - 1;
1488 int last_line = view_child.last_line() - 1;
1489 int last_column = view_child.last_column();
1491 std::string detail =
1492 !view_child.first_child_by_name(
"type").is_null()
1493 ? wasp::strip_quotes(hit::extractValue(view_child.first_child_by_name(
"type").data()))
1497 wasp::DataObject & data_child = wasp::lsp::addDocumentSymbolChild(data_parent);
1498 pass &= wasp::lsp::buildDocumentSymbolObject(data_child,
1522 const std::string & param_name,
1523 const std::string & clean_type,
1530 return wasp::lsp::m_comp_kind_event;
1531 else if (param_name ==
"active" || param_name ==
"inactive")
1532 return wasp::lsp::m_comp_kind_class;
1533 else if (clean_type ==
"bool")
1534 return wasp::lsp::m_comp_kind_interface;
1539 return is_param ? wasp::lsp::m_comp_kind_enum : wasp::lsp::m_comp_kind_enum_member;
1540 else if (param_name ==
"type")
1541 return wasp::lsp::m_comp_kind_type_param;
1542 else if (std::find_if(associated_types.begin(),
1543 associated_types.end(),
1544 [&](
const auto & entry)
1545 {
return entry.second == clean_type; }) != associated_types.end())
1546 return wasp::lsp::m_comp_kind_reference;
1548 return is_param ? wasp::lsp::m_comp_kind_keyword : wasp::lsp::m_comp_kind_value;
1555 auto is_boolean = [](wasp::HITNodeView symbol_node)
1559 return (iss >> std::boolalpha >>
convert && !iss.fail());
1561 auto is_number = [](wasp::HITNodeView symbol_node)
1564 std::istringstream iss(symbol_node.last_as_string());
1565 return (iss >>
convert && iss.eof());
1569 if (symbol_node.type() == wasp::OBJECT)
1570 return wasp::lsp::m_symbol_kind_struct;
1571 else if (symbol_node.type() == wasp::FILE)
1572 return wasp::lsp::m_symbol_kind_file;
1573 else if (symbol_node.type() == wasp::ARRAY)
1574 return wasp::lsp::m_symbol_kind_array;
1575 else if (symbol_node.type() == wasp::KEYED_VALUE && symbol_node.name() == std::string(
"type"))
1576 return wasp::lsp::m_symbol_kind_type_param;
1577 else if (symbol_node.type() == wasp::KEYED_VALUE && is_boolean(symbol_node))
1578 return wasp::lsp::m_symbol_kind_boolean;
1579 else if (symbol_node.type() == wasp::KEYED_VALUE && is_number(symbol_node))
1580 return wasp::lsp::m_symbol_kind_number;
1581 else if (symbol_node.type() == wasp::KEYED_VALUE)
1582 return wasp::lsp::m_symbol_kind_key;
1583 else if (symbol_node.type() == wasp::VALUE)
1584 return wasp::lsp::m_symbol_kind_string;
1586 return wasp::lsp::m_symbol_kind_property;
1591 const std::string & subblock_type,
1592 const std::set<std::string> & existing_params,
1593 const std::string & indent_spaces)
1597 std::set<std::string> obj_act_tasks;
1601 std::string required_param_text;
1602 std::size_t param_index = 1;
1603 for (
const auto & valid_params_iter : valid_params)
1606 const std::string & param_name = valid_params_iter.first;
1607 if (!valid_params.isParamDeprecated(param_name) && !valid_params.isPrivate(param_name) &&
1608 !valid_params.isParamValid(param_name) && valid_params.isParamRequired(param_name) &&
1609 !existing_params.count(param_name))
1611 std::string tab_stop = client_snippet_support ?
"$" + std::to_string(param_index++) :
"";
1612 required_param_text +=
"\n" + indent_spaces + param_name +
" = " + tab_stop;
1616 return required_param_text;
1621 const std::string & extensionMethod,
1627 if (extensionMethod ==
"plotting")
1639 auto & root = *root_ptr;
1642 wasp::HITNodeView view_root = root.getNodeView();
1643 wasp::HITNodeView request_context =
1644 wasp::findNodeUnderLineColumn(view_root, line + 1, character + 1);
1647 wasp::HITNodeView object_context = request_context;
1648 while (object_context.type() != wasp::OBJECT && object_context.has_parent())
1649 object_context = object_context.parent();
1650 const std::string & object_name = object_context.name();
1651 wasp::HITNodeView type_node = object_context.first_child_by_name(
"type");
1652 const std::string & object_type =
1653 type_node.is_null() ?
"" : wasp::strip_quotes(hit::extractValue(type_node.data()));
1661 if (!
problem->hasFunction(object_name))
1665 const auto * pw_func =
dynamic_cast<const PiecewiseBase *
>(&
problem->getFunction(object_name));
1670 if (pw_func->functionSize() == 0)
1674 std::vector<double> graph_keys, graph_vals;
1675 for (std::size_t i = 0; i < pw_func->functionSize(); i++)
1677 graph_keys.push_back(pw_func->domain(i));
1678 graph_vals.push_back(pw_func->range(i));
1682 std::string plot_title = object_name +
" " + object_type +
" Function";
1683 wasp::CustomPlot plot_object;
1685 plottingResponses.push_back(wasp::serializeCustomPlot(plot_object));
1692 const std::string & plot_title,
1693 const std::vector<double> & graph_keys,
1694 const std::vector<double> & graph_vals)
1697 double min_key = *std::min_element(graph_keys.begin(), graph_keys.end());
1698 double max_key = *std::max_element(graph_keys.begin(), graph_keys.end());
1699 double min_val = *std::min_element(graph_vals.begin(), graph_vals.end());
1700 double max_val = *std::max_element(graph_vals.begin(), graph_vals.end());
1703 double pad_factor = 0.05;
1704 double pad_x_axis = (max_key - min_key) * pad_factor;
1705 double pad_y_axis = (max_val - min_val) * pad_factor;
1706 min_key -= pad_x_axis;
1707 max_key += pad_x_axis;
1708 min_val -= pad_y_axis;
1709 max_val += pad_y_axis;
1712 plot_object.title().text(plot_title);
1713 plot_object.title().font().pointsize(18);
1714 plot_object.title().visible(
true);
1715 plot_object.legend().visible(
false);
1718 plot_object.x1Axis().label(
"abscissa values");
1719 plot_object.x1Axis().rangeMin(min_key);
1720 plot_object.x1Axis().rangeMax(max_key);
1721 plot_object.x1Axis().scaleType(wasp::CustomPlot::stLinear);
1722 plot_object.x1Axis().labelType(wasp::CustomPlot::ltNumber);
1723 plot_object.x1Axis().labelFont().pointsize(18);
1724 plot_object.x1Axis().tickLabelFont().pointsize(16);
1727 plot_object.y1Axis().label(
"ordinate values");
1728 plot_object.y1Axis().rangeMin(min_val);
1729 plot_object.y1Axis().rangeMax(max_val);
1730 plot_object.y1Axis().scaleType(wasp::CustomPlot::stLinear);
1731 plot_object.y1Axis().labelType(wasp::CustomPlot::ltNumber);
1732 plot_object.y1Axis().labelFont().pointsize(18);
1733 plot_object.y1Axis().tickLabelFont().pointsize(16);
1736 auto line_graph = std::make_shared<wasp::CustomPlot::Graph>();
1737 line_graph->keys() = graph_keys;
1738 line_graph->values() = graph_vals;
1739 line_graph->scatterShape(wasp::CustomPlot::ssDisc);
1740 plot_object.series().push_back(line_graph);
1750 mooseAssert(&app_ptr->parser() == parser_ptr,
"App should have this parser");
1752 if (
const auto root_ptr = parser_ptr->queryRoot())
1753 if (!root_ptr->getNodeView().is_null())
1763 return it ==
_check_state.end() ? nullptr : &it->second;
1776 return state ? state->parser.get() :
nullptr;
1782 return const_cast<Parser *
>(std::as_const(*this).queryCheckParser());
1789 return state->app.get();
1796 return const_cast<MooseApp *
>(std::as_const(*this).queryCheckApp());
1804 const auto & text_vector = parser->getInputText();
1805 mooseAssert(text_vector.size() == 1,
"Unexpected size");
1806 return &text_vector[0];
1816 auto & app = *app_ptr;
1818 mooseAssert(&app.parser() ==
queryCheckParser(),
"Parser should be the app's parser");
1821 mooseError(
"MooseServer::getCheckApp(): App not available");
1829 mooseError(
"MooseServer::getRoot(): Root not available");
1837 mooseError(
"MooseServer::getDocumentText(): Document text not available");
int getDocumentSymbolKind(wasp::HITNodeView symbol_node)
Get document symbol kind value that client may use for outline icon.
const std::multimap< std::string, std::string > & getAssociatedTypes() const
Get a multimap of registered associations of syntax with type.
std::pair< std::multimap< std::string, ActionInfo >::const_iterator, std::multimap< std::string, ActionInfo >::const_iterator > getActions(const std::string &syntax) const
Returns a pair of multimap iterators to all the ActionInfo objects associated with a given piece of s...
std::map< std::string, std::set< std::string > > _type_to_input_paths
_type_to_input_paths - map of parameter types to lookup paths
Function base which provides a piecewise approximation to a specified (x,y) point data set...
A MultiMooseEnum object to hold "execute_on" flags.
bool isRegistered(const std::string &obj_name) const
Returns a Boolean indicating whether an object type has been registered.
void getInputLookupDefinitionNodes(SortedLocationNodes &location_nodes, const std::string &clean_type, const std::string &val_string)
Get set of nodes from associated path lookups matching value string.
const std::multimap< std::string, ActionInfo > & getAssociatedActions() const
Return all Syntax to Action associations.
std::string getRequiredParamsText(const std::string &subblock_path, const std::string &subblock_type, const std::set< std::string > &existing_params, const std::string &indent_spaces)
Get required parameter completion text list for given subblock path.
std::map< std::string, std::set< std::string > > _input_path_to_types
_type_to_input_paths - map of lookup paths to parameter types
Generic factory class for build all sorts of objects.
const std::string & getDocumentText() const
InputParameters getValidParams(const std::string &name)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
std::shared_ptr< CommandLine > commandLine() const
Get the command line.
MooseServer(MooseApp &moose_app)
static const std::string main_app_name
The name for the "main" moose application.
void buildLineGraphPlot(wasp::CustomPlot &plot_object, const std::string &plot_title, const std::vector< double > &graph_keys, const std::vector< double > &graph_vals)
Build CustomPlot graph with provided keys, values, and plot title.
bool addValuesToList(wasp::DataArray &completionItems, const InputParameters &valid_params, const std::set< std::string > &existing_params, const std::set< std::string > &existing_subblocks, const std::string ¶m_name, const std::set< std::string > &obj_act_tasks, const std::string &object_path, int replace_line_beg, int replace_char_beg, int replace_line_end, int replace_char_end)
Add parameter values to completion list for request line and column.
bool gatherDocumentSymbols(wasp::DataArray &documentSymbols)
Gather document symbols - specific to this server implemention.
bool addParametersToList(wasp::DataArray &completionItems, const InputParameters &valid_params, const std::set< std::string > &existing_params, int replace_line_beg, int replace_char_beg, int replace_line_end, int replace_char_end, const std::string &filtering_prefix)
Add parameters that were previously gathered to list for completion.
const InputParameters & parameters() const
Get the parameters of the object.
std::set< std::string > getTasksByAction(const std::string &action) const
virtual void run()
Run the application.
static InputParameters validParams()
Parameters that are processed directly by the Parser and are valid anywhere in the input...
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
Base class for MOOSE-based applications.
const hit::Node & getRoot() const
const std::string * queryDocumentText() const
Syntax & syntax()
Returns a writable reference to the syntax object.
bool getHoverDisplayText(std::string &display_text, int line, int character)
Get hover display text - logic specific to this server implemention.
ActionFactory & getActionFactory()
Retrieve a writable reference to the ActionFactory associated with this App.
bool updateDocumentTextChanges(const std::string &replacement_text, int start_line, int start_character, int end_line, int end_character, int range_length)
Update document text changes - specific to this server implemention.
const CheckState * queryCheckState() const
FileLineInfo getLineInfo(const std::string &name) const
Gets file and line information where an object was initially registered.
Factory & getFactory()
Retrieve a writable reference to the Factory associated with this App.
std::shared_ptr< FEProblemBase > & problemBase()
bool convert(const std::string &str, T &value, const bool throw_on_failure)
Takes the string representation of a value and converts it to the value.
std::set< wasp::HITNodeView, std::function< bool(const wasp::HITNodeView &, const wasp::HITNodeView &)> > SortedLocationNodes
SortedLocationNodes - type alias for set of nodes sorted by location.
void getObjectParameters(InputParameters &valid_params, std::string object_type, const std::set< std::string > &obj_act_tasks)
Get all object parameters using requested object path to collection.
static std::unique_ptr< MooseApp > create(const std::string &app_type, const std::vector< std::string > &cli_args={})
Create an app with no input and command line arguments.
void getNodesByValueAndTypes(SortedLocationNodes &match_nodes, wasp::HITNodeView view_parent, const std::string &target_value, const std::set< std::string > &target_types)
Recursively walk input to gather all nodes matching value and types.
static std::string buildOutputString(const std::iterator_traits< InputParameters::iterator >::value_type &p)
const std::string & name() const
Get the name of the class.
const Parser * queryCheckParser() const
void remove(std::string_view)
Specialized factory for generic Action System objects.
bool checkFileReadable(const std::string &filename, bool check_line_endings=false, bool throw_on_unreadable=true, bool check_for_git_lfs_pointer=true)
Checks to see if a file is readable (exists and permissions)
std::string trim(const std::string &str, const std::string &white_space=" \\\)
Standard scripting language trim function.
const std::string & type() const
Get the type of this class.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
const MooseApp * queryCheckApp() const
ActionWarehouse & actionWarehouse()
Return a writable reference to the ActionWarehouse associated with this app.
void getAllValidParameters(InputParameters &valid_params, const std::string &object_path, const std::string &object_type, std::set< std::string > &obj_act_tasks)
Get all global parameters, action parameters, and object parameters.
virtual Problem & problem()
Deprecated: Return a reference to this Executioner's Problem instance.
const auto & registeredObjects() const
Returns a reference to the map from names to RegistryEntryBase pointers.
Helper for storing the state for a single document.
std::string toLower(std::string name)
Convert supplied string to lower case.
bool gatherDocumentFormattingTextEdits(wasp::DataArray &formattingTextEdits, int tab_size, bool insert_spaces)
Gather formatting text edits - specific to this server implemention.
static std::string basicCppType(const std::string &cpp_type)
Utilities for making sense of c++ types.
Holds file and line information.
static AppFactory & instance()
Get the instance of the AppFactory.
std::string isAssociated(const std::string &real_id, bool *is_parent, const std::map< std::string, std::set< std::string >> &alt_map={}) const
Method for determining whether a piece of syntax is associated with an Action an optional syntax map ...
void getActionParameters(InputParameters &valid_params, const std::string &object_path, std::set< std::string > &obj_act_tasks)
Get all action parameters using requested object path to collection.
bool traverseParseTreeAndFillSymbols(wasp::HITNodeView view_parent, wasp::DataObject &data_parent)
Recursively fill document symbols from the given node.
bool gatherExtensionResponses(wasp::DataArray &extensionResponses, const std::string &extensionMethod, int line, int character)
Gather extension responses - specific to this server implemention.
MooseApp & _moose_app
_moose_app - reference to parent application that owns this server
bool addSubblocksToList(wasp::DataArray &completionItems, const std::string &object_path, int replace_line_beg, int replace_char_beg, int replace_line_end, int replace_char_end, const std::string &filtering_prefix, bool request_on_block_decl)
Add subblocks to completion list for request path, line, and column.
bool gatherDocumentCompletionItems(wasp::DataArray &completionItems, bool &is_incomplete, int line, int character)
Gather document completion items - specific to this server implemention.
bool gatherDocumentReferencesLocations(wasp::DataArray &referencesLocations, int line, int character, bool include_declaration)
Gather references locations - specific to this server implemention.
Scoped helper for setting Moose::_throw_on_error during this scope.
IntRange< T > make_range(T beg, T end)
Holding syntax for parsing input files.
std::size_t _formatting_tab_size
_formatting_tab_size - number of indent spaces for formatting
bool gatherPlottingResponses(wasp::DataArray &plottingResponses, int line, int character)
Build CustomPlot extension responses when method name is plotting.
bool parseDocumentForDiagnostics(wasp::DataArray &diagnosticsList)
Parse document for diagnostics - specific to this server implemention.
bool verifyMooseObjectTask(const std::string &base, const std::string &task) const
Returns a Boolean indicating whether a task is associated with on of the MOOSE pluggable systems (BAS...
bool gatherDocumentDefinitionLocations(wasp::DataArray &definitionLocations, int line, int character)
Gather definition locations - specific to this server implemention.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type...
bool addLocationNodesToList(wasp::DataArray &defsOrRefsLocations, const SortedLocationNodes &location_nodes)
Add set of nodes sorted by location to definition or reference list.
std::map< std::string, std::set< std::string > > _syntax_to_subblocks
_syntax_to_subblocks - map of syntax paths to valid subblocks
Exception to be thrown whenever we have _throw_on_error set and a mooseError() is emitted...
int getCompletionItemKind(const InputParameters &valid_params, const std::string ¶m_name, const std::string &clean_type, bool is_param)
Get completion item kind value that client may use for icon in list.
const std::shared_ptr< libMesh::Parallel::Communicator > getCommunicator() const
void getEnumsAndDocs(MooseEnumType &moose_enum_param, std::map< std::string, std::string > &options_and_descs)
Fill map of all options and descriptions if parameter is moose enum.
void ErrorVector unsigned int
Class for parsing input files.
std::map< std::string, CheckState > _check_state
_check_state - map from document paths to state (parser, app, text)
const hit::Node * queryRoot() const
std::string formatDocument(wasp::HITNodeView parent, std::size_t &prev_line, std::size_t level)
Recursively walk down whole nodeview tree while formatting document.
void escape(std::string &str)
This function will escape all of the standard C++ escape characters so that they can be printed...
void getExistingInput(wasp::HITNodeView parent_node, std::set< std::string > &existing_params, std::set< std::string > &existing_subblocks)
Get names of parameters and subblocks specified in given input node.
std::string prettyCppType(const std::string &cpp_type)