LCOV - code coverage report
Current view: top level - include/base - MooseServer.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 99787a Lines: 3 5 60.0 %
Date: 2025-10-14 20:01:24 Functions: 4 6 66.7 %
Legend: Lines: hit not hit

          Line data    Source code
       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           4 :   virtual ~MooseServer() = default;
      35             : 
      36             :   /**
      37             :    * Get read / write connection - specific to this server implemention.
      38             :    * @return - shared pointer to the server's read / write connection
      39             :    */
      40           2 :   std::shared_ptr<wasp::lsp::Connection> getConnection() { return _connection; }
      41             : 
      42             : private:
      43             :   /**
      44             :    * SortedLocationNodes - type alias for set of nodes sorted by location
      45             :    */
      46             :   using SortedLocationNodes =
      47             :       std::set<wasp::HITNodeView,
      48             :                std::function<bool(const wasp::HITNodeView &, const wasp::HITNodeView &)>>;
      49             : 
      50             :   /**
      51             :    * Parse document for diagnostics - specific to this server implemention.
      52             :    * @param diagnosticsList - data array of diagnostics data objects to fill
      53             :    * @return - true if completed successfully - does not indicate parse fail
      54             :    */
      55             :   bool parseDocumentForDiagnostics(wasp::DataArray & diagnosticsList);
      56             : 
      57             :   /**
      58             :    * Add paths from includes and FileName parameters for client to watch.
      59             :    */
      60             :   void addResourcesForDocument();
      61             : 
      62             :   /**
      63             :    * Recursively walk input to gather all FileName type parameter values.
      64             :    * @param filename_vals - set to fill up with FileName parameter values
      65             :    * @param parent - nodeview for recursive tree traversal starting point
      66             :    */
      67             :   void getFileNameTypeValues(std::set<std::string> & filename_vals, wasp::HITNodeView parent);
      68             : 
      69             :   /**
      70             :    * Gather document completion items - specific to this server implemention.
      71             :    * @param completionItems - data array of completion item objects to fill
      72             :    * @param is_incomplete - flag indicating if the completions are complete
      73             :    * @param line - line to be used for completions gathering logic
      74             :    * @param character - column to be used for completions gathering logic
      75             :    * @return - true if the gathering of items completed successfully
      76             :    */
      77             :   bool gatherDocumentCompletionItems(wasp::DataArray & completionItems,
      78             :                                      bool & is_incomplete,
      79             :                                      int line,
      80             :                                      int character);
      81             : 
      82             :   /**
      83             :    * Get names of parameters and subblocks specified in given input node.
      84             :    * @param parent_node - object node context under which to gather input
      85             :    * @param existing_params - set to fill with parameter names from input
      86             :    * @param existing_subblocks - set to fill with subblock names in input
      87             :    */
      88             :   void getExistingInput(wasp::HITNodeView parent_node,
      89             :                         std::set<std::string> & existing_params,
      90             :                         std::set<std::string> & existing_subblocks);
      91             : 
      92             :   /**
      93             :    * Get all global parameters, action parameters, and object parameters.
      94             :    * @param valid_params - collection to fill with valid input parameters
      95             :    * @param object_path - full node path where autocomplete was requested
      96             :    * @param object_type - type of object where autocomplete was requested
      97             :    * @param obj_act_tasks - set for adding in all MooseObjectAction tasks
      98             :    */
      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             : 
     104             :   /**
     105             :    * Get all action parameters using requested object path to collection.
     106             :    * @param valid_params - collection for filling action input parameters
     107             :    * @param object_path - full node path where autocomplete was requested
     108             :    * @param obj_act_tasks - set for adding in all MooseObjectAction tasks
     109             :    */
     110             :   void getActionParameters(InputParameters & valid_params,
     111             :                            const std::string & object_path,
     112             :                            std::set<std::string> & obj_act_tasks);
     113             : 
     114             :   /**
     115             :    * Get all object parameters using requested object path to collection.
     116             :    * @param valid_params - collection for filling object input parameters
     117             :    * @param object_type - type of object where autocomplete was requested
     118             :    * @param obj_act_tasks - tasks to verify object type with valid syntax
     119             :    */
     120             :   void getObjectParameters(InputParameters & valid_params,
     121             :                            std::string object_type,
     122             :                            const std::set<std::string> & obj_act_tasks);
     123             : 
     124             :   /**
     125             :    * Add parameters that were previously gathered to list for completion.
     126             :    * @param completionItems - list of completion objects to be filled out
     127             :    * @param valid_params - all valid parameters to add to completion list
     128             :    * @param existing_params - set of parameters already existing in input
     129             :    * @param replace_line_beg - start line of autocompletion replace range
     130             :    * @param replace_char_beg - start column of autocomplete replace range
     131             :    * @param replace_line_end - end line of autocomplete replacement range
     132             :    * @param replace_char_end - end column of autocompletion replace range
     133             :    * @param filtering_prefix - beginning text to filter list if not empty
     134             :    * @return - true if filling of completion items completed successfully
     135             :    */
     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             : 
     145             :   /**
     146             :    * Add subblocks to completion list for request path, line, and column.
     147             :    * @param completionItems - list of completion objects to be filled out
     148             :    * @param object_path - full node path where autocomplete was requested
     149             :    * @param replace_line_beg - start line of autocompletion replace range
     150             :    * @param replace_char_beg - start column of autocomplete replace range
     151             :    * @param replace_line_end - end line of autocomplete replacement range
     152             :    * @param replace_char_end - end column of autocompletion replace range
     153             :    * @param filtering_prefix - beginning text to filter list if not empty
     154             :    * @return - true if filling of completion items completed successfully
     155             :    */
     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             : 
     165             :   /**
     166             :    * Add parameter values to completion list for request line and column.
     167             :    * @param completionItems - list of completion objects to be filled out
     168             :    * @param valid_params - all valid parameters used for value completion
     169             :    * @param existing_params - set of parameters already existing in input
     170             :    * @param existing_subblocks - active and inactive subblock name values
     171             :    * @param param_name - name of input parameter for value autocompletion
     172             :    * @param obj_act_tasks - tasks to verify object type with valid syntax
     173             :    * @param object_path - full node path where autocomplete was requested
     174             :    * @param replace_line_beg - start line of autocompletion replace range
     175             :    * @param replace_char_beg - start column of autocomplete replace range
     176             :    * @param replace_line_end - end line of autocomplete replacement range
     177             :    * @param replace_char_end - end column of autocompletion replace range
     178             :    * @return - true if filling of completion items completed successfully
     179             :    */
     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             : 
     192             :   /**
     193             :    * Fill map of all options and descriptions if parameter is moose enum.
     194             :    * @param moose_enum_param - parameter to get documentation and options
     195             :    * @param options_and_descs - map to fill with options and descriptions
     196             :    */
     197             :   template <typename MooseEnumType>
     198             :   void getEnumsAndDocs(MooseEnumType & moose_enum_param,
     199             :                        std::map<std::string, std::string> & options_and_descs);
     200             : 
     201             :   /**
     202             :    * Gather definition locations - specific to this server implemention.
     203             :    * @param definitionLocations - data array of locations objects to fill
     204             :    * @param line - line to be used for locations gathering logic
     205             :    * @param character - column to be used for locations gathering logic
     206             :    * @return - true if the gathering of locations completed successfully
     207             :    */
     208             :   bool
     209             :   gatherDocumentDefinitionLocations(wasp::DataArray & definitionLocations, int line, int character);
     210             : 
     211             :   /**
     212             :    * Get set of nodes from associated path lookups matching value string.
     213             :    * @param location_nodes - set to fill with lookup nodes matching value
     214             :    * @param clean_type - cpp type string used for key finding input paths
     215             :    * @param val_string - specified value used for gathering input lookups
     216             :    */
     217             :   void getInputLookupDefinitionNodes(SortedLocationNodes & location_nodes,
     218             :                                      const std::string & clean_type,
     219             :                                      const std::string & val_string);
     220             : 
     221             :   /**
     222             :    * Add set of nodes sorted by location to definition or reference list.
     223             :    * @param defsOrRefsLocations - data array of locations objects to fill
     224             :    * @param location_nodes - set of nodes that have locations to be added
     225             :    * @return - true if filling of location objects completed successfully
     226             :    */
     227             :   bool addLocationNodesToList(wasp::DataArray & defsOrRefsLocations,
     228             :                               const SortedLocationNodes & location_nodes);
     229             : 
     230             :   /**
     231             :    * Get hover display text - logic specific to this server implemention.
     232             :    * @param display_text - string reference to add hover text for display
     233             :    * @param line - zero-based line to use for finding node and hover text
     234             :    * @param character - zero-based column for finding node and hover text
     235             :    * @return - true if display text was added or left empty without error
     236             :    */
     237             :   bool getHoverDisplayText(std::string & display_text, int line, int character);
     238             : 
     239             :   /**
     240             :    * Gather references locations - specific to this server implemention.
     241             :    * @param referencesLocations - data array of locations objects to fill
     242             :    * @param line - line to be used for locations gathering logic
     243             :    * @param character - column to be used for locations gathering logic
     244             :    * @param include_declaration - flag indicating declaration inclusion
     245             :    * @return - true if the gathering of locations completed successfully
     246             :    */
     247             :   bool gatherDocumentReferencesLocations(wasp::DataArray & referencesLocations,
     248             :                                          int line,
     249             :                                          int character,
     250             :                                          bool include_declaration);
     251             : 
     252             :   /**
     253             :    * Recursively walk input to gather all nodes matching value and types.
     254             :    * @param match_nodes - set to fill with nodes matching value and types
     255             :    * @param view_parent - nodeview used to start recursive tree traversal
     256             :    * @param target_value -
     257             :    * @param target_types -
     258             :    */
     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             : 
     264             :   /**
     265             :    * Gather formatting text edits - specific to this server implemention.
     266             :    * @param formattingTextEdits - data array of text edit objects to fill
     267             :    * @param tab_size - value of the size of a tab in spaces for formatting
     268             :    * @param insert_spaces - flag indicating whether to use spaces for tabs
     269             :    * @return - true if the gathering of text edits completed successfully
     270             :    */
     271             :   bool gatherDocumentFormattingTextEdits(wasp::DataArray & formattingTextEdits,
     272             :                                          int tab_size,
     273             :                                          bool insert_spaces);
     274             : 
     275             :   /**
     276             :    * Recursively walk down whole nodeview tree while formatting document.
     277             :    * @param parent - nodeview for recursive tree traversal starting point
     278             :    * @param prev_line - line of last print for blanks and inline comments
     279             :    * @param level - current level in document tree to use for indentation
     280             :    * @return - formatted string that gets appended to each recursive call
     281             :    */
     282             :   std::string formatDocument(wasp::HITNodeView parent, std::size_t & prev_line, std::size_t level);
     283             : 
     284             :   /**
     285             :    * Gather document symbols - specific to this server implemention.
     286             :    * @param documentSymbols - data array of symbols data objects to fill
     287             :    * @return - true if the gathering of symbols completed successfully
     288             :    */
     289             :   bool gatherDocumentSymbols(wasp::DataArray & documentSymbols);
     290             : 
     291             :   /**
     292             :    * Recursively fill document symbols from the given node.
     293             :    * @param view_parent - nodeview used in recursive tree traversal
     294             :    * @param data_parent - data object with array of symbol children
     295             :    * @return - true if no problems with this level of the resursion
     296             :    */
     297             :   bool traverseParseTreeAndFillSymbols(wasp::HITNodeView view_parent,
     298             :                                        wasp::DataObject & data_parent);
     299             : 
     300             :   /**
     301             :    * Get completion item kind value that client may use for icon in list.
     302             :    * @param valid_params - valid parameters used for completion item kind
     303             :    * @param param_name - name of input parameter for completion item kind
     304             :    * @param clean_type - type to decide if reference completion item kind
     305             :    * @param is_param - boolean denoting if kind is for parameter or value
     306             :    * @return - enumerated kind value that client may use for icon in list
     307             :    */
     308             :   int getCompletionItemKind(const InputParameters & valid_params,
     309             :                             const std::string & param_name,
     310             :                             const std::string & clean_type,
     311             :                             bool is_param);
     312             : 
     313             :   /**
     314             :    * Get document symbol kind value that client may use for outline icon.
     315             :    * @param symbol_node - node that will be added to symbol tree for kind
     316             :    * @return - enumerated kind value that client may use for outline icon
     317             :    */
     318             :   int getDocumentSymbolKind(wasp::HITNodeView symbol_node);
     319             : 
     320             :   /**
     321             :    * Get required parameter completion text list for given subblock path.
     322             :    * @param subblock_path - subblock path for finding required parameters
     323             :    * @param subblock_type - subblock type for finding required parameters
     324             :    * @param existing_params - set of parameters already existing in input
     325             :    * @param indent_spaces - indentation to be added before each parameter
     326             :    * @return - list of required parameters to use in subblock insert text
     327             :    */
     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             : 
     333             :   /**
     334             :    * Gather extension responses - specific to this server implemention.
     335             :    * @param extensionResponses - data array of custom responses to fill
     336             :    * @param extensionMethod - name for current extension request method
     337             :    * @param line - zero-based line to use for logic of custom extension
     338             :    * @param character - zero-based column for logic of custom extension
     339             :    * @return - true if request successfully handled with response built
     340             :    */
     341             :   bool gatherExtensionResponses(wasp::DataArray & extensionResponses,
     342             :                                 const std::string & extensionMethod,
     343             :                                 int line,
     344             :                                 int character);
     345             : 
     346             :   /**
     347             :    * Build CustomPlot extension responses when method name is plotting.
     348             :    * @param plottingResponses - array to fill with CustomPlot responses
     349             :    * @param line - zero-based line to use for logic of custom extension
     350             :    * @param character - zero-based column for logic of custom extension
     351             :    * @return - true if request successfully handled with response built
     352             :    */
     353             :   bool gatherPlottingResponses(wasp::DataArray & plottingResponses, int line, int character);
     354             : 
     355             :   /**
     356             :    * Build CustomPlot graph with provided keys, values, and plot title.
     357             :    * @param plot_object - CustomPlot object to be built into line graph
     358             :    * @param plot_title - title for plot composed of block name and type
     359             :    * @param graph_keys - abscissa values from function for graph x-axis
     360             :    * @param graph_vals - ordinate values from function for graph y-axis
     361             :    */
     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             : 
     367             :   /**
     368             :    * Read from connection into object - specific to this server's connection.
     369             :    * @param object - reference to object to be read into
     370             :    * @return - true if the read from the connection completed successfully
     371             :    */
     372           0 :   bool connectionRead(wasp::DataObject & object) { return _connection->read(object, errors); }
     373             : 
     374             :   /**
     375             :    * Write object json to connection - specific to this server's connection.
     376             :    * @param object - reference to object with contents to write to connection
     377             :    * @return - true if the write to the connection completed successfully
     378             :    */
     379           0 :   bool connectionWrite(wasp::DataObject & object) { return _connection->write(object, errors); }
     380             : 
     381             :   /**
     382             :    * @return Whether or not the root is valid
     383             :    *
     384             :    * Will be true if the app is valid, the root is not nullptr, and the root node view is not null
     385             :    */
     386             :   bool rootIsValid() const;
     387             : 
     388             :   /**
     389             :    * Helper for storing the state for a single document
     390             :    */
     391             :   struct CheckState
     392             :   {
     393          24 :     CheckState(std::shared_ptr<Parser> & parser) : parser(parser) {}
     394             :     std::shared_ptr<Parser> parser;
     395             :     std::unique_ptr<MooseApp> app;
     396             :   };
     397             : 
     398             :   /**
     399             :    * @return The check state for the current document path, if any
     400             :    */
     401             :   ///@{
     402             :   const CheckState * queryCheckState() const;
     403             :   CheckState * queryCheckState();
     404             :   ///@}
     405             :   /**
     406             :    * @return The check app for the current document path, if any
     407             :    */
     408             :   ///@{
     409             :   const MooseApp * queryCheckApp() const;
     410             :   MooseApp * queryCheckApp();
     411             :   ///@}
     412             :   /**
     413             :    * @return The check parser for the current document path, if any
     414             :    */
     415             :   ///@{
     416             :   const Parser * queryCheckParser() const;
     417             :   Parser * queryCheckParser();
     418             :   ///@}
     419             :   /**
     420             :    * @return The root node from the check parser for the current document path, if any
     421             :    */
     422             :   const hit::Node * queryRoot() const;
     423             : 
     424             :   /**
     425             :    * @return The check app for the current document path, with error checking on if it exists
     426             :    */
     427             :   MooseApp & getCheckApp();
     428             :   /**
     429             :    * @return The root node from the check parser for the current document path, with error checking
     430             :    * on if it exists
     431             :    */
     432             :   const hit::Node & getRoot() const;
     433             : 
     434             :   /**
     435             :    * @brief _moose_app - reference to parent application that owns this server
     436             :    */
     437             :   MooseApp & _moose_app;
     438             : 
     439             :   /**
     440             :    * @brief _check_state - map from document paths to state (parser, app, text)
     441             :    */
     442             :   std::map<std::string, CheckState> _check_state;
     443             : 
     444             :   /**
     445             :    * @brief _connection - shared pointer to this server's read / write iostream
     446             :    */
     447             :   std::shared_ptr<wasp::lsp::IOStreamConnection> _connection;
     448             : 
     449             :   /**
     450             :    * @brief _syntax_to_subblocks - map of syntax paths to valid subblocks
     451             :    */
     452             :   std::map<std::string, std::set<std::string>> _syntax_to_subblocks;
     453             : 
     454             :   /**
     455             :    * @brief _type_to_input_paths - map of parameter types to lookup paths
     456             :    */
     457             :   std::map<std::string, std::set<std::string>> _type_to_input_paths;
     458             : 
     459             :   /**
     460             :    * @brief _type_to_input_paths - map of lookup paths to parameter types
     461             :    */
     462             :   std::map<std::string, std::set<std::string>> _input_path_to_types;
     463             : 
     464             :   /**
     465             :    * @brief _formatting_tab_size - number of indent spaces for formatting
     466             :    */
     467             :   std::size_t _formatting_tab_size;
     468             : };

Generated by: LCOV version 1.14