https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
29class MooseServer : public wasp::lsp::ServerImpl
30{
31public:
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
55private:
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
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
443
448 {
449 std::map<std::string, std::set<std::string>> syntax_to_subblocks;
450 std::map<std::string, std::set<std::string>> type_to_input_paths;
451 std::map<std::string, std::set<std::string>> input_path_to_types;
452 };
453
458
463 {
464 CheckState(std::shared_ptr<Parser> & parser) : parser(parser) {}
465 std::shared_ptr<Parser> parser;
466 std::unique_ptr<MooseApp> app;
467 };
468
473 const CheckState * queryCheckState() const;
476
480 const MooseApp * queryCheckApp() const;
483
487 const Parser * queryCheckParser() const;
490
493 const hit::Node * queryRoot() const;
494
499 const hit::Node & getRoot() const;
500
505
509 std::map<std::string, CheckState> _check_state;
510
514 std::shared_ptr<wasp::lsp::IOStreamConnection> _connection;
515
519 std::map<std::string, SyntaxMetadata> _app_type_to_syntax_metadata;
520
525
530
535};
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
Base class for MOOSE-based applications.
Definition MooseApp.h:110
bool gatherPlottingResponses(wasp::DataArray &plotting_responses, int line, int character)
Build CustomPlot extension responses when method name is plotting.
MooseApp & getCheckApp()
Public interface for writable check app reference with error checks.
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.
int getDocumentSymbolKind(wasp::HITNodeView symbol_node)
Get document symbol kind value that client may use for outline icon.
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.
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 parseDocumentForDiagnostics(wasp::DataArray &diagnosticsList)
Parse document for diagnostics - specific to this server implemention.
Definition MooseServer.C:71
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.
std::size_t _dist_plot_num_points
_dist_plot_num_points - distribution plot sampling resolution
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.
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.
const CheckState * queryCheckState() 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.
std::map< std::string, SyntaxMetadata > _app_type_to_syntax_metadata
_app_type_to_syntax_metadata - syntax metadata per app type map
bool gatherDocumentReferencesLocations(wasp::DataArray &referencesLocations, int line, int character, bool include_declaration)
Gather references locations - 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.
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.
bool gatherDocumentDefinitionLocations(wasp::DataArray &definitionLocations, int line, int character)
Gather definition locations - specific to this server implemention.
std::size_t _formatting_tab_size
_formatting_tab_size - number of indent spaces for formatting
MooseApp & _moose_app
_moose_app - reference to parent application that owns this server
std::map< std::string, CheckState > _check_state
_check_state - map from document paths to state (parser, app, text)
virtual ~MooseServer()=default
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.
bool connectionRead(wasp::DataObject &object)
Read from connection into object - specific to this server's connection.
std::shared_ptr< wasp::lsp::Connection > getConnection()
Get read / write connection - specific to this server implemention.
Definition MooseServer.h:40
bool traverseParseTreeAndFillSymbols(wasp::HITNodeView view_parent, wasp::DataObject &data_parent)
Recursively fill document symbols from the given node.
const hit::Node & getRoot() const
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.
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 addResourcesForDocument()
Add paths from includes and FileName parameters for client to watch.
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.
bool connectionWrite(wasp::DataObject &object)
Write object json to connection - specific to this server's connection.
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.
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.
std::shared_ptr< wasp::lsp::IOStreamConnection > _connection
_connection - shared pointer to this server's read / write iostream
void setDistPlotNumPoints(std::size_t num_points)
Override number of discrete points in continuous distribution plots.
Definition MooseServer.h:53
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.
void getFileNameTypeValues(std::set< std::string > &filename_vals, wasp::HITNodeView parent)
Recursively walk input to gather all FileName type parameter values.
bool gatherExtensionResponses(wasp::DataArray &extensionResponses, const std::string &extensionMethod, int line, int character)
Gather extension responses - specific to this server implemention.
const MooseApp * queryCheckApp() const
bool rootIsValid() const
const Parser * queryCheckParser() const
bool gatherDocumentFormattingTextEdits(wasp::DataArray &formattingTextEdits, int tab_size, bool insert_spaces)
Gather formatting text edits - specific to this server implemention.
bool gatherDocumentCompletionItems(wasp::DataArray &completionItems, bool &is_incomplete, int line, int character)
Gather document completion items - specific to this server implemention.
bool addLocationNodesToList(wasp::DataArray &defsOrRefsLocations, const SortedLocationNodes &location_nodes)
Add set of nodes sorted by location to definition or reference list.
MooseApp & getRegistrationApp()
double _dist_plot_quantile_bound
_dist_plot_quantile_bound - epsilon to bound plot range tails
SyntaxMetadata & getSyntaxMetadata()
const hit::Node * queryRoot() const
bool getHoverDisplayText(std::string &display_text, int line, int character)
Get hover display text - logic specific to this server implemention.
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.
bool gatherDocumentSymbols(wasp::DataArray &documentSymbols)
Gather document symbols - specific to this server implemention.
Class for parsing input files.
Definition Parser.h:102
Helper for storing the state for a single document.
std::unique_ptr< MooseApp > app
CheckState(std::shared_ptr< Parser > &parser)
std::shared_ptr< Parser > parser
struct to store syntax metadata for each registration application type
std::map< std::string, std::set< std::string > > syntax_to_subblocks
std::map< std::string, std::set< std::string > > input_path_to_types
std::map< std::string, std::set< std::string > > type_to_input_paths