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 <string>
24 #include <memory>
25 #include <set>
26 #include <map>
27 
28 class MooseServer : public wasp::lsp::ServerImpl
29 {
30 public:
31  MooseServer(MooseApp & moose_app);
32 
33  virtual ~MooseServer() = default;
34 
39  std::shared_ptr<wasp::lsp::Connection> getConnection() { return _connection; }
40 
41 private:
45  using SortedLocationNodes =
46  std::set<wasp::HITNodeView,
47  std::function<bool(const wasp::HITNodeView &, const wasp::HITNodeView &)>>;
48 
54  bool parseDocumentForDiagnostics(wasp::DataArray & diagnosticsList);
55 
66  bool updateDocumentTextChanges(const std::string & replacement_text,
67  int start_line,
68  int start_character,
69  int end_line,
70  int end_character,
71  int range_length);
72 
81  bool gatherDocumentCompletionItems(wasp::DataArray & completionItems,
82  bool & is_incomplete,
83  int line,
84  int character);
85 
92  void getExistingInput(wasp::HITNodeView parent_node,
93  std::set<std::string> & existing_params,
94  std::set<std::string> & existing_subblocks);
95 
103  void getAllValidParameters(InputParameters & valid_params,
104  const std::string & object_path,
105  const std::string & object_type,
106  std::set<std::string> & obj_act_tasks);
107 
114  void getActionParameters(InputParameters & valid_params,
115  const std::string & object_path,
116  std::set<std::string> & obj_act_tasks);
117 
124  void getObjectParameters(InputParameters & valid_params,
125  std::string object_type,
126  const std::set<std::string> & obj_act_tasks);
127 
140  bool addParametersToList(wasp::DataArray & completionItems,
141  const InputParameters & valid_params,
142  const std::set<std::string> & existing_params,
143  int replace_line_beg,
144  int replace_char_beg,
145  int replace_line_end,
146  int replace_char_end,
147  const std::string & filtering_prefix);
148 
160  bool addSubblocksToList(wasp::DataArray & completionItems,
161  const std::string & object_path,
162  int replace_line_beg,
163  int replace_char_beg,
164  int replace_line_end,
165  int replace_char_end,
166  const std::string & filtering_prefix,
167  bool request_on_block_decl);
168 
184  bool addValuesToList(wasp::DataArray & completionItems,
185  const InputParameters & valid_params,
186  const std::set<std::string> & existing_params,
187  const std::set<std::string> & existing_subblocks,
188  const std::string & param_name,
189  const std::set<std::string> & obj_act_tasks,
190  const std::string & object_path,
191  int replace_line_beg,
192  int replace_char_beg,
193  int replace_line_end,
194  int replace_char_end);
195 
201  template <typename MooseEnumType>
202  void getEnumsAndDocs(MooseEnumType & moose_enum_param,
203  std::map<std::string, std::string> & options_and_descs);
204 
212  bool
213  gatherDocumentDefinitionLocations(wasp::DataArray & definitionLocations, int line, int character);
214 
222  const std::string & clean_type,
223  const std::string & val_string);
224 
231  bool addLocationNodesToList(wasp::DataArray & defsOrRefsLocations,
232  const SortedLocationNodes & location_nodes);
233 
241  bool getHoverDisplayText(std::string & display_text, int line, int character);
242 
251  bool gatherDocumentReferencesLocations(wasp::DataArray & referencesLocations,
252  int line,
253  int character,
254  bool include_declaration);
255 
263  void getNodesByValueAndTypes(SortedLocationNodes & match_nodes,
264  wasp::HITNodeView view_parent,
265  const std::string & target_value,
266  const std::set<std::string> & target_types);
267 
275  bool gatherDocumentFormattingTextEdits(wasp::DataArray & formattingTextEdits,
276  int tab_size,
277  bool insert_spaces);
278 
286  std::string formatDocument(wasp::HITNodeView parent, std::size_t & prev_line, std::size_t level);
287 
293  bool gatherDocumentSymbols(wasp::DataArray & documentSymbols);
294 
301  bool traverseParseTreeAndFillSymbols(wasp::HITNodeView view_parent,
302  wasp::DataObject & data_parent);
303 
312  int getCompletionItemKind(const InputParameters & valid_params,
313  const std::string & param_name,
314  const std::string & clean_type,
315  bool is_param);
316 
322  int getDocumentSymbolKind(wasp::HITNodeView symbol_node);
323 
332  std::string getRequiredParamsText(const std::string & subblock_path,
333  const std::string & subblock_type,
334  const std::set<std::string> & existing_params,
335  const std::string & indent_spaces);
336 
342  bool connectionRead(wasp::DataObject & object) { return _connection->read(object, errors); }
343 
349  bool connectionWrite(wasp::DataObject & object) { return _connection->write(object, errors); }
350 
356  bool rootIsValid() const;
357 
361  hit::Node & getRoot();
362 
366  std::shared_ptr<MooseApp> getCheckApp() const;
367 
371  const std::string & getDocumentText() const;
372 
377 
381  std::map<std::string, std::shared_ptr<MooseApp>> _check_apps;
382 
386  std::map<std::string, std::string> _path_to_text;
387 
391  std::shared_ptr<wasp::lsp::IOStreamConnection> _connection;
392 
396  std::map<std::string, std::set<std::string>> _syntax_to_subblocks;
397 
401  std::map<std::string, std::set<std::string>> _type_to_input_paths;
402 
406  std::map<std::string, std::set<std::string>> _input_path_to_types;
407 
411  std::size_t _formatting_tab_size;
412 };
int getDocumentSymbolKind(wasp::HITNodeView symbol_node)
Get document symbol kind value that client may use for outline icon.
Definition: MooseServer.C:1457
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:401
std::shared_ptr< MooseApp > getCheckApp() const
Definition: MooseServer.C:1535
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:943
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:1495
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:406
const std::string & getDocumentText() const
Definition: MooseServer.C:1542
MooseServer(MooseApp &moose_app)
Definition: MooseServer.C:34
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:671
bool gatherDocumentSymbols(wasp::DataArray &documentSymbols)
Gather document symbols - specific to this server implemention.
Definition: MooseServer.C:1320
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:459
Base class for MOOSE-based applications.
Definition: MooseApp.h:85
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
bool getHoverDisplayText(std::string &display_text, int line, int character)
Get hover display text - logic specific to this server implemention.
Definition: MooseServer.C:1016
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.
Definition: MooseServer.C:161
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:47
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:406
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:1170
std::shared_ptr< wasp::lsp::Connection > getConnection()
Get read / write connection - specific to this server implemention.
Definition: MooseServer.h:39
bool rootIsValid() const
Definition: MooseServer.C:1521
std::shared_ptr< wasp::lsp::IOStreamConnection > _connection
_connection - shared pointer to this server&#39;s read / write iostream
Definition: MooseServer.h:391
hit::Node & getRoot()
Definition: MooseServer.C:1528
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:349
bool gatherDocumentFormattingTextEdits(wasp::DataArray &formattingTextEdits, int tab_size, bool insert_spaces)
Gather formatting text edits - specific to this server implemention.
Definition: MooseServer.C:1215
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:361
bool traverseParseTreeAndFillSymbols(wasp::HITNodeView view_parent, wasp::DataObject &data_parent)
Recursively fill document symbols from the given node.
Definition: MooseServer.C:1374
MooseApp & _moose_app
_moose_app - reference to parent application that owns this server
Definition: MooseServer.h:376
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:569
bool gatherDocumentCompletionItems(wasp::DataArray &completionItems, bool &is_incomplete, int line, int character)
Gather document completion items - specific to this server implemention.
Definition: MooseServer.C:175
bool gatherDocumentReferencesLocations(wasp::DataArray &referencesLocations, int line, int character, bool include_declaration)
Gather references locations - specific to this server implemention.
Definition: MooseServer.C:1098
std::size_t _formatting_tab_size
_formatting_tab_size - number of indent spaces for formatting
Definition: MooseServer.h:411
bool connectionRead(wasp::DataObject &object)
Read from connection into object - specific to this server&#39;s connection.
Definition: MooseServer.h:342
bool parseDocumentForDiagnostics(wasp::DataArray &diagnosticsList)
Parse document for diagnostics - specific to this server implemention.
Definition: MooseServer.C:55
bool gatherDocumentDefinitionLocations(wasp::DataArray &definitionLocations, int line, int character)
Gather definition locations - specific to this server implemention.
Definition: MooseServer.C:840
std::map< std::string, std::string > _path_to_text
_path_to_text - map of document paths to current text strings
Definition: MooseServer.h:386
bool addLocationNodesToList(wasp::DataArray &defsOrRefsLocations, const SortedLocationNodes &location_nodes)
Add set of nodes sorted by location to definition or reference list.
Definition: MooseServer.C:989
bool connectionWrite(wasp::DataObject &object)
Write object json to connection - specific to this server&#39;s connection.
Definition: MooseServer.h:349
std::map< std::string, std::set< std::string > > _syntax_to_subblocks
_syntax_to_subblocks - map of syntax paths to valid subblocks
Definition: MooseServer.h:396
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:1426
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:828
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:1261
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:331
std::map< std::string, std::shared_ptr< MooseApp > > _check_apps
_check_apps - map from document paths to input check applications
Definition: MooseServer.h:381