27 #include "wasphit/HITInterpreter.h" 28 #include "waspcore/utils.h" 36 : _moose_app(moose_app),
37 _connection(
std::make_shared<wasp::lsp::IOStreamConnection>(this)),
38 _formatting_tab_size(0)
41 server_capabilities[wasp::lsp::m_text_doc_sync] = wasp::DataObject();
42 server_capabilities[wasp::lsp::m_text_doc_sync][wasp::lsp::m_open_close] =
true;
43 server_capabilities[wasp::lsp::m_text_doc_sync][wasp::lsp::m_change] = wasp::lsp::m_change_full;
46 server_capabilities[wasp::lsp::m_completion_provider] = wasp::DataObject();
47 server_capabilities[wasp::lsp::m_completion_provider][wasp::lsp::m_resolve_provider] =
false;
48 server_capabilities[wasp::lsp::m_doc_symbol_provider] =
true;
49 server_capabilities[wasp::lsp::m_doc_format_provider] =
true;
50 server_capabilities[wasp::lsp::m_definition_provider] =
true;
51 server_capabilities[wasp::lsp::m_references_provider] =
true;
52 server_capabilities[wasp::lsp::m_hover_provider] =
true;
63 std::string parse_file_path = document_path;
64 pcrecpp::RE(
"(.*://)(.*)").Replace(
"\\2", &parse_file_path);
69 const auto diagnostic = [
this, &diagnosticsList, &pass](
const std::string & message,
71 const int start_column,
72 const std::optional<int> end_line = {},
73 const std::optional<int> end_column = {})
75 diagnosticsList.push_back(wasp::DataObject());
76 auto & diagnostic = *diagnosticsList.back().to_object();
77 pass &= wasp::lsp::buildDiagnosticObject(diagnostic,
81 end_line ? *end_line : start_line,
82 end_column ? *end_column : start_column,
90 const auto zero_line_diagnostic = [&diagnostic](
const std::string & message)
91 { diagnostic(message, 0, 0); };
94 const auto hit_node_diagnostic = [&zero_line_diagnostic, &diagnostic, &parse_file_path](
95 const hit::Node *
const node,
const std::string & message)
98 if (!node || node->isRoot() || node->filename() != parse_file_path || !node->line() ||
100 zero_line_diagnostic(message);
103 diagnostic(message, node->line() - 1, node->column() - 1);
107 const auto hit_error_message_diagnostic =
108 [&diagnostic, &zero_line_diagnostic, &parse_file_path](
const hit::ErrorMessage &
err)
114 if (*
err.filename == parse_file_path)
117 if (
err.lineinfo &&
err.lineinfo->start_line &&
err.lineinfo->start_column &&
118 err.lineinfo->end_line &&
err.lineinfo->end_column)
120 diagnostic(
err.message,
121 err.lineinfo->start_line - 1,
122 err.lineinfo->start_column - 1,
123 err.lineinfo->end_line - 1,
124 err.lineinfo->end_column - 1);
134 zero_line_diagnostic(
err.prefixed_message);
140 const auto try_catch = [&hit_error_message_diagnostic,
141 &hit_node_diagnostic,
142 &zero_line_diagnostic](
const auto & action) ->
bool 157 for (
const auto & error_message :
err.error_messages)
158 hit_error_message_diagnostic(error_message);
164 hit_node_diagnostic(
err.getNode(),
err.what());
167 catch (std::exception &
err)
169 zero_line_diagnostic(
err.what());
178 if (command_line->hasArgument(
"--language-server"))
179 command_line->removeArgument(
"--language-server");
180 command_line->addArgument(
"--check-input");
181 command_line->addArgument(
"--error-unused");
182 command_line->addArgument(
"--error");
183 command_line->addArgument(
"--color=off");
184 command_line->addArgument(
"--disable-perf-graph-live");
185 command_line->parse();
188 auto parser = std::make_shared<Parser>(parse_file_path, document_text);
189 mooseAssert(parser->getInputFileNames()[0] == parse_file_path,
"Should be consistent");
190 parser->setCommandLineParams(command_line->buildHitParams());
191 parser->setThrowOnError(
true);
194 const bool parse_success = try_catch([&parser]() { parser->parse(); });
198 if (
auto parser_root_ptr = parser->queryRoot())
199 if (!parser_root_ptr->getNodeView().is_null())
201 auto it_inserted_pair =
_check_state.emplace(document_path, parser);
202 mooseAssert(it_inserted_pair.second,
"Should not already exist");
203 state = &it_inserted_pair.first->second;
213 app_params.
set<std::shared_ptr<Parser>>(
"_parser") = parser;
214 app_params.
set<std::shared_ptr<CommandLine>>(
"_command_line") = std::move(command_line);
217 std::unique_ptr<MooseApp> app =
nullptr;
218 const auto do_build_app = [
this, &app_params, &app]()
225 if (!try_catch(do_build_app))
233 state->app = std::move(app);
237 if (!try_catch(do_run_app))
252 document_text = replacement_text;
259 bool & is_incomplete,
267 return addSubblocksToList(completionItems,
"/", line, character, line, character,
"",
false);
268 auto & root = *root_ptr;
271 auto is_request_in_open_block = [](wasp::HITNodeView request_context) {
272 return request_context.type() == wasp::OBJECT || request_context.type() == wasp::DOCUMENT_ROOT;
274 auto is_request_on_param_decl = [](wasp::HITNodeView request_context)
276 return request_context.type() == wasp::DECL && request_context.has_parent() &&
277 (request_context.parent().type() == wasp::KEYED_VALUE ||
278 request_context.parent().type() == wasp::ARRAY);
280 auto is_request_on_block_decl = [](wasp::HITNodeView request_context)
282 return request_context.type() == wasp::DECL && request_context.has_parent() &&
283 request_context.parent().type() == wasp::OBJECT;
287 wasp::HITNodeView view_root = root.getNodeView();
288 wasp::HITNodeView request_context;
291 if (line + 1 < (
int)view_root.last_line() ||
292 (line + 1 == (
int)view_root.last_line() && character <= (
int)view_root.last_column()))
293 request_context = wasp::findNodeUnderLineColumn(view_root, line + 1, character + 1);
299 wasp::findNodeUnderLineColumn(view_root, view_root.last_line(), view_root.last_column());
302 wasp::HITNodeView object_context = request_context;
303 while (object_context.type() != wasp::OBJECT && object_context.has_parent())
304 object_context = object_context.parent();
305 if (request_context.type() == wasp::OBJECT_TERM && object_context.has_parent())
306 object_context = object_context.parent();
307 request_context = object_context;
311 if (is_request_in_open_block(request_context))
313 wasp::HITNodeView backup_context = request_context;
314 for (
int backup_char = character; backup_context == request_context && --backup_char > 0;)
315 backup_context = wasp::findNodeUnderLineColumn(request_context, line + 1, backup_char + 1);
316 if (backup_context.type() == wasp::ASSIGN || backup_context.type() == wasp::OVERRIDE_ASSIGN)
317 request_context = backup_context;
321 int replace_line_beg = line;
322 int replace_char_beg = character;
323 int replace_line_end = line;
324 int replace_char_end = character;
325 std::string filtering_prefix;
326 if (request_context.type() == wasp::DECL || request_context.type() == wasp::VALUE)
329 replace_line_beg = request_context.line() - 1;
330 replace_char_beg = request_context.column() - 1;
331 replace_line_end = request_context.last_line() - 1;
332 replace_char_end = request_context.last_column();
333 filtering_prefix = request_context.data();
336 if (is_request_on_block_decl(request_context) && filtering_prefix.empty())
344 const auto & parent_name = request_context.has_parent() ? request_context.parent().name() :
"";
347 wasp::HITNodeView object_context = request_context;
348 while (object_context.type() != wasp::OBJECT && object_context.has_parent())
349 object_context = object_context.parent();
350 if (is_request_on_block_decl(request_context))
351 object_context = object_context.parent();
352 const std::string & object_path = object_context.path();
353 wasp::HITNodeView type_node = object_context.first_child_by_name(
"type");
354 const std::string & object_type =
355 type_node.is_null() ?
"" : wasp::strip_quotes(hit::extractValue(type_node.data()));
358 std::set<std::string> existing_params, existing_subblocks;
365 std::set<std::string> obj_act_tasks;
373 if (is_request_in_open_block(request_context) || is_request_on_param_decl(request_context))
384 if (is_request_in_open_block(request_context) || is_request_on_param_decl(request_context) ||
385 is_request_on_block_decl(request_context))
393 is_request_on_block_decl(request_context));
396 if ((request_context.type() == wasp::VALUE || request_context.type() == wasp::ASSIGN ||
397 request_context.type() == wasp::OVERRIDE_ASSIGN) &&
411 is_incomplete = !pass;
418 std::set<std::string> & existing_params,
419 std::set<std::string> & existing_subblocks)
422 for (
auto itr = parent_node.begin(); itr != parent_node.end(); itr.next())
424 auto child_node = itr.get();
427 if (child_node.type() == wasp::KEYED_VALUE || child_node.type() == wasp::ARRAY)
428 existing_params.insert(child_node.name());
429 else if (child_node.type() == wasp::OBJECT)
430 existing_subblocks.insert(child_node.name());
436 const std::string & object_path,
437 const std::string & object_type,
438 std::set<std::string> & obj_act_tasks)
448 const std::string & object_path,
449 std::set<std::string> & obj_act_tasks)
456 std::string registered_syntax = syntax.
isAssociated(object_path, &is_parent);
462 auto action_range = syntax.
getActions(registered_syntax);
465 for (
auto action_iter = action_range.first; action_iter != action_range.second; action_iter++)
467 const std::string & action_name = action_iter->second._action;
475 if (action_params.
get<
bool>(
"isObjectAction"))
477 std::set<std::string> tasks_by_actions = action_factory.
getTasksByAction(action_name);
478 obj_act_tasks.insert(tasks_by_actions.begin(), tasks_by_actions.end());
482 action_params.
remove(
"isObjectAction");
486 valid_params += action_params;
493 std::string object_type,
494 const std::set<std::string> & obj_act_tasks)
500 if (object_type.empty() && valid_params.
have_parameter<std::string>(
"type") &&
501 !valid_params.
get<std::string>(
"type").empty())
503 object_type = valid_params.
get<std::string>(
"type");
518 const std::string & moose_base = object_params.
getBase();
520 for (
const auto & obj_act_task : obj_act_tasks)
525 valid_params += object_params;
533 if (valid_params.
have_parameter<std::vector<std::string>>(
"_object_params_set_by_action"))
535 auto names = valid_params.
get<std::vector<std::string>>(
"_object_params_set_by_action");
536 for (
const auto &
name : names)
540 valid_params.
remove(
"_object_params_set_by_action");
547 const std::set<std::string> & existing_params,
548 int replace_line_beg,
549 int replace_char_beg,
550 int replace_line_end,
551 int replace_char_end,
552 const std::string & filtering_prefix)
557 for (
const auto & valid_params_iter : valid_params)
559 const std::string & param_name = valid_params_iter.first;
560 bool deprecated = valid_params.isParamDeprecated(param_name);
561 bool is_private = valid_params.isPrivate(param_name);
564 if (deprecated || is_private || existing_params.count(param_name))
568 if (param_name.rfind(filtering_prefix, 0) != 0)
572 std::string dirty_type = valid_params.type(param_name);
575 std::string doc_string = valid_params.getDocString(param_name);
579 bool is_array = basic_type.compare(0, 6,
"Array:") == 0;
582 pcrecpp::RE(
"(Array:)*(.*)").GlobalReplace(
"\\2", &basic_type);
585 pcrecpp::RE(
".+<([A-Za-z0-9_' ':]*)>.*").GlobalReplace(
"\\1", &clean_type);
591 std::string default_value;
594 if (valid_params.isParamValid(param_name))
601 else if (valid_params.hasDefaultCoupledValue(param_name))
603 std::ostringstream oss;
604 oss << valid_params.defaultCoupledValue(param_name);
605 default_value = oss.str();
609 if (basic_type ==
"Boolean" && default_value ==
"1")
610 default_value =
"true";
611 else if (basic_type ==
"Boolean" && default_value ==
"0")
612 default_value =
"false";
615 std::string array_quote = is_array && !default_value.empty() ?
"'" :
"";
619 std::string insert_text;
620 if (client_snippet_support && !default_value.empty())
622 text_format = wasp::lsp::m_text_format_snippet;
623 insert_text = param_name +
" = " + array_quote +
"${1:" + default_value +
"}" + array_quote;
627 text_format = wasp::lsp::m_text_format_plaintext;
628 insert_text = param_name +
" = " + array_quote + default_value + array_quote;
633 completionItems.push_back(wasp::DataObject());
634 wasp::DataObject * item = completionItems.back().to_object();
635 pass &= wasp::lsp::buildCompletionObject(*item,
656 const std::string & object_path,
657 int replace_line_beg,
658 int replace_char_beg,
659 int replace_line_end,
660 int replace_char_end,
661 const std::string & filtering_prefix,
662 bool request_on_block_decl)
667 std::set<std::string> syntax_paths_processed;
674 std::string syntax_path =
"/" + syntax_path_iter.first;
677 if (!syntax_paths_processed.insert(syntax_path).second)
681 for (std::size_t last_sep; (last_sep = syntax_path.find_last_of(
"/")) != std::string::npos;)
683 std::string subblock_name = syntax_path.substr(last_sep + 1);
684 syntax_path = syntax_path.substr(0, last_sep);
696 if (!registered_syntax.empty() || object_path ==
"/")
699 int text_format = client_snippet_support ? wasp::lsp::m_text_format_snippet
700 : wasp::lsp::m_text_format_plaintext;
705 if (subblock_name !=
"*" && subblock_name.rfind(filtering_prefix, 0) != 0)
708 std::string doc_string;
709 std::string insert_text;
713 const std::string full_block_path = object_path +
"/" + subblock_name;
717 if (subblock_name ==
"*")
719 doc_string =
"custom user named block";
720 insert_text = (request_on_block_decl ?
"" :
"[") +
721 (filtering_prefix.size() ? filtering_prefix :
"block_name") +
"]" +
722 req_params +
"\n " + (client_snippet_support ?
"$0" :
"") +
"\n[]";
723 complete_kind = wasp::lsp::m_comp_kind_variable;
727 doc_string =
"application named block";
728 insert_text = (request_on_block_decl ?
"" :
"[") + subblock_name +
"]" + req_params +
729 "\n " + (client_snippet_support ?
"$0" :
"") +
"\n[]";
730 complete_kind = wasp::lsp::m_comp_kind_struct;
734 completionItems.push_back(wasp::DataObject());
735 wasp::DataObject * item = completionItems.back().to_object();
736 pass &= wasp::lsp::buildCompletionObject(*item,
759 const std::set<std::string> & existing_params,
760 const std::set<std::string> & existing_subblocks,
761 const std::string & param_name,
762 const std::set<std::string> & obj_act_tasks,
763 const std::string & object_path,
764 int replace_line_beg,
765 int replace_char_beg,
766 int replace_line_end,
767 int replace_char_end)
773 std::string dirty_type = valid_params.
type(param_name);
778 pcrecpp::RE(
"(Array:)*(.*)").GlobalReplace(
"\\2", &basic_type);
781 pcrecpp::RE(
".+<([A-Za-z0-9_' ':]*)>.*").GlobalReplace(
"\\1", &clean_type);
787 std::map<std::string, std::string> options_and_descs;
790 if (param_name ==
"active" || param_name ==
"inactive")
791 for (
const auto & subblock_name : existing_subblocks)
792 options_and_descs[subblock_name] =
"subblock name";
795 else if (basic_type ==
"Boolean")
797 options_and_descs[
"true"];
798 options_and_descs[
"false"];
808 else if (valid_params.
have_parameter<std::vector<MooseEnum>>(param_name))
809 getEnumsAndDocs(valid_params.
get<std::vector<MooseEnum>>(param_name)[0], options_and_descs);
812 else if (param_name ==
"type")
817 const std::string & object_name = objects_iter.first;
818 const InputParameters & object_params = objects_iter.second->buildParameters();
822 req_params += req_params.size() ?
"\n" + std::string(client_snippet_support ?
"$0" :
"") :
"";
827 const std::string & moose_base = object_params.
getBase();
830 for (
const auto & obj_act_task : obj_act_tasks)
836 options_and_descs[object_name + req_params] = type_description;
850 const std::string &
type = associated_types_iter.second;
851 const std::string & path = associated_types_iter.first;
861 wasp::HITNodeView view_root =
getRoot().getNodeView();
864 for (
const auto & input_path : input_path_iter->second)
867 wasp::SIRENInterpreter<> selector;
868 if (!selector.parseString(input_path))
870 wasp::SIRENResultSet<wasp::HITNodeView> results;
871 std::size_t count = selector.evaluate(view_root, results);
874 for (std::size_t i = 0; i < count; i++)
875 if (results.adapted(i).type() == wasp::OBJECT)
876 options_and_descs[results.adapted(i).name()] =
"from /" + input_path;
882 int text_format = client_snippet_support ? wasp::lsp::m_text_format_snippet
883 : wasp::lsp::m_text_format_plaintext;
888 for (
const auto & option_and_desc : options_and_descs)
890 const std::string & insert_text = option_and_desc.first;
891 const std::string & option_name = insert_text.substr(0, insert_text.find(
'\n'));
892 const std::string & description = option_and_desc.second;
895 completionItems.push_back(wasp::DataObject());
896 wasp::DataObject * item = completionItems.back().to_object();
897 pass &= wasp::lsp::buildCompletionObject(*item,
916 template <
typename MooseEnumType>
919 std::map<std::string, std::string> & options_and_descs)
922 const auto & enum_docs = moose_enum_param.getItemDocumentation();
925 for (
const auto & item : moose_enum_param.items())
926 options_and_descs[item.name()] = enum_docs.count(item) ? enum_docs.at(item) :
"";
940 auto & root = *root_ptr;
943 wasp::HITNodeView view_root = root.getNodeView();
944 wasp::HITNodeView request_context =
945 wasp::findNodeUnderLineColumn(view_root, line + 1, character + 1);
948 if (request_context.type() != wasp::VALUE)
952 std::string param_name = request_context.has_parent() ? request_context.parent().name() :
"";
953 std::string val_string = request_context.last_as_string();
956 if (param_name ==
"type" && factory.
isRegistered(val_string))
962 if (!file_line_info.
isValid() ||
967 auto location_uri = wasp::lsp::m_uri_prefix + file_line_info.
file();
970 definitionLocations.push_back(wasp::DataObject());
971 wasp::DataObject * location = definitionLocations.back().to_object();
972 return wasp::lsp::buildLocationObject(*location,
975 file_line_info.
line() - 1,
977 file_line_info.
line() - 1,
982 wasp::HITNodeView object_context = request_context;
983 while (object_context.type() != wasp::OBJECT && object_context.has_parent())
984 object_context = object_context.parent();
985 const std::string & object_path = object_context.path();
986 wasp::HITNodeView type_node = object_context.first_child_by_name(
"type");
987 const std::string & object_type =
988 type_node.is_null() ?
"" : wasp::strip_quotes(hit::extractValue(type_node.data()));
994 std::set<std::string> obj_act_tasks;
1001 [](
const wasp::HITNodeView & l,
const wasp::HITNodeView & r)
1003 const std::string & l_file = l.node_pool()->stream_name();
1004 const std::string & r_file = r.node_pool()->stream_name();
1005 return (l_file < r_file || (l_file == r_file && l.line() < r.line()) ||
1006 (l_file == r_file && l.line() == r.line() && l.column() < r.column()));
1010 for (
const auto & valid_params_iter : valid_params)
1012 if (valid_params_iter.first == param_name)
1015 std::string dirty_type = valid_params.type(param_name);
1017 pcrecpp::RE(
".+<([A-Za-z0-9_' ':]*)>.*").GlobalReplace(
"\\1", &clean_type);
1026 if (location_nodes.empty() && request_context.has_parent() &&
1027 request_context.parent().child_count_by_name(
"decl"))
1028 location_nodes.insert(request_context.parent().first_child_by_name(
"decl"));
1036 const std::string & clean_type,
1037 const std::string & val_string)
1046 const std::string &
type = associated_types_iter.second;
1047 const std::string & path = associated_types_iter.first;
1060 wasp::HITNodeView view_root =
getRoot().getNodeView();
1063 for (
const auto & input_path : input_path_iter->second)
1066 wasp::SIRENInterpreter<> selector;
1067 if (!selector.parseString(input_path))
1069 wasp::SIRENResultSet<wasp::HITNodeView> results;
1070 std::size_t count = selector.evaluate(view_root, results);
1073 for (std::size_t i = 0; i < count; i++)
1074 if (results.adapted(i).type() == wasp::OBJECT && results.adapted(i).name() == val_string &&
1075 results.adapted(i).child_count_by_name(
"decl"))
1076 location_nodes.insert(results.adapted(i).first_child_by_name(
"decl"));
1087 for (
const auto & location_nodes_iter : location_nodes)
1090 auto location_uri = wasp::lsp::m_uri_prefix + location_nodes_iter.node_pool()->stream_name();
1093 defsOrRefsLocations.push_back(wasp::DataObject());
1094 wasp::DataObject * location = defsOrRefsLocations.back().to_object();
1095 pass &= wasp::lsp::buildLocationObject(*location,
1098 location_nodes_iter.line() - 1,
1099 location_nodes_iter.column() - 1,
1100 location_nodes_iter.last_line() - 1,
1101 location_nodes_iter.last_column());
1117 auto & root = *root_ptr;
1120 wasp::HITNodeView view_root = root.getNodeView();
1121 wasp::HITNodeView request_context =
1122 wasp::findNodeUnderLineColumn(view_root, line + 1, character + 1);
1125 if ((request_context.type() != wasp::DECL && request_context.type() != wasp::VALUE) ||
1126 !request_context.has_parent() ||
1127 (request_context.parent().type() != wasp::KEYED_VALUE &&
1128 request_context.parent().type() != wasp::ARRAY))
1132 std::string paramkey = request_context.parent().name();
1133 std::string paramval = request_context.last_as_string();
1136 wasp::HITNodeView object_context = request_context;
1137 while (object_context.type() != wasp::OBJECT && object_context.has_parent())
1138 object_context = object_context.parent();
1139 const std::string object_path = object_context.path();
1140 wasp::HITNodeView type_node = object_context.first_child_by_name(
"type");
1141 const std::string object_type =
1142 type_node.is_null() ?
"" : wasp::strip_quotes(hit::extractValue(type_node.data()));
1146 std::set<std::string> obj_act_tasks;
1150 if (request_context.type() == wasp::VALUE && paramkey ==
"type" && factory.
isRegistered(paramval))
1155 const std::string & moose_base = object_params.
getBase();
1156 for (
const auto & obj_act_task : obj_act_tasks)
1168 else if (request_context.type() == wasp::VALUE)
1170 std::map<std::string, std::string> options_and_descs;
1177 else if (valid_params.
have_parameter<std::vector<MooseEnum>>(paramkey))
1178 getEnumsAndDocs(valid_params.
get<std::vector<MooseEnum>>(paramkey)[0], options_and_descs);
1179 if (options_and_descs.count(paramval))
1180 display_text = options_and_descs.find(paramval)->second;
1184 else if (request_context.type() == wasp::DECL && valid_params.
getParametersList().count(paramkey))
1195 bool include_declaration)
1203 auto & root = *root_ptr;
1206 wasp::HITNodeView view_root = root.getNodeView();
1207 wasp::HITNodeView request_context =
1208 wasp::findNodeUnderLineColumn(view_root, line + 1, character + 1);
1211 if ((request_context.type() != wasp::DECL && request_context.type() != wasp::DOT_SLASH &&
1212 request_context.type() != wasp::LBRACKET && request_context.type() != wasp::RBRACKET) ||
1213 !request_context.has_parent() || request_context.parent().type() != wasp::OBJECT)
1217 const std::string & block_path = request_context.parent().path();
1218 const std::string & block_name = request_context.parent().name();
1224 const std::string & path = associated_types_iter.first;
1225 const std::string &
type = associated_types_iter.second;
1242 [](
const wasp::HITNodeView & l,
const wasp::HITNodeView & r)
1244 const std::string & l_file = l.node_pool()->stream_name();
1245 const std::string & r_file = r.node_pool()->stream_name();
1246 return (l_file < r_file || (l_file == r_file && l.line() < r.line()) ||
1247 (l_file == r_file && l.line() == r.line() && l.column() < r.column()));
1254 if (match_nodes.empty())
1258 if (include_declaration && request_context.parent().child_count_by_name(
"decl"))
1259 match_nodes.insert(request_context.parent().first_child_by_name(
"decl"));
1267 wasp::HITNodeView view_parent,
1268 const std::string & target_value,
1269 const std::set<std::string> & target_types)
1272 for (
const auto & view_child : view_parent)
1275 if (view_child.type() == wasp::VALUE && view_child.to_string() == target_value)
1278 wasp::HITNodeView object_context = view_child;
1279 while (object_context.type() != wasp::OBJECT && object_context.has_parent())
1280 object_context = object_context.parent();
1281 const std::string object_path = object_context.path();
1282 wasp::HITNodeView type_node = object_context.first_child_by_name(
"type");
1283 const std::string object_type =
1284 type_node.is_null() ?
"" : wasp::strip_quotes(hit::extractValue(type_node.data()));
1288 std::set<std::string> obj_act_tasks;
1292 std::string param_name = view_child.has_parent() ? view_child.parent().name() :
"";
1295 std::string dirty_type = valid_params.
type(param_name);
1297 pcrecpp::RE(
".+<([A-Za-z0-9_' ':]*)>.*").GlobalReplace(
"\\1", &clean_type);
1300 if (target_types.count(clean_type))
1301 match_nodes.insert(view_child);
1305 if (!view_child.is_leaf())
1316 std::string parse_file_path = document_path;
1317 pcrecpp::RE(
"(.*://)(.*)").Replace(
"\\2", &parse_file_path);
1321 wasp::DefaultHITInterpreter interpreter(input_errors);
1324 if (!interpreter.parseStream(input_stream, parse_file_path))
1328 if (interpreter.root().is_null())
1332 wasp::HITNodeView view_root = interpreter.root();
1333 int document_start_line = view_root.line() - 1;
1334 int document_start_char = view_root.column() - 1;
1335 int document_last_line = view_root.last_line() - 1;
1336 int document_last_char = view_root.last_column();
1340 std::size_t starting_line = view_root.line() - 1;
1341 std::string document_format =
formatDocument(view_root, starting_line, 0);
1344 formattingTextEdits.push_back(wasp::DataObject());
1345 wasp::DataObject * item = formattingTextEdits.back().to_object();
1346 bool pass = wasp::lsp::buildTextEditObject(*item,
1348 document_start_line,
1349 document_start_char,
1363 auto collapse_spaces = [](std::string string_copy)
1365 pcrecpp::RE(
"\\s+").Replace(
" ", &string_copy);
1370 std::string format_string;
1373 for (
const auto i :
make_range(parent.child_count()))
1376 wasp::HITNodeView child = parent.child_at(i);
1379 std::string blank = child.line() > prev_line + 1 ?
"\n" :
"";
1382 if (child.type() == wasp::FILE)
1383 format_string += blank + newline_indent +
MooseUtils::trim(collapse_spaces(child.data()));
1386 else if (child.type() == wasp::COMMENT)
1387 format_string += (child.line() == prev_line ?
" " : blank + newline_indent) +
1391 else if (child.type() == wasp::OBJECT)
1392 format_string += blank + newline_indent +
"[" + child.name() +
"]" +
1393 formatDocument(child, prev_line, level + 1) + newline_indent +
"[]";
1396 else if (child.type() == wasp::KEYED_VALUE || child.type() == wasp::ARRAY)
1398 const std::string prefix = newline_indent + child.name() +
" = ";
1400 const std::string render_val = hit::extractValue(child.data());
1401 std::size_t val_column = child.child_count() > 2 ? child.child_at(2).column() : 0;
1402 std::size_t prefix_len = prefix.size() - 1;
1404 format_string += blank + prefix + hit::formatValue(render_val, val_column, prefix_len);
1408 prev_line = child.last_line();
1412 return level != 0 ? format_string : format_string.substr(1);
1422 auto & root = *root_ptr;
1424 wasp::HITNodeView view_root = root.getNodeView();
1429 for (
const auto i :
make_range(view_root.child_count()))
1432 wasp::HITNodeView view_child = view_root.child_at(i);
1435 std::string
name = view_child.name();
1436 int line = view_child.line() - 1;
1437 int column = view_child.column() - 1;
1438 int last_line = view_child.last_line() - 1;
1439 int last_column = view_child.last_column();
1441 std::string detail =
1442 !view_child.first_child_by_name(
"type").is_null()
1443 ? wasp::strip_quotes(hit::extractValue(view_child.first_child_by_name(
"type").data()))
1447 documentSymbols.push_back(wasp::DataObject());
1448 wasp::DataObject * data_child = documentSymbols.back().to_object();
1449 pass &= wasp::lsp::buildDocumentSymbolObject(*data_child,
1473 wasp::DataObject & data_parent)
1476 if (wasp::is_nested_file(view_parent))
1482 for (
const auto i :
make_range(view_parent.child_count()))
1485 wasp::HITNodeView view_child = view_parent.child_at(i);
1488 std::string
name = view_child.name();
1489 int line = view_child.line() - 1;
1490 int column = view_child.column() - 1;
1491 int last_line = view_child.last_line() - 1;
1492 int last_column = view_child.last_column();
1494 std::string detail =
1495 !view_child.first_child_by_name(
"type").is_null()
1496 ? wasp::strip_quotes(hit::extractValue(view_child.first_child_by_name(
"type").data()))
1500 wasp::DataObject & data_child = wasp::lsp::addDocumentSymbolChild(data_parent);
1501 pass &= wasp::lsp::buildDocumentSymbolObject(data_child,
1525 const std::string & param_name,
1526 const std::string & clean_type,
1533 return wasp::lsp::m_comp_kind_event;
1534 else if (param_name ==
"active" || param_name ==
"inactive")
1535 return wasp::lsp::m_comp_kind_class;
1536 else if (clean_type ==
"bool")
1537 return wasp::lsp::m_comp_kind_interface;
1542 return is_param ? wasp::lsp::m_comp_kind_enum : wasp::lsp::m_comp_kind_enum_member;
1543 else if (param_name ==
"type")
1544 return wasp::lsp::m_comp_kind_type_param;
1545 else if (std::find_if(associated_types.begin(),
1546 associated_types.end(),
1547 [&](
const auto & entry)
1548 {
return entry.second == clean_type; }) != associated_types.end())
1549 return wasp::lsp::m_comp_kind_reference;
1551 return is_param ? wasp::lsp::m_comp_kind_keyword : wasp::lsp::m_comp_kind_value;
1558 auto is_boolean = [](wasp::HITNodeView symbol_node)
1562 return (iss >> std::boolalpha >>
convert && !iss.fail());
1564 auto is_number = [](wasp::HITNodeView symbol_node)
1567 std::istringstream iss(symbol_node.last_as_string());
1568 return (iss >>
convert && iss.eof());
1572 if (symbol_node.type() == wasp::OBJECT)
1573 return wasp::lsp::m_symbol_kind_struct;
1574 else if (symbol_node.type() == wasp::FILE)
1575 return wasp::lsp::m_symbol_kind_file;
1576 else if (symbol_node.type() == wasp::ARRAY)
1577 return wasp::lsp::m_symbol_kind_array;
1578 else if (symbol_node.type() == wasp::KEYED_VALUE && symbol_node.name() == std::string(
"type"))
1579 return wasp::lsp::m_symbol_kind_type_param;
1580 else if (symbol_node.type() == wasp::KEYED_VALUE && is_boolean(symbol_node))
1581 return wasp::lsp::m_symbol_kind_boolean;
1582 else if (symbol_node.type() == wasp::KEYED_VALUE && is_number(symbol_node))
1583 return wasp::lsp::m_symbol_kind_number;
1584 else if (symbol_node.type() == wasp::KEYED_VALUE)
1585 return wasp::lsp::m_symbol_kind_key;
1586 else if (symbol_node.type() == wasp::VALUE)
1587 return wasp::lsp::m_symbol_kind_string;
1589 return wasp::lsp::m_symbol_kind_property;
1594 const std::string & subblock_type,
1595 const std::set<std::string> & existing_params,
1596 const std::string & indent_spaces)
1600 std::set<std::string> obj_act_tasks;
1604 std::string required_param_text;
1605 std::size_t param_index = 1;
1606 for (
const auto & valid_params_iter : valid_params)
1609 const std::string & param_name = valid_params_iter.first;
1610 if (!valid_params.isParamDeprecated(param_name) && !valid_params.isPrivate(param_name) &&
1611 !valid_params.isParamValid(param_name) && valid_params.isParamRequired(param_name) &&
1612 !existing_params.count(param_name))
1614 std::string tab_stop = client_snippet_support ?
"$" + std::to_string(param_index++) :
"";
1615 required_param_text +=
"\n" + indent_spaces + param_name +
" = " + tab_stop;
1619 return required_param_text;
1629 mooseAssert(&app_ptr->parser() == parser_ptr,
"App should have this parser");
1631 if (
const auto root_ptr = parser_ptr->queryRoot())
1632 if (!root_ptr->getNodeView().is_null())
1642 return it ==
_check_state.end() ? nullptr : &it->second;
1655 return state ? state->parser.get() :
nullptr;
1661 return const_cast<Parser *
>(std::as_const(*this).queryCheckParser());
1668 return state->app.get();
1675 return const_cast<MooseApp *
>(std::as_const(*this).queryCheckApp());
1683 const auto & text_vector = parser->getInputText();
1684 mooseAssert(text_vector.size() == 1,
"Unexpected size");
1685 return &text_vector[0];
1695 auto & app = *app_ptr;
1697 mooseAssert(&app.parser() ==
queryCheckParser(),
"Parser should be the app's parser");
1700 mooseError(
"MooseServer::getCheckApp(): App not available");
1708 mooseError(
"MooseServer::getRoot(): Root not available");
1716 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
T convert(const std::string &str, bool throw_on_failure=false)
convert takes a string representation of a number type and converts it to the number.
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.
std::string toLower(const std::string &name)
Convert supplied string to lower case.
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.
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::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
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.
const auto & registeredObjects() const
Returns a reference to the map from names to RegistryEntryBase pointers.
Helper for storing the state for a single document.
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.
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.
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 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.
bool _throw_on_error
Variable to turn on exceptions during mooseError(), should only be used within MOOSE unit tests or wh...
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)