11 #include "GDCore/Events/Parsers/ExpressionParser2.h"
12 #include "GDCore/Events/Parsers/ExpressionParser2Node.h"
13 #include "GDCore/Events/Parsers/ExpressionParser2NodePrinter.h"
14 #include "GDCore/Events/Parsers/ExpressionParser2NodeWorker.h"
15 #include "GDCore/Events/Parsers/GrammarTerminals.h"
16 #include "GDCore/Extensions/Metadata/ExpressionMetadata.h"
17 #include "GDCore/Extensions/Metadata/InstructionMetadata.h"
18 #include "GDCore/Extensions/Metadata/ValueTypeMetadata.h"
19 #include "GDCore/IDE/Events/ExpressionNodeLocationFinder.h"
20 #include "GDCore/IDE/Events/ExpressionTypeFinder.h"
21 #include "GDCore/IDE/Events/ExpressionVariableOwnerFinder.h"
22 #include "GDCore/IDE/Events/ExpressionVariablePathFinder.h"
23 #include "GDCore/Project/ProjectScopedContainers.h"
24 #include "GDCore/Project/Variable.h"
28 class ObjectsContainer;
30 class ParameterMetadata;
31 class ExpressionMetadata;
32 class ObjectConfiguration;
64 size_t replacementStartPosition_,
65 size_t replacementEndPosition_,
68 BehaviorWithPrefix, replacementStartPosition_, replacementEndPosition_);
69 description.SetPrefix(prefix_);
70 description.SetObjectName(objectName_);
81 size_t replacementStartPosition_,
82 size_t replacementEndPosition_,
83 const bool isLastParameter_,
86 TextWithPrefix, replacementStartPosition_, replacementEndPosition_);
87 description.SetObjectName(objectName_);
88 description.SetType(type_);
89 description.SetPrefix(prefix_);
90 description.SetIsLastParameter(isLastParameter_);
91 description.SetParameterMetadata(parameterMetadata_);
102 size_t replacementStartPosition_,
103 size_t replacementEndPosition_,
107 replacementStartPosition_,
108 replacementEndPosition_);
109 description.SetObjectName(objectName_);
110 description.SetBehaviorName(behaviorName_);
111 description.SetType(type_);
112 description.SetPrefix(prefix_);
118 return completionKind == other.completionKind && type == other.type &&
119 variableType == other.variableType && prefix == other.prefix &&
120 objectName == other.objectName && completion == other.completion &&
121 behaviorName == other.behaviorName;
145 variableType = variableType_;
153 return variableScope;
157 SetVariableScope(gd::VariablesContainer::SourceType variableScope_) {
158 variableScope = variableScope_;
179 completion = completion_;
191 objectName = objectName_;
206 behaviorName = behaviorName_;
231 return replacementStartPosition;
243 isLastParameter = isLastParameter_;
258 parameterMetadata = ¶meterMetadata_;
266 return parameterMetadata != &badParameterMetadata;
274 return *parameterMetadata;
283 objectConfiguration = objectConfiguration_;
284 if (!objectConfiguration) objectConfiguration = &badObjectConfiguration;
292 return objectConfiguration != &badObjectConfiguration;
300 return *objectConfiguration;
305 (GetType() ||
"no type") +
", " +
307 (GetPrefix() ||
"no prefix") +
", " +
308 (GetCompletion() ||
"no completion") +
", " +
309 (GetObjectName() ||
"no object name") +
", " +
310 (GetBehaviorName() ||
"no behavior name") +
", " +
311 (IsExact() ?
"exact" :
"non-exact") +
", " +
312 (IsLastParameter() ?
"last parameter" :
"not last parameter") +
314 (HasParameterMetadata() ?
"with parameter metadata"
315 :
"no parameter metadata") +
317 (HasObjectConfiguration() ?
"with object configuration"
318 :
"no object configuration") +
326 size_t replacementStartPosition_,
327 size_t replacementEndPosition_)
328 : completionKind(completionKind_),
331 replacementStartPosition(replacementStartPosition_),
332 replacementEndPosition(replacementEndPosition_),
334 isLastParameter(false),
335 parameterMetadata(&badParameterMetadata),
336 objectConfiguration(&badObjectConfiguration) {}
339 CompletionKind completionKind;
341 gd::VariablesContainer::SourceType variableScope = gd::VariablesContainer::Unknown;
345 size_t replacementStartPosition = 0;
346 size_t replacementEndPosition = 0;
349 bool isExact =
false;
350 bool isLastParameter =
false;
362 std::ostream& os, ExpressionCompletionDescription
const& value);
376 static std::vector<ExpressionCompletionDescription>
382 size_t searchedPosition) {
387 if (nodeAtLocation ==
nullptr) {
388 std::vector<ExpressionCompletionDescription> emptyCompletions;
389 return emptyCompletions;
395 projectScopedContainers,
398 maybeParentNodeAtLocation);
399 nodeAtLocation->Visit(autocompletionProvider);
406 const std::vector<ExpressionCompletionDescription>&
414 void OnVisitSubExpressionNode(SubExpressionNode& node)
override {
415 auto type = gd::ExpressionTypeFinder::GetType(
416 platform, projectScopedContainers, rootType, node);
418 AddCompletionsForAllIdentifiersMatchingSearch(
"", type);
419 completions.push_back(
421 type,
"", searchedPosition + 1, searchedPosition + 1));
423 void OnVisitOperatorNode(OperatorNode& node)
override {
426 void OnVisitUnaryOperatorNode(UnaryOperatorNode& node)
override {
428 platform, projectScopedContainers, rootType, node);
430 AddCompletionsForAllIdentifiersMatchingSearch(
"", type);
431 completions.push_back(
433 type,
"", searchedPosition + 1, searchedPosition + 1));
435 void OnVisitNumberNode(NumberNode& node)
override {
439 void OnVisitTextNode(TextNode& node)
override {
442 FunctionCallNode* functionCall =
443 dynamic_cast<FunctionCallNode*
>(maybeParentNodeAtLocation);
444 if (functionCall !=
nullptr) {
445 int parameterIndex = -1;
446 for (
int i = 0; i < functionCall->parameters.size(); i++) {
447 if (functionCall->parameters.at(i).get() == &node) {
452 if (parameterIndex < 0) {
456 size_t visibleParameterIndex = 0;
457 size_t metadataParameterIndex =
459 functionCall->objectName, functionCall->behaviorName);
460 const auto& objectsContainersList =
461 projectScopedContainers.GetObjectsContainersList();
463 MetadataProvider::GetFunctionCallMetadata(
464 platform, objectsContainersList, *functionCall);
467 while (metadataParameterIndex <
469 if (!metadata.GetParameters()
472 if (visibleParameterIndex == parameterIndex) {
474 &metadata.GetParameters().
GetParameter(metadataParameterIndex);
476 visibleParameterIndex++;
478 metadataParameterIndex++;
480 const int visibleParameterCount = visibleParameterIndex;
481 if (parameterMetadata ==
nullptr) {
488 if (type ==
"string") {
493 bool isLastParameter = parameterIndex == visibleParameterCount - 1;
498 node.location.GetStartPosition(),
499 node.location.GetEndPosition(),
501 functionCall->objectName));
504 void OnVisitVariableNode(VariableNode& node)
override {
505 const auto& objectsContainersList =
506 projectScopedContainers.GetObjectsContainersList();
508 platform, projectScopedContainers, rootType, node);
512 bool eagerlyCompleteIfExactMatch = node.child ==
nullptr;
515 if (type ==
"globalvar" || type ==
"scenevar") {
516 const auto* variablesContainer =
518 ? projectScopedContainers.GetVariablesContainersList()
519 .GetTopMostVariablesContainer()
520 : projectScopedContainers.GetVariablesContainersList()
521 .GetBottomMostVariablesContainer();
522 if (variablesContainer) {
523 AddCompletionsForVariablesMatchingSearch(*variablesContainer,
526 eagerlyCompleteIfExactMatch);
528 }
else if (type ==
"objectvar") {
530 platform, objectsContainersList, rootObjectName, node);
532 AddCompletionsForObjectOrGroupVariablesMatchingSearch(
533 objectsContainersList,
537 eagerlyCompleteIfExactMatch);
540 AddCompletionsForObjectsAndVariablesMatchingSearch(
541 node.name, type, node.nameLocation, eagerlyCompleteIfExactMatch);
544 void OnVisitVariableAccessorNode(VariableAccessorNode& node)
override {
545 VariableAndItsParent variableAndItsParent =
546 gd::ExpressionVariablePathFinder::GetLastParentOfNode(
547 platform, projectScopedContainers, node);
553 node.child ==
nullptr ? node.name :
"";
554 AddCompletionsForChildrenVariablesOf(variableAndItsParent,
556 eagerlyCompleteForVariableName);
558 void OnVisitVariableBracketAccessorNode(
559 VariableBracketAccessorNode& node)
override {}
560 void OnVisitIdentifierNode(IdentifierNode& node)
override {
561 const auto& objectsContainersList =
562 projectScopedContainers.GetObjectsContainersList();
564 platform, projectScopedContainers, rootType, node);
567 AddCompletionsForObjectMatchingSearch(
568 node.identifierName, type, node.location);
570 if (type ==
"globalvar" || type ==
"scenevar") {
571 const auto* variablesContainer =
573 ? projectScopedContainers.GetVariablesContainersList()
574 .GetTopMostVariablesContainer()
575 : projectScopedContainers.GetVariablesContainersList()
576 .GetBottomMostVariablesContainer();
577 if (variablesContainer) {
578 if (IsCaretOn(node.identifierNameDotLocation) ||
579 IsCaretOn(node.childIdentifierNameLocation)) {
581 if (variablesContainer->Has(node.identifierName)) {
582 AddCompletionsForChildrenVariablesOf(
583 &variablesContainer->Get(node.identifierName),
584 node.childIdentifierNameLocation,
585 node.childIdentifierName);
592 bool eagerlyCompleteIfPossible =
593 !node.identifierNameDotLocation.IsValid();
594 AddCompletionsForVariablesMatchingSearch(
597 node.identifierNameLocation,
598 eagerlyCompleteIfPossible);
601 }
else if (type ==
"objectvar") {
603 platform, objectsContainersList, rootObjectName, node);
605 if (IsCaretOn(node.identifierNameDotLocation) ||
606 IsCaretOn(node.childIdentifierNameLocation)) {
608 const auto* variablesContainer =
609 objectsContainersList.GetObjectOrGroupVariablesContainer(
611 if (variablesContainer &&
612 variablesContainer->Has(node.identifierName)) {
613 AddCompletionsForChildrenVariablesOf(
614 &variablesContainer->Get(node.identifierName),
615 node.childIdentifierNameLocation,
616 node.childIdentifierName);
623 bool eagerlyCompleteIfPossible =
624 !node.identifierNameDotLocation.IsValid();
625 AddCompletionsForObjectOrGroupVariablesMatchingSearch(
626 objectsContainersList,
629 node.identifierNameLocation,
630 eagerlyCompleteIfPossible);
635 if (IsCaretOn(node.identifierNameLocation)) {
638 bool eagerlyCompleteIfPossible =
639 !node.identifierNameDotLocation.IsValid();
640 AddCompletionsForAllIdentifiersMatchingSearch(
643 node.identifierNameLocation,
644 eagerlyCompleteIfPossible);
645 if (!node.identifierNameDotLocation.IsValid()) {
646 completions.push_back(
650 node.identifierNameLocation.GetStartPosition(),
651 node.identifierNameLocation.GetEndPosition()));
653 }
else if (IsCaretOn(node.identifierNameDotLocation) ||
654 IsCaretOn(node.childIdentifierNameLocation)) {
658 projectScopedContainers.MatchIdentifierWithName<
void>(
662 const gd::String& objectName = node.identifierName;
663 AddCompletionsForObjectOrGroupVariablesMatchingSearch(
664 objectsContainersList,
666 node.childIdentifierName,
667 node.childIdentifierNameLocation,
670 completions.push_back(
672 node.childIdentifierName,
673 node.childIdentifierNameLocation.GetStartPosition(),
674 node.childIdentifierNameLocation.GetEndPosition(),
676 completions.push_back(
679 node.childIdentifierName,
680 node.childIdentifierNameLocation.GetStartPosition(),
681 node.childIdentifierNameLocation.GetEndPosition(),
686 VariableAndItsParent variableAndItsParent =
687 gd::ExpressionVariablePathFinder::GetLastParentOfNode(
688 platform, projectScopedContainers, node);
690 AddCompletionsForChildrenVariablesOf(
691 variableAndItsParent,
692 node.childIdentifierNameLocation,
693 node.childIdentifierName);
709 void OnVisitObjectFunctionNameNode(ObjectFunctionNameNode& node)
override {
711 platform, projectScopedContainers, rootType, node);
712 if (!node.behaviorFunctionName.empty() ||
713 node.behaviorNameNamespaceSeparatorLocation.IsValid()) {
716 if (IsCaretOn(node.objectNameLocation)) {
717 AddCompletionsForObjectMatchingSearch(
718 node.objectName, type, node.objectNameLocation);
719 }
else if (IsCaretOn(node.objectNameDotLocation) ||
720 IsCaretOn(node.objectFunctionOrBehaviorNameLocation)) {
721 completions.push_back(
723 node.objectFunctionOrBehaviorName,
724 node.objectFunctionOrBehaviorNameLocation.GetStartPosition(),
725 node.objectFunctionOrBehaviorNameLocation.GetEndPosition(),
727 }
else if (IsCaretOn(node.behaviorNameNamespaceSeparatorLocation) ||
728 IsCaretOn(node.behaviorFunctionNameLocation)) {
729 completions.push_back(
732 node.behaviorFunctionName,
733 node.behaviorFunctionNameLocation.GetStartPosition(),
734 node.behaviorFunctionNameLocation.GetEndPosition(),
736 node.objectFunctionOrBehaviorName));
740 if (IsCaretOn(node.objectNameLocation)) {
741 AddCompletionsForObjectMatchingSearch(
742 node.objectName, type, node.objectNameLocation);
743 }
else if (IsCaretOn(node.objectNameDotLocation) ||
744 IsCaretOn(node.objectFunctionOrBehaviorNameLocation)) {
745 completions.push_back(
747 node.objectFunctionOrBehaviorName,
748 node.objectFunctionOrBehaviorNameLocation.GetStartPosition(),
749 node.objectFunctionOrBehaviorNameLocation.GetEndPosition(),
751 completions.push_back(
754 node.objectFunctionOrBehaviorName,
755 node.objectFunctionOrBehaviorNameLocation.GetStartPosition(),
756 node.objectFunctionOrBehaviorNameLocation.GetEndPosition(),
761 void OnVisitFunctionCallNode(FunctionCallNode& node)
override {
763 platform, projectScopedContainers, rootType, node);
764 bool isCaretOnParenthesis = IsCaretOn(node.openingParenthesisLocation) ||
765 IsCaretOn(node.closingParenthesisLocation);
767 if (!node.behaviorName.empty()) {
769 if (IsCaretOn(node.objectNameLocation)) {
770 AddCompletionsForObjectMatchingSearch(
771 node.objectName, type, node.objectNameLocation);
772 }
else if (IsCaretOn(node.objectNameDotLocation) ||
773 IsCaretOn(node.behaviorNameLocation)) {
774 completions.push_back(
777 node.behaviorNameLocation.GetStartPosition(),
778 node.behaviorNameLocation.GetEndPosition(),
781 completions.push_back(
785 node.functionNameLocation.GetStartPosition(),
786 node.functionNameLocation.GetEndPosition(),
791 }
else if (!node.objectName.empty()) {
793 if (IsCaretOn(node.objectNameLocation)) {
794 AddCompletionsForObjectMatchingSearch(
795 node.objectName, type, node.objectNameLocation);
802 if (!isCaretOnParenthesis) {
803 completions.push_back(
806 node.objectNameLocation.GetStartPosition(),
807 node.objectNameLocation.GetEndPosition(),
811 completions.push_back(
815 node.functionNameLocation.GetStartPosition(),
816 node.functionNameLocation.GetEndPosition(),
822 completions.push_back(
826 node.functionNameLocation.GetStartPosition(),
827 node.functionNameLocation.GetEndPosition())
831 void OnVisitEmptyNode(EmptyNode& node)
override {
833 platform, projectScopedContainers, rootType, node);
835 AddCompletionsForAllIdentifiersMatchingSearch(
836 node.text, type, node.location);
837 completions.push_back(
841 node.location.GetStartPosition(),
842 node.location.GetEndPosition()));
846 bool IsCaretOn(
const ExpressionParserLocation& location,
847 bool inclusive =
false) {
848 if (!location.IsValid())
return false;
850 return (location.GetStartPosition() <= searchedPosition &&
851 ((!inclusive && searchedPosition < location.GetEndPosition()) ||
852 (inclusive && searchedPosition <= location.GetEndPosition())));
859 bool IsIdentifierSafe(
const gd::String& name) {
860 if (name.
empty())
return false;
862 for (
auto character : name) {
871 void AddCompletionsForChildrenVariablesOf(
872 VariableAndItsParent variableAndItsParent,
873 const ExpressionParserLocation& location,
874 gd::String eagerlyCompleteForVariableName =
"") {
875 if (variableAndItsParent.parentVariable) {
876 AddCompletionsForChildrenVariablesOf(variableAndItsParent.parentVariable,
878 eagerlyCompleteForVariableName);
879 }
else if (variableAndItsParent.parentVariablesContainer) {
880 AddCompletionsForVariablesMatchingSearch(
881 *variableAndItsParent.parentVariablesContainer,
"", location);
885 void AddCompletionsForChildrenVariablesOf(
887 const ExpressionParserLocation& location,
888 gd::String eagerlyCompleteForVariableName =
"") {
889 if (!variable)
return;
891 if (variable->
GetType() == gd::Variable::Structure) {
893 if (!IsIdentifierSafe(name))
continue;
895 const auto& childVariable = variable->
GetChild(name);
896 ExpressionCompletionDescription description(
897 ExpressionCompletionDescription::Variable,
898 location.GetStartPosition(),
899 location.GetEndPosition());
900 description.SetCompletion(name);
901 description.SetVariableType(childVariable.GetType());
902 completions.push_back(description);
904 if (name == eagerlyCompleteForVariableName) {
905 AddEagerCompletionForVariableChildren(childVariable, name, location);
914 void AddEagerCompletionForVariableChildren(
917 const ExpressionParserLocation& location) {
918 if (variable.
GetType() == gd::Variable::Structure) {
922 IsIdentifierSafe(name)
924 : (variableName +
"[" +
925 gd::ExpressionParser2NodePrinter::PrintStringLiteral(name) +
928 const auto& childVariable = variable.
GetChild(name);
929 ExpressionCompletionDescription description(
930 ExpressionCompletionDescription::Variable,
931 location.GetStartPosition(),
932 location.GetEndPosition());
933 description.SetCompletion(completion);
934 description.SetVariableType(childVariable.GetType());
935 completions.push_back(description);
940 void AddCompletionsForVariablesMatchingSearch(
943 const ExpressionParserLocation& location,
944 bool eagerlyCompleteIfExactMatch =
false) {
948 ExpressionCompletionDescription description(
949 ExpressionCompletionDescription::Variable,
950 location.GetStartPosition(),
951 location.GetEndPosition());
952 description.SetCompletion(variableName);
953 description.SetVariableType(variable.
GetType());
954 description.SetVariableScope(variablesContainer.GetSourceType());
955 completions.push_back(description);
957 if (eagerlyCompleteIfExactMatch && variableName == search) {
958 AddEagerCompletionForVariableChildren(
959 variable, variableName, location);
964 void AddCompletionsForObjectOrGroupVariablesMatchingSearch(
968 const ExpressionParserLocation& location,
969 bool eagerlyCompleteIfExactMatch) {
974 ExpressionCompletionDescription description(
975 ExpressionCompletionDescription::Variable,
976 location.GetStartPosition(),
977 location.GetEndPosition());
978 description.SetCompletion(variableName);
979 description.SetVariableType(variable.
GetType());
980 description.SetVariableScope(gd::VariablesContainer::Object);
981 completions.push_back(description);
983 if (eagerlyCompleteIfExactMatch && variableName == search) {
984 AddEagerCompletionForVariableChildren(
985 variable, variableName, location);
990 void AddCompletionsForObjectMatchingSearch(
993 const ExpressionParserLocation& location) {
994 projectScopedContainers.GetObjectsContainersList()
995 .ForEachNameMatchingSearch(
999 ExpressionCompletionDescription description(
1000 ExpressionCompletionDescription::Object,
1001 location.GetStartPosition(),
1002 location.GetEndPosition());
1003 description.SetObjectConfiguration(objectConfiguration);
1004 description.SetCompletion(name);
1005 description.SetType(type);
1006 completions.push_back(description);
1010 void AddCompletionsForObjectsAndVariablesMatchingSearch(
1013 const ExpressionParserLocation& location,
1014 bool eagerlyCompleteIfExactMatch) {
1015 projectScopedContainers.ForEachIdentifierMatchingSearch(
1018 const ObjectConfiguration* objectConfiguration) {
1019 ExpressionCompletionDescription description(
1020 ExpressionCompletionDescription::Object,
1021 location.GetStartPosition(),
1022 location.GetEndPosition());
1023 description.SetObjectConfiguration(objectConfiguration);
1024 description.SetCompletion(objectName);
1025 description.SetType(type);
1026 completions.push_back(description);
1029 ExpressionCompletionDescription description(
1030 ExpressionCompletionDescription::Variable,
1031 location.GetStartPosition(),
1032 location.GetEndPosition());
1033 description.SetCompletion(variableName);
1034 description.SetVariableType(variable.
GetType());
1035 description.SetVariableScope(
1036 projectScopedContainers.GetVariablesContainersList()
1037 .GetVariablesContainerFromVariableName(variableName)
1039 completions.push_back(description);
1041 if (eagerlyCompleteIfExactMatch && variableName == search) {
1042 AddEagerCompletionForVariableChildren(
1043 variable, variableName, location);
1054 void AddCompletionsForAllIdentifiersMatchingSearch(
const gd::String& search,
1056 AddCompletionsForAllIdentifiersMatchingSearch(
1059 ExpressionParserLocation(searchedPosition + 1, searchedPosition + 1));
1062 void AddCompletionsForAllIdentifiersMatchingSearch(
1065 const ExpressionParserLocation& location,
1066 bool eagerlyCompleteIfExactMatch =
false) {
1067 projectScopedContainers.ForEachIdentifierMatchingSearch(
1070 const ObjectConfiguration *objectConfiguration) {
1071 ExpressionCompletionDescription description(
1072 ExpressionCompletionDescription::Object,
1073 location.GetStartPosition(),
1074 location.GetEndPosition());
1075 description.SetObjectConfiguration(objectConfiguration);
1076 description.SetCompletion(objectName);
1077 description.SetType(type);
1078 completions.push_back(description);
1081 ExpressionCompletionDescription description(
1082 ExpressionCompletionDescription::Variable,
1083 location.GetStartPosition(),
1084 location.GetEndPosition());
1085 description.SetCompletion(variableName);
1086 description.SetVariableType(variable.
GetType());
1087 description.SetVariableScope(
1088 projectScopedContainers.GetVariablesContainersList()
1089 .GetVariablesContainerFromVariableName(variableName)
1091 completions.push_back(description);
1093 if (eagerlyCompleteIfExactMatch && variableName == search) {
1094 AddEagerCompletionForVariableChildren(
1095 variable, variableName, location);
1100 property.GetType());
1103 ExpressionCompletionDescription description(
1104 ExpressionCompletionDescription::Property,
1105 location.GetStartPosition(), location.GetEndPosition());
1106 description.SetCompletion(property.GetName());
1107 description.SetType(property.GetType());
1108 completions.push_back(description);
1112 if (parameter.GetValueTypeMetadata().IsNumber() ||
1113 parameter.GetValueTypeMetadata().IsString()) {
1114 ExpressionCompletionDescription description(
1115 ExpressionCompletionDescription::Parameter,
1116 location.GetStartPosition(), location.GetEndPosition());
1117 description.SetCompletion(parameter.GetName());
1118 description.SetType(parameter.GetType());
1119 completions.push_back(description);
1124 ExpressionCompletionFinder(
1128 size_t searchedPosition_,
1130 : searchedPosition(searchedPosition_),
1131 maybeParentNodeAtLocation(maybeParentNodeAtLocation_),
1132 platform(platform_),
1133 projectScopedContainers(projectScopedContainers_),
1134 rootType(rootType_),
1139 std::vector<ExpressionCompletionDescription> completions;
1140 size_t searchedPosition;
Returns the list of completion descriptions for an expression node.
Definition: ExpressionCompletionFinder.h:370
const std::vector< ExpressionCompletionDescription > & GetCompletionDescriptions()
Return the completions found for the visited node.
Definition: ExpressionCompletionFinder.h:407
static std::vector< ExpressionCompletionDescription > GetCompletionDescriptionsFor(const gd::Platform &platform, const gd::ProjectScopedContainers &projectScopedContainers, const gd::String &rootType, gd::ExpressionNode &node, size_t searchedPosition)
Given the expression, find the node at the specified location and returns completions for it.
Definition: ExpressionCompletionFinder.h:377
Find the deepest node at the specified location in an expression.
Definition: ExpressionNodeLocationFinder.h:30
ExpressionNode * GetParentNode()
Return the parent of deepest node found at the search position, if any.
Definition: ExpressionNodeLocationFinder.h:74
ExpressionNode * GetNode()
Return the deepest node found at the search position, if any.
Definition: ExpressionNodeLocationFinder.h:68
static size_t WrittenParametersFirstIndex(const gd::String &objectName, const gd::String &behaviorName)
Definition: ExpressionParser2.h:73
The interface for any worker class ("visitor" pattern) that want to interact with the nodes of a pars...
Definition: ExpressionParser2NodeWorker.h:36
static const gd::String GetType(const gd::Platform &platform, const gd::ProjectScopedContainers &projectScopedContainers, const gd::String &rootType, gd::ExpressionNode &node)
Helper function to find the type of the expression or sub-expression that a given node represents.
Definition: ExpressionTypeFinder.h:52
const gd::String & GetObjectName()
Get all the errors.
Definition: ExpressionVariableOwnerFinder.h:75
Used to describe a property shown in a property grid.
Definition: NamedPropertyDescriptor.h:21
Base class used to represent an object configuration. For example, this can be the animations in a sp...
Definition: ObjectConfiguration.h:38
Represent an object of a platform.
Definition: Object.h:37
A list of objects containers, useful for accessing objects in a scoped way, along with methods to acc...
Definition: ObjectsContainersList.h:29
void ForEachObjectOrGroupVariableMatchingSearch(const gd::String &objectOrGroupName, const gd::String &search, std::function< void(const gd::String &variableName, const gd::Variable &variable)> fn) const
Call the callback for each variable of the object (or group) matching the search passed in parameter.
Definition: ObjectsContainersList.cpp:274
Holds references to variables, objects, properties and other containers.
Definition: ProjectScopedContainers.h:34
String represents an UTF8 encoded string.
Definition: String.h:33
static String From(T value)
Method to create a gd::String from a number (float, double, int, ...)
Definition: String.h:221
void push_back(value_type character)
Add a character (from its codepoint) at the end of the String.
Definition: String.cpp:223
bool empty() const
Returns true if the string is empty.
Definition: String.h:157
Defines a variable which can be used by an object, a layout or a project.
Definition: Variable.h:29
Type
Definition: Variable.h:32
Variable & GetChild(const gd::String &name)
Return the child with the specified name.
Definition: Variable.cpp:148
Type GetType() const
Get the type of the variable.
Definition: Variable.h:64
std::vector< gd::String > GetAllChildrenNames() const
Get the names of all children.
Definition: Variable.cpp:358
Class defining a container for gd::Variable.
Definition: VariablesContainer.h:28
void ForEachVariableMatchingSearch(const gd::String &search, std::function< void(const gd::String &name, const gd::Variable &variable)> fn) const
Call the callback for each variable with a name matching the specified search.
Definition: VariablesContainer.cpp:170
bool IsAllowedInIdentifier(gd::String::value_type character)
Definition: GrammarTerminals.h:99
Definition: CommonTools.h:24
std::ostream & operator<<(std::ostream &os, ExpressionCompletionDescription const &value)
Turn an ExpressionCompletionDescription to a string.
Definition: ExpressionCompletionFinder.cpp:19
Describe completions to be shown to the user.
Definition: ExpressionCompletionFinder.h:40
const gd::String & GetCompletion() const
Return the completion that must be inserted.
Definition: ExpressionCompletionFinder.h:175
const gd::String & GetPrefix() const
Return the prefix that must be completed.
Definition: ExpressionCompletionFinder.h:165
bool operator==(const ExpressionCompletionDescription &other) const
Definition: ExpressionCompletionFinder.h:117
ExpressionCompletionDescription()
Definition: ExpressionCompletionFinder.h:323
bool IsExact() const
Check if the completion description is exact, i.e: it's not used to complete anything....
Definition: ExpressionCompletionFinder.h:225
const gd::String & GetObjectName() const
Return the object name, if completing an object expression or a behavior.
Definition: ExpressionCompletionFinder.h:187
ExpressionCompletionDescription & SetObjectConfiguration(const gd::ObjectConfiguration *objectConfiguration_)
Set the object configuration, in the case the completion is about an object.
Definition: ExpressionCompletionFinder.h:281
ExpressionCompletionDescription & SetParameterMetadata(const gd::ParameterMetadata ¶meterMetadata_)
Set the parameter metadata, in the case the completion is about a parameter of a function call.
Definition: ExpressionCompletionFinder.h:256
gd::VariablesContainer::SourceType GetVariableScope() const
Return the scope of the variable, for a variable completion.
Definition: ExpressionCompletionFinder.h:152
static ExpressionCompletionDescription ForBehaviorWithPrefix(const gd::String &prefix_, size_t replacementStartPosition_, size_t replacementEndPosition_, const gd::String &objectName_)
Create a completion for a behavior with the given prefix, for the specified object.
Definition: ExpressionCompletionFinder.h:62
bool HasParameterMetadata() const
Check if the completion is about a parameter of a function call.
Definition: ExpressionCompletionFinder.h:265
ExpressionCompletionDescription & SetIsLastParameter(bool isLastParameter_)
Set if the expression is the last child of a function call.
Definition: ExpressionCompletionFinder.h:242
const gd::ObjectConfiguration & GetObjectConfiguration() const
Return the parameter metadata, if the completion is about a object. Returns an empty configuration ot...
Definition: ExpressionCompletionFinder.h:299
CompletionKind
Definition: ExpressionCompletionFinder.h:48
size_t GetReplacementStartPosition() const
Return the first character index of the autocompleted part.
Definition: ExpressionCompletionFinder.h:230
const gd::String & GetBehaviorName() const
Return the behavior name, if completing an object behavior expression.
Definition: ExpressionCompletionFinder.h:202
gd::Variable::Type GetVariableType() const
Return the type of the variable, for a variable completion.
Definition: ExpressionCompletionFinder.h:141
size_t GetReplacementEndPosition() const
Return the first character index after the autocompleted part.
Definition: ExpressionCompletionFinder.h:237
static ExpressionCompletionDescription ForTextWithPrefix(const gd::String &type_, const gd::ParameterMetadata ¶meterMetadata_, const gd::String &prefix_, size_t replacementStartPosition_, size_t replacementEndPosition_, const bool isLastParameter_, const gd::String &objectName_="")
Create a completion for a text with the given prefix.
Definition: ExpressionCompletionFinder.h:77
CompletionKind GetCompletionKind() const
Return the kind of the completion.
Definition: ExpressionCompletionFinder.h:125
const gd::String & GetType() const
Return the type of the completion (same type as types supported in expressions). For properties,...
Definition: ExpressionCompletionFinder.h:131
ExpressionCompletionDescription & SetIsExact(bool isExact_)
Set if the completion description is exact, i.e: it's not used to complete anything....
Definition: ExpressionCompletionFinder.h:215
bool HasObjectConfiguration() const
Check if the completion is about an object.
Definition: ExpressionCompletionFinder.h:291
static ExpressionCompletionDescription ForExpressionWithPrefix(const gd::String &type_, const gd::String &prefix_, size_t replacementStartPosition_, size_t replacementEndPosition_, const gd::String &objectName_="", const gd::String &behaviorName_="")
Create a completion for an expression (free, object or behavior expression) with the given prefix.
Definition: ExpressionCompletionFinder.h:99
const gd::ParameterMetadata & GetParameterMetadata() const
Return the parameter metadata, if the completion is about a parameter of a function call....
Definition: ExpressionCompletionFinder.h:273
bool IsLastParameter() const
Check if the expression is the last child of a function call.
Definition: ExpressionCompletionFinder.h:250
The base node, from which all nodes in the tree of an expression inherits from.
Definition: ExpressionParser2Node.h:100