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 
42 private:
46  using SortedLocationNodes =
47  std::set<wasp::HITNodeView,
48  std::function<bool(const wasp::HITNodeView &, const wasp::HITNodeView &)>>;
49 
55  bool parseDocumentForDiagnostics(wasp::DataArray & diagnosticsList);
56 
61 
67  void getFileNameTypeValues(std::set<std::string> & filename_vals, wasp::HITNodeView parent);
68 
77  bool gatherDocumentCompletionItems(wasp::DataArray & completionItems,
78  bool & is_incomplete,
79  int line,
80  int character);
81 
88  void getExistingInput(wasp::HITNodeView parent_node,
89  std::set<std::string> & existing_params,
90  std::set<std::string> & existing_subblocks);
91 
99  void getAllValidParameters(InputParameters & valid_params,
100  const std::string & object_path,
101  const std::string & object_type,
102  std::set<std::string> & obj_act_tasks);
103 
110  void getActionParameters(InputParameters & valid_params,
111  const std::string & object_path,
112  std::set<std::string> & obj_act_tasks);
113 
120  void getObjectParameters(InputParameters & valid_params,
121  std::string object_type,
122  const std::set<std::string> & obj_act_tasks);
123 
136  bool addParametersToList(wasp::DataArray & completionItems,
137  const InputParameters & valid_params,
138  const std::set<std::string> & existing_params,
139  int replace_line_beg,
140  int replace_char_beg,
141  int replace_line_end,
142  int replace_char_end,
143  const std::string & filtering_prefix);
144 
156  bool addSubblocksToList(wasp::DataArray & completionItems,
157  const std::string & object_path,
158  int replace_line_beg,
159  int replace_char_beg,
160  int replace_line_end,
161  int replace_char_end,
162  const std::string & filtering_prefix,
163  bool request_on_block_decl);
164 
180  bool addValuesToList(wasp::DataArray & completionItems,
181  const InputParameters & valid_params,
182  const std::set<std::string> & existing_params,
183  const std::set<std::string> & existing_subblocks,
184  const std::string & param_name,
185  const std::set<std::string> & obj_act_tasks,
186  const std::string & object_path,
187  int replace_line_beg,
188  int replace_char_beg,
189  int replace_line_end,
190  int replace_char_end);
191 
197  template <typename MooseEnumType>
198  void getEnumsAndDocs(MooseEnumType & moose_enum_param,
199  std::map<std::string, std::string> & options_and_descs);
200 
208  bool
209  gatherDocumentDefinitionLocations(wasp::DataArray & definitionLocations, int line, int character);
210 
218  const std::string & clean_type,
219  const std::string & val_string);
220 
227  bool addLocationNodesToList(wasp::DataArray & defsOrRefsLocations,
228  const SortedLocationNodes & location_nodes);
229 
237  bool getHoverDisplayText(std::string & display_text, int line, int character);
238 
247  bool gatherDocumentReferencesLocations(wasp::DataArray & referencesLocations,
248  int line,
249  int character,
250  bool include_declaration);
251 
259  void getNodesByValueAndTypes(SortedLocationNodes & match_nodes,
260  wasp::HITNodeView view_parent,
261  const std::string & target_value,
262  const std::set<std::string> & target_types);
263 
271  bool gatherDocumentFormattingTextEdits(wasp::DataArray & formattingTextEdits,
272  int tab_size,
273  bool insert_spaces);
274 
282  std::string formatDocument(wasp::HITNodeView parent, std::size_t & prev_line, std::size_t level);
283 
289  bool gatherDocumentSymbols(wasp::DataArray & documentSymbols);
290 
297  bool traverseParseTreeAndFillSymbols(wasp::HITNodeView view_parent,
298  wasp::DataObject & data_parent);
299 
308  int getCompletionItemKind(const InputParameters & valid_params,
309  const std::string & param_name,
310  const std::string & clean_type,
311  bool is_param);
312 
318  int getDocumentSymbolKind(wasp::HITNodeView symbol_node);
319 
328  std::string getRequiredParamsText(const std::string & subblock_path,
329  const std::string & subblock_type,
330  const std::set<std::string> & existing_params,
331  const std::string & indent_spaces);
332 
341  bool gatherExtensionResponses(wasp::DataArray & extensionResponses,
342  const std::string & extensionMethod,
343  int line,
344  int character);
345 
353  bool gatherPlottingResponses(wasp::DataArray & plottingResponses, int line, int character);
354 
362  void buildLineGraphPlot(wasp::CustomPlot & plot_object,
363  const std::string & plot_title,
364  const std::vector<double> & graph_keys,
365  const std::vector<double> & graph_vals);
366 
372  bool connectionRead(wasp::DataObject & object) { return _connection->read(object, errors); }
373 
379  bool connectionWrite(wasp::DataObject & object) { return _connection->write(object, errors); }
380 
386  bool rootIsValid() const;
387 
391  struct CheckState
392  {
393  CheckState(std::shared_ptr<Parser> & parser) : parser(parser) {}
394  std::shared_ptr<Parser> parser;
395  std::unique_ptr<MooseApp> app;
396  };
397 
401  const CheckState * queryCheckState() const;
405 
408  const MooseApp * queryCheckApp() const;
412 
415  const Parser * queryCheckParser() const;
419 
422  const hit::Node * queryRoot() const;
423 
427  MooseApp & getCheckApp();
432  const hit::Node & getRoot() const;
433 
438 
442  std::map<std::string, CheckState> _check_state;
443 
447  std::shared_ptr<wasp::lsp::IOStreamConnection> _connection;
448 
452  std::map<std::string, std::set<std::string>> _syntax_to_subblocks;
453 
457  std::map<std::string, std::set<std::string>> _type_to_input_paths;
458 
462  std::map<std::string, std::set<std::string>> _input_path_to_types;
463 
467  std::size_t _formatting_tab_size;
468 };
int getDocumentSymbolKind(wasp::HITNodeView symbol_node)
Get document symbol kind value that client may use for outline icon.
Definition: MooseServer.C:1655
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:457
void addResourcesForDocument()
Add paths from includes and FileName parameters for client to watch.
Definition: MooseServer.C:249
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:1125
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:1693
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:462
MooseServer(MooseApp &moose_app)
Definition: MooseServer.C:39
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.
Definition: MooseServer.C:1799
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:847
MooseApp & getCheckApp()
Definition: MooseServer.C:1908
bool gatherDocumentSymbols(wasp::DataArray &documentSymbols)
Gather document symbols - specific to this server implemention.
Definition: MooseServer.C:1516
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:635
std::shared_ptr< Parser > parser
Definition: MooseServer.h:394
Base class for MOOSE-based applications.
Definition: MooseApp.h:103
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const hit::Node & getRoot() const
Definition: MooseServer.C:1921
bool getHoverDisplayText(std::string &display_text, int line, int character)
Get hover display text - logic specific to this server implemention.
Definition: MooseServer.C:1198
const CheckState * queryCheckState() const
Definition: MooseServer.C:1868
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:48
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:582
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:1356
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:447
CheckState(std::shared_ptr< Parser > &parser)
Definition: MooseServer.h:393
const Parser * queryCheckParser() const
Definition: MooseServer.C:1881
const MooseApp * queryCheckApp() const
Definition: MooseServer.C:1894
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:525
Helper for storing the state for a single document.
Definition: MooseServer.h:391
bool gatherDocumentFormattingTextEdits(wasp::DataArray &formattingTextEdits, int tab_size, bool insert_spaces)
Gather formatting text edits - specific to this server implemention.
Definition: MooseServer.C:1401
void getFileNameTypeValues(std::set< std::string > &filename_vals, wasp::HITNodeView parent)
Recursively walk input to gather all FileName type parameter values.
Definition: MooseServer.C:292
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:537
bool traverseParseTreeAndFillSymbols(wasp::HITNodeView view_parent, wasp::DataObject &data_parent)
Recursively fill document symbols from the given node.
Definition: MooseServer.C:1572
bool gatherExtensionResponses(wasp::DataArray &extensionResponses, const std::string &extensionMethod, int line, int character)
Gather extension responses - specific to this server implemention.
Definition: MooseServer.C:1723
MooseApp & _moose_app
_moose_app - reference to parent application that owns this server
Definition: MooseServer.h:437
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:745
bool gatherDocumentCompletionItems(wasp::DataArray &completionItems, bool &is_incomplete, int line, int character)
Gather document completion items - specific to this server implemention.
Definition: MooseServer.C:348
std::unique_ptr< MooseApp > app
Definition: MooseServer.h:395
bool gatherDocumentReferencesLocations(wasp::DataArray &referencesLocations, int line, int character, bool include_declaration)
Gather references locations - specific to this server implemention.
Definition: MooseServer.C:1282
std::size_t _formatting_tab_size
_formatting_tab_size - number of indent spaces for formatting
Definition: MooseServer.h:467
bool gatherPlottingResponses(wasp::DataArray &plottingResponses, int line, int character)
Build CustomPlot extension responses when method name is plotting.
Definition: MooseServer.C:1736
bool connectionRead(wasp::DataObject &object)
Read from connection into object - specific to this server&#39;s connection.
Definition: MooseServer.h:372
bool parseDocumentForDiagnostics(wasp::DataArray &diagnosticsList)
Parse document for diagnostics - specific to this server implemention.
Definition: MooseServer.C:57
bool gatherDocumentDefinitionLocations(wasp::DataArray &definitionLocations, int line, int character)
Gather definition locations - specific to this server implemention.
Definition: MooseServer.C:1020
bool addLocationNodesToList(wasp::DataArray &defsOrRefsLocations, const SortedLocationNodes &location_nodes)
Add set of nodes sorted by location to definition or reference list.
Definition: MooseServer.C:1171
bool connectionWrite(wasp::DataObject &object)
Write object json to connection - specific to this server&#39;s connection.
Definition: MooseServer.h:379
std::map< std::string, std::set< std::string > > _syntax_to_subblocks
_syntax_to_subblocks - map of syntax paths to valid subblocks
Definition: MooseServer.h:452
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:1624
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:1008
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:442
const hit::Node * queryRoot() const
Definition: MooseServer.C:1852
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:1450
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:507