https://mooseframework.inl.gov
MooseServer.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 #include "MooseApp.h"
13 #include "wasplsp/LSP.h"
14 #include "wasplsp/ServerImpl.h"
15 #include "wasplsp/Connection.h"
16 #include "libmesh/ignore_warnings.h"
17 #include "wasplsp/IOStreamConnection.h"
18 #include "libmesh/restore_warnings.h"
19 #include "waspcore/Object.h"
20 #include "wasphit/HITNodeView.h"
21 #include "waspsiren/SIRENInterpreter.h"
22 #include "waspsiren/SIRENResultSet.h"
23 #include "waspplot/CustomPlotFile.h"
24 #include <string>
25 #include <memory>
26 #include <set>
27 #include <map>
28 
29 class MooseServer : public wasp::lsp::ServerImpl
30 {
31 public:
32  MooseServer(MooseApp & moose_app);
33 
34  virtual ~MooseServer() = default;
35 
40  std::shared_ptr<wasp::lsp::Connection> getConnection() { return _connection; }
41 
47 
53  void setDistPlotNumPoints(std::size_t num_points) { _dist_plot_num_points = num_points; }
54 
55 private:
59  using SortedLocationNodes =
60  std::set<wasp::HITNodeView,
61  std::function<bool(const wasp::HITNodeView &, const wasp::HITNodeView &)>>;
62 
68  bool parseDocumentForDiagnostics(wasp::DataArray & diagnosticsList);
69 
74 
80  void getFileNameTypeValues(std::set<std::string> & filename_vals, wasp::HITNodeView parent);
81 
90  bool gatherDocumentCompletionItems(wasp::DataArray & completionItems,
91  bool & is_incomplete,
92  int line,
93  int character);
94 
101  void getExistingInput(wasp::HITNodeView parent_node,
102  std::set<std::string> & existing_params,
103  std::set<std::string> & existing_subblocks);
104 
112  void getAllValidParameters(InputParameters & valid_params,
113  const std::string & object_path,
114  const std::string & object_type,
115  std::set<std::string> & obj_act_tasks);
116 
123  void getActionParameters(InputParameters & valid_params,
124  const std::string & object_path,
125  std::set<std::string> & obj_act_tasks);
126 
133  void getObjectParameters(InputParameters & valid_params,
134  std::string object_type,
135  const std::set<std::string> & obj_act_tasks);
136 
149  bool addParametersToList(wasp::DataArray & completionItems,
150  const InputParameters & valid_params,
151  const std::set<std::string> & existing_params,
152  int replace_line_beg,
153  int replace_char_beg,
154  int replace_line_end,
155  int replace_char_end,
156  const std::string & filtering_prefix);
157 
169  bool addSubblocksToList(wasp::DataArray & completionItems,
170  const std::string & object_path,
171  int replace_line_beg,
172  int replace_char_beg,
173  int replace_line_end,
174  int replace_char_end,
175  const std::string & filtering_prefix,
176  bool request_on_block_decl);
177 
193  bool addValuesToList(wasp::DataArray & completionItems,
194  const InputParameters & valid_params,
195  const std::set<std::string> & existing_params,
196  const std::set<std::string> & existing_subblocks,
197  const std::string & param_name,
198  const std::set<std::string> & obj_act_tasks,
199  const std::string & object_path,
200  int replace_line_beg,
201  int replace_char_beg,
202  int replace_line_end,
203  int replace_char_end);
204 
210  template <typename MooseEnumType>
211  void getEnumsAndDocs(MooseEnumType & moose_enum_param,
212  std::map<std::string, std::string> & options_and_descs);
213 
219  void addObjectsFromWarehouses(const std::string & param_type,
220  std::map<std::string, std::string> & options_and_descs);
221 
229  bool
230  gatherDocumentDefinitionLocations(wasp::DataArray & definitionLocations, int line, int character);
231 
239  const std::string & clean_type,
240  const std::string & val_string);
241 
248  bool addLocationNodesToList(wasp::DataArray & defsOrRefsLocations,
249  const SortedLocationNodes & location_nodes);
250 
258  bool getHoverDisplayText(std::string & display_text, int line, int character);
259 
268  bool gatherDocumentReferencesLocations(wasp::DataArray & referencesLocations,
269  int line,
270  int character,
271  bool include_declaration);
272 
280  void getNodesByValueAndTypes(SortedLocationNodes & match_nodes,
281  wasp::HITNodeView view_parent,
282  const std::string & target_value,
283  const std::set<std::string> & target_types);
284 
292  bool gatherDocumentFormattingTextEdits(wasp::DataArray & formattingTextEdits,
293  int tab_size,
294  bool insert_spaces);
295 
303  std::string formatDocument(wasp::HITNodeView parent, std::size_t & prev_line, std::size_t level);
304 
310  bool gatherDocumentSymbols(wasp::DataArray & documentSymbols);
311 
318  bool traverseParseTreeAndFillSymbols(wasp::HITNodeView view_parent,
319  wasp::DataObject & data_parent);
320 
329  int getCompletionItemKind(const InputParameters & valid_params,
330  const std::string & param_name,
331  const std::string & clean_type,
332  bool is_param);
333 
339  int getDocumentSymbolKind(wasp::HITNodeView symbol_node);
340 
349  std::string getRequiredParamsText(const std::string & subblock_path,
350  const std::string & subblock_type,
351  const std::set<std::string> & existing_params,
352  const std::string & indent_spaces);
353 
362  bool gatherExtensionResponses(wasp::DataArray & extensionResponses,
363  const std::string & extensionMethod,
364  int line,
365  int character);
366 
374  bool gatherPlottingResponses(wasp::DataArray & plotting_responses, int line, int character);
375 
383  void buildFuncPlotResponse(wasp::DataArray & plotting_responses,
384  FEProblemBase & problem,
385  const std::string & object_name,
386  const std::string & object_type);
387 
395  void buildDistPlotResponses(wasp::DataArray & plotting_responses,
396  FEProblemBase & problem,
397  const std::string & object_name,
398  const std::string & object_type);
399 
409  void buildLineGraphPlot(wasp::CustomPlot & plot_object,
410  const std::string & plot_title,
411  const std::string & x_axis_label,
412  const std::string & y_axis_label,
413  const std::vector<double> & graph_keys,
414  const std::vector<double> & graph_vals);
415 
421  bool connectionRead(wasp::DataObject & object) { return _connection->read(object, errors); }
422 
428  bool connectionWrite(wasp::DataObject & object) { return _connection->write(object, errors); }
429 
435  bool rootIsValid() const;
436 
440  struct CheckState
441  {
442  CheckState(std::shared_ptr<Parser> & parser) : parser(parser) {}
443  std::shared_ptr<Parser> parser;
444  std::unique_ptr<MooseApp> app;
445  };
446 
450  const CheckState * queryCheckState() const;
454 
457  const MooseApp * queryCheckApp() const;
461 
464  const Parser * queryCheckParser() const;
468 
471  const hit::Node * queryRoot() const;
472 
477  const hit::Node & getRoot() const;
478 
483 
487  std::map<std::string, CheckState> _check_state;
488 
492  std::shared_ptr<wasp::lsp::IOStreamConnection> _connection;
493 
497  std::map<std::string, std::set<std::string>> _syntax_to_subblocks;
498 
502  std::map<std::string, std::set<std::string>> _type_to_input_paths;
503 
507  std::map<std::string, std::set<std::string>> _input_path_to_types;
508 
512  std::size_t _formatting_tab_size;
513 
518 
523 };
int getDocumentSymbolKind(wasp::HITNodeView symbol_node)
Get document symbol kind value that client may use for outline icon.
Definition: MooseServer.C:1765
std::map< std::string, std::set< std::string > > _type_to_input_paths
_type_to_input_paths - map of parameter types to lookup paths
Definition: MooseServer.h:502
void addResourcesForDocument()
Add paths from includes and FileName parameters for client to watch.
Definition: MooseServer.C:263
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.
Definition: MooseServer.C:1215
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.
Definition: MooseServer.C:1803
std::map< std::string, std::set< std::string > > _input_path_to_types
_type_to_input_paths - map of lookup paths to parameter types
Definition: MooseServer.h:507
MooseServer(MooseApp &moose_app)
Definition: MooseServer.C:51
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 &param_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.
Definition: MooseServer.C:861
MooseApp & getCheckApp()
Public interface for writable check app reference with error checks.
Definition: MooseServer.C:2088
void setDistPlotNumPoints(std::size_t num_points)
Override number of discrete points in continuous distribution plots.
Definition: MooseServer.h:53
bool gatherDocumentSymbols(wasp::DataArray &documentSymbols)
Gather document symbols - specific to this server implemention.
Definition: MooseServer.C:1626
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.
Definition: MooseServer.C:649
std::shared_ptr< Parser > parser
Definition: MooseServer.h:443
Base class for MOOSE-based applications.
Definition: MooseApp.h:108
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const hit::Node & getRoot() const
Definition: MooseServer.C:2101
double _dist_plot_quantile_bound
_dist_plot_quantile_bound - epsilon to bound plot range tails
Definition: MooseServer.h:522
bool getHoverDisplayText(std::string &display_text, int line, int character)
Get hover display text - logic specific to this server implemention.
Definition: MooseServer.C:1288
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
const CheckState * queryCheckState() const
Definition: MooseServer.C:2048
void buildLineGraphPlot(wasp::CustomPlot &plot_object, const std::string &plot_title, const std::string &x_axis_label, const std::string &y_axis_label, const std::vector< double > &graph_keys, const std::vector< double > &graph_vals)
Build CustomPlot graph with provided keys, values, and plot title.
Definition: MooseServer.C:1975
std::set< wasp::HITNodeView, std::function< bool(const wasp::HITNodeView &, const wasp::HITNodeView &)> > SortedLocationNodes
SortedLocationNodes - type alias for set of nodes sorted by location.
Definition: MooseServer.h:61
void addObjectsFromWarehouses(const std::string &param_type, std::map< std::string, std::string > &options_and_descs)
Supplement completion list with objects in warehouses if applicable.
Definition: MooseServer.C:1039
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.
Definition: MooseServer.C:596
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.
Definition: MooseServer.C:1465
std::shared_ptr< wasp::lsp::Connection > getConnection()
Get read / write connection - specific to this server implemention.
Definition: MooseServer.h:40
bool rootIsValid() const
std::shared_ptr< wasp::lsp::IOStreamConnection > _connection
_connection - shared pointer to this server&#39;s read / write iostream
Definition: MooseServer.h:492
CheckState(std::shared_ptr< Parser > &parser)
Definition: MooseServer.h:442
const Parser * queryCheckParser() const
Definition: MooseServer.C:2061
const MooseApp * queryCheckApp() const
Definition: MooseServer.C:2074
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.
Definition: MooseServer.C:539
Helper for storing the state for a single document.
Definition: MooseServer.h:440
bool gatherDocumentFormattingTextEdits(wasp::DataArray &formattingTextEdits, int tab_size, bool insert_spaces)
Gather formatting text edits - specific to this server implemention.
Definition: MooseServer.C:1510
void getFileNameTypeValues(std::set< std::string > &filename_vals, wasp::HITNodeView parent)
Recursively walk input to gather all FileName type parameter values.
Definition: MooseServer.C:306
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.
Definition: MooseServer.C:551
bool traverseParseTreeAndFillSymbols(wasp::HITNodeView view_parent, wasp::DataObject &data_parent)
Recursively fill document symbols from the given node.
Definition: MooseServer.C:1682
void buildDistPlotResponses(wasp::DataArray &plotting_responses, FEProblemBase &problem, const std::string &object_name, const std::string &object_type)
Compute PDF and CDF, build CustomPlot objects, and add to responses.
Definition: MooseServer.C:1922
bool gatherExtensionResponses(wasp::DataArray &extensionResponses, const std::string &extensionMethod, int line, int character)
Gather extension responses - specific to this server implemention.
Definition: MooseServer.C:1833
MooseApp & _moose_app
_moose_app - reference to parent application that owns this server
Definition: MooseServer.h:482
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.
Definition: MooseServer.C:759
bool gatherDocumentCompletionItems(wasp::DataArray &completionItems, bool &is_incomplete, int line, int character)
Gather document completion items - specific to this server implemention.
Definition: MooseServer.C:362
std::unique_ptr< MooseApp > app
Definition: MooseServer.h:444
bool gatherDocumentReferencesLocations(wasp::DataArray &referencesLocations, int line, int character, bool include_declaration)
Gather references locations - specific to this server implemention.
Definition: MooseServer.C:1391
bool gatherPlottingResponses(wasp::DataArray &plotting_responses, int line, int character)
Build CustomPlot extension responses when method name is plotting.
Definition: MooseServer.C:1846
std::size_t _formatting_tab_size
_formatting_tab_size - number of indent spaces for formatting
Definition: MooseServer.h:512
void buildFuncPlotResponse(wasp::DataArray &plotting_responses, FEProblemBase &problem, const std::string &object_name, const std::string &object_type)
Gather function data, build CustomPlot object, and add to responses.
Definition: MooseServer.C:1890
bool connectionRead(wasp::DataObject &object)
Read from connection into object - specific to this server&#39;s connection.
Definition: MooseServer.h:421
bool parseDocumentForDiagnostics(wasp::DataArray &diagnosticsList)
Parse document for diagnostics - specific to this server implemention.
Definition: MooseServer.C:71
std::size_t _dist_plot_num_points
_dist_plot_num_points - distribution plot sampling resolution
Definition: MooseServer.h:517
bool gatherDocumentDefinitionLocations(wasp::DataArray &definitionLocations, int line, int character)
Gather definition locations - specific to this server implemention.
Definition: MooseServer.C:1110
bool addLocationNodesToList(wasp::DataArray &defsOrRefsLocations, const SortedLocationNodes &location_nodes)
Add set of nodes sorted by location to definition or reference list.
Definition: MooseServer.C:1261
bool connectionWrite(wasp::DataObject &object)
Write object json to connection - specific to this server&#39;s connection.
Definition: MooseServer.h:428
std::map< std::string, std::set< std::string > > _syntax_to_subblocks
_syntax_to_subblocks - map of syntax paths to valid subblocks
Definition: MooseServer.h:497
virtual ~MooseServer()=default
int getCompletionItemKind(const InputParameters &valid_params, const std::string &param_name, const std::string &clean_type, bool is_param)
Get completion item kind value that client may use for icon in list.
Definition: MooseServer.C:1734
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.
Definition: MooseServer.C:1027
Class for parsing input files.
Definition: Parser.h:87
std::map< std::string, CheckState > _check_state
_check_state - map from document paths to state (parser, app, text)
Definition: MooseServer.h:487
const hit::Node * queryRoot() const
Definition: MooseServer.C:2032
std::string formatDocument(wasp::HITNodeView parent, std::size_t &prev_line, std::size_t level)
Recursively walk down whole nodeview tree while formatting document.
Definition: MooseServer.C:1559
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.
Definition: MooseServer.C:521