Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
340 changes: 177 additions & 163 deletions Core/GDCore/IDE/Events/ExpressionCompletionFinder.h

Large diffs are not rendered by default.

33 changes: 18 additions & 15 deletions Core/GDCore/IDE/Events/ExpressionTypeFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class GD_CORE_API ExpressionTypeFinder : public ExpressionParser2NodeWorker {
const gd::String &rootType,
gd::ExpressionNode& node) {
gd::ExpressionTypeFinder typeFinder(
platform, projectScopedContainers, rootType);
platform, projectScopedContainers, rootType, emptyExtraInfo);
node.Visit(typeFinder);
return typeFinder.GetType();
}
Expand All @@ -70,9 +70,10 @@ class GD_CORE_API ExpressionTypeFinder : public ExpressionParser2NodeWorker {
static const gd::TypeAndExtraInfo GetTypeAndExtraInfo(
const gd::Platform &platform,
const gd::ProjectScopedContainers &projectScopedContainers,
const gd::String &rootType, gd::ExpressionNode &node) {
const gd::String &rootType, const gd::String &rootExtraInfo,
gd::ExpressionNode &node) {
gd::ExpressionTypeFinder typeFinder(platform, projectScopedContainers,
rootType);
rootType, rootExtraInfo);
node.Visit(typeFinder);
return {.type = typeFinder.GetType(),
.extraInfo = typeFinder.GetExtraInfo()};
Expand All @@ -81,18 +82,17 @@ class GD_CORE_API ExpressionTypeFinder : public ExpressionParser2NodeWorker {
virtual ~ExpressionTypeFinder(){};

protected:
ExpressionTypeFinder(const gd::Platform &platform_,
const gd::ProjectScopedContainers &projectScopedContainers_,
const gd::String &rootType_)
: platform(platform_),
projectScopedContainers(projectScopedContainers_),
rootType(rootType_),
type(ExpressionTypeFinder::unknownType),
child(nullptr) {};

const gd::String &GetType() {
return gd::ValueTypeMetadata::GetExpressionPrimitiveValueType(type);
};
ExpressionTypeFinder(
const gd::Platform &platform_,
const gd::ProjectScopedContainers &projectScopedContainers_,
const gd::String &rootType_, const gd::String &rootExtraInfo_)
: platform(platform_), projectScopedContainers(projectScopedContainers_),
rootType(rootType_), rootExtraInfo(rootExtraInfo_),
type(ExpressionTypeFinder::unknownType), child(nullptr) {};

const gd::String &GetType() {
return gd::ValueTypeMetadata::GetExpressionPrimitiveValueType(type);
};

const gd::String &GetExtraInfo() {
return extraInfo;
Expand Down Expand Up @@ -194,10 +194,12 @@ class GD_CORE_API ExpressionTypeFinder : public ExpressionParser2NodeWorker {
}
else {
type = rootType;
extraInfo = rootExtraInfo;
}
}
else {
type = rootType;
extraInfo = rootExtraInfo;
}
}

Expand All @@ -215,6 +217,7 @@ class GD_CORE_API ExpressionTypeFinder : public ExpressionParser2NodeWorker {
const gd::Platform &platform;
const gd::ProjectScopedContainers &projectScopedContainers;
const gd::String rootType;
const gd::String rootExtraInfo;
};

} // namespace gd
Expand Down
7 changes: 6 additions & 1 deletion Core/GDCore/IDE/Events/ExpressionVariableOwnerFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ class GD_CORE_API ExpressionVariableOwnerFinder : public ExpressionParser2NodeWo
variableNode = &node;
node.parent->Visit(*this);
}
void OnVisitEmptyNode(EmptyNode& node) override {}
void OnVisitEmptyNode(EmptyNode& node) override {
if (node.parent == nullptr) {
objectName = rootObjectName;
return;
}
}
void OnVisitObjectFunctionNameNode(ObjectFunctionNameNode& node) override {}
void OnVisitVariableBracketAccessorNode(
VariableBracketAccessorNode& node) override {}
Expand Down
5 changes: 5 additions & 0 deletions Core/tests/DummyPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,11 @@ void SetupProjectWithDummyPlatform(gd::Project& project,
"GetVariableAsNumber", "Get me a variable value", "", "", "")
.AddParameter("scenevar", "Scene variable")
.SetFunctionName("returnVariable");
extension
->AddExpression(
"GetGlobalVariableAsNumber", "Get me a variable value", "", "", "")
.AddParameter("globalvar", "Global variable")
.SetFunctionName("returnGlobalVariable");
extension
->AddExpression(
"GetAnyVariableAsNumber", "Get me a variable value", "", "", "")
Expand Down
926 changes: 588 additions & 338 deletions Core/tests/ExpressionCompletionFinder.cpp

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion GDevelop.js/Bindings/Bindings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -3373,7 +3373,14 @@ interface VectorExpressionCompletionDescription {
};

interface ExpressionCompletionFinder {
[Value] VectorExpressionCompletionDescription STATIC_GetCompletionDescriptionsFor([Const, Ref] Platform platform, [Const, Ref] ProjectScopedContainers projectScopedContainers, [Const] DOMString rootType, [Ref] ExpressionNode node, unsigned long location);
[Value] VectorExpressionCompletionDescription STATIC_GetCompletionDescriptionsFor(
[Const, Ref] Platform platform,
[Const, Ref] ProjectScopedContainers projectScopedContainers,
[Const] DOMString rootType,
[Const] DOMString rootExtraInfo,
[Const] DOMString rootObjectName,
[Ref] ExpressionNode node,
unsigned long location);

[Const, Ref] VectorExpressionCompletionDescription GetCompletionDescriptions();

Expand Down
2 changes: 2 additions & 0 deletions GDevelop.js/__tests__/ExpressionCompletionFinder.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ describe('gd.ExpressionCompletionFinder', function () {
gd.JsPlatform.get(),
projectScopedContainers,
type,
'',
'',
expressionNode,
// We're looking for completion for the character just before the caret.
Math.max(0, caretPosition - 1)
Expand Down
2 changes: 1 addition & 1 deletion GDevelop.js/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2423,7 +2423,7 @@ export class VectorExpressionCompletionDescription extends EmscriptenObject {
}

export class ExpressionCompletionFinder extends EmscriptenObject {
static getCompletionDescriptionsFor(platform: Platform, projectScopedContainers: ProjectScopedContainers, rootType: string, node: ExpressionNode, location: number): VectorExpressionCompletionDescription;
static getCompletionDescriptionsFor(platform: Platform, projectScopedContainers: ProjectScopedContainers, rootType: string, rootExtraInfo: string, rootObjectName: string, node: ExpressionNode, location: number): VectorExpressionCompletionDescription;
getCompletionDescriptions(): VectorExpressionCompletionDescription;
}

Expand Down
2 changes: 1 addition & 1 deletion GDevelop.js/types/gdexpressioncompletionfinder.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Automatically generated by GDevelop.js/scripts/generate-types.js
declare class gdExpressionCompletionFinder {
static getCompletionDescriptionsFor(platform: gdPlatform, projectScopedContainers: gdProjectScopedContainers, rootType: string, node: gdExpressionNode, location: number): gdVectorExpressionCompletionDescription;
static getCompletionDescriptionsFor(platform: gdPlatform, projectScopedContainers: gdProjectScopedContainers, rootType: string, rootExtraInfo: string, rootObjectName: string, node: gdExpressionNode, location: number): gdVectorExpressionCompletionDescription;
getCompletionDescriptions(): gdVectorExpressionCompletionDescription;
delete(): void;
ptr: number;
Expand Down
20 changes: 7 additions & 13 deletions newIDE/app/src/EventsSheet/ParameterFields/AnyVariableField.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { type ParameterInlineRendererProps } from './ParameterInlineRenderer.flo
import VariableField, {
getRootVariableName,
renderVariableWithIcon,
type VariableFieldInterface,
} from './VariableField';
import { type VariableDialogOpeningProps } from '../../VariablesList/VariablesEditorDialog';
import GlobalAndSceneVariablesDialog from '../../VariablesList/GlobalAndSceneVariablesDialog';
Expand All @@ -14,14 +13,13 @@ import {
type ParameterFieldInterface,
type FieldFocusFunction,
} from './ParameterFieldCommons';
import { enumerateVariablesOfContainersList } from './EnumerateVariables';
import { mapFor } from '../../Utils/MapFor';

const gd: libGDevelop = global.gd;

export default (React.forwardRef<ParameterFieldProps, ParameterFieldInterface>(
function AnyVariableField(props: ParameterFieldProps, ref) {
const field = React.useRef<?VariableFieldInterface>(null);
const field = React.useRef<?ParameterFieldInterface>(null);
const [
variableEditorOpen,
setVariableEditorOpen,
Expand All @@ -43,14 +41,6 @@ export default (React.forwardRef<ParameterFieldProps, ParameterFieldInterface>(
value,
} = props;

const enumerateGlobalAndSceneVariables = React.useCallback(
() =>
enumerateVariablesOfContainersList(
projectScopedContainersAccessor.get().getVariablesContainersList()
),
[projectScopedContainersAccessor]
);

const variablesContainers = React.useMemo(
() => {
const variablesContainersList = projectScopedContainersAccessor
Expand Down Expand Up @@ -82,7 +72,6 @@ export default (React.forwardRef<ParameterFieldProps, ParameterFieldInterface>(
// The variable editor may have refactor the events for a variable type
// change which may have change the currently edited instruction type.
if (onInstructionTypeChanged) onInstructionTypeChanged();
if (field.current) field.current.updateAutocompletions();
},
[onChange, onInstructionTypeChanged, value]
);
Expand All @@ -106,7 +95,6 @@ export default (React.forwardRef<ParameterFieldProps, ParameterFieldInterface>(
project={project}
instruction={instruction}
variablesContainers={variablesContainers}
enumerateVariables={enumerateGlobalAndSceneVariables}
parameterMetadata={props.parameterMetadata}
value={props.value}
onChange={props.onChange}
Expand All @@ -128,6 +116,12 @@ export default (React.forwardRef<ParameterFieldProps, ParameterFieldInterface>(
getVariableSourceFromIdentifier={getVariableSourceFromIdentifier}
editEventsFunctionParameter={null}
openEventsBasedEntityPropertyEditorDialog={null}
instructionMetadata={props.instructionMetadata}
expression={props.expression}
expressionMetadata={props.expressionMetadata}
parameterIndex={props.parameterIndex}
resourceManagementProps={props.resourceManagementProps}
parameterRenderingService={props.parameterRenderingService}
/>
{variableEditorOpen &&
(variableSourceType === gd.VariablesContainer.Local ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { type ParameterInlineRendererProps } from './ParameterInlineRenderer.flo
import VariableField, {
getRootVariableName,
renderVariableWithIcon,
type VariableFieldInterface,
} from './VariableField';
import { type VariableDialogOpeningProps } from '../../VariablesList/VariablesEditorDialog';
import GlobalAndSceneVariablesDialog from '../../VariablesList/GlobalAndSceneVariablesDialog';
Expand All @@ -14,14 +13,13 @@ import {
type ParameterFieldInterface,
type FieldFocusFunction,
} from './ParameterFieldCommons';
import { enumerateVariablesOrPropertiesOfContainersList } from './EnumerateVariables';
import { mapFor } from '../../Utils/MapFor';

const gd: libGDevelop = global.gd;

export default (React.forwardRef<ParameterFieldProps, ParameterFieldInterface>(
function AnyVariableField(props: ParameterFieldProps, ref) {
const field = React.useRef<?VariableFieldInterface>(null);
const field = React.useRef<?ParameterFieldInterface>(null);
const [
variableEditorOpen,
setVariableEditorOpen,
Expand All @@ -44,14 +42,6 @@ export default (React.forwardRef<ParameterFieldProps, ParameterFieldInterface>(
openEventsBasedEntityPropertyEditorDialog,
} = props;

const enumerateGlobalAndSceneVariables = React.useCallback(
() =>
enumerateVariablesOrPropertiesOfContainersList(
projectScopedContainersAccessor.get().getVariablesContainersList()
),
[projectScopedContainersAccessor]
);

const variablesContainers = React.useMemo(
() => {
const variablesContainersList = projectScopedContainersAccessor
Expand Down Expand Up @@ -81,7 +71,6 @@ export default (React.forwardRef<ParameterFieldProps, ParameterFieldInterface>(
// The variable editor may have refactor the events for a variable type
// change which may have change the currently edited instruction type.
if (onInstructionTypeChanged) onInstructionTypeChanged();
if (field.current) field.current.updateAutocompletions();
},
[onChange, onInstructionTypeChanged, value]
);
Expand All @@ -105,7 +94,6 @@ export default (React.forwardRef<ParameterFieldProps, ParameterFieldInterface>(
project={project}
instruction={instruction}
variablesContainers={variablesContainers}
enumerateVariables={enumerateGlobalAndSceneVariables}
parameterMetadata={props.parameterMetadata}
value={props.value}
onChange={props.onChange}
Expand All @@ -129,6 +117,12 @@ export default (React.forwardRef<ParameterFieldProps, ParameterFieldInterface>(
openEventsBasedEntityPropertyEditorDialog={
openEventsBasedEntityPropertyEditorDialog || null
}
instructionMetadata={props.instructionMetadata}
expression={props.expression}
expressionMetadata={props.expressionMetadata}
parameterIndex={props.parameterIndex}
resourceManagementProps={props.resourceManagementProps}
parameterRenderingService={props.parameterRenderingService}
/>
{variableEditorOpen &&
(variableSourceType === gd.VariablesContainer.Local ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { type ParameterInlineRendererProps } from './ParameterInlineRenderer.flo
import VariableField, {
getRootVariableName,
renderVariableWithIcon,
type VariableFieldInterface,
} from './VariableField';
import { type VariableDialogOpeningProps } from '../../VariablesList/VariablesEditorDialog';
import GlobalAndSceneVariablesDialog from '../../VariablesList/GlobalAndSceneVariablesDialog';
Expand All @@ -14,14 +13,13 @@ import {
type ParameterFieldInterface,
type FieldFocusFunction,
} from './ParameterFieldCommons';
import { enumerateVariablesOrPropertiesOrParametersOfContainersList } from './EnumerateVariables';
import { mapFor } from '../../Utils/MapFor';

const gd: libGDevelop = global.gd;

export default (React.forwardRef<ParameterFieldProps, ParameterFieldInterface>(
function AnyVariableField(props: ParameterFieldProps, ref) {
const field = React.useRef<?VariableFieldInterface>(null);
const field = React.useRef<?ParameterFieldInterface>(null);
const [
variableEditorOpen,
setVariableEditorOpen,
Expand All @@ -45,14 +43,6 @@ export default (React.forwardRef<ParameterFieldProps, ParameterFieldInterface>(
openEventsBasedEntityPropertyEditorDialog,
} = props;

const enumerateGlobalAndSceneVariables = React.useCallback(
() =>
enumerateVariablesOrPropertiesOrParametersOfContainersList(
projectScopedContainersAccessor.get().getVariablesContainersList()
),
[projectScopedContainersAccessor]
);

const variablesContainers = React.useMemo(
() => {
const variablesContainersList = projectScopedContainersAccessor
Expand All @@ -78,7 +68,6 @@ export default (React.forwardRef<ParameterFieldProps, ParameterFieldInterface>(
// The variable editor may have refactor the events for a variable type
// change which may have change the currently edited instruction type.
if (onInstructionTypeChanged) onInstructionTypeChanged();
if (field.current) field.current.updateAutocompletions();
},
[onChange, onInstructionTypeChanged, value]
);
Expand All @@ -102,7 +91,6 @@ export default (React.forwardRef<ParameterFieldProps, ParameterFieldInterface>(
project={project}
instruction={instruction}
variablesContainers={variablesContainers}
enumerateVariables={enumerateGlobalAndSceneVariables}
parameterMetadata={props.parameterMetadata}
value={props.value}
onChange={props.onChange}
Expand All @@ -126,6 +114,12 @@ export default (React.forwardRef<ParameterFieldProps, ParameterFieldInterface>(
openEventsBasedEntityPropertyEditorDialog={
openEventsBasedEntityPropertyEditorDialog || null
}
instructionMetadata={props.instructionMetadata}
expression={props.expression}
expressionMetadata={props.expressionMetadata}
parameterIndex={props.parameterIndex}
resourceManagementProps={props.resourceManagementProps}
parameterRenderingService={props.parameterRenderingService}
/>
{variableEditorOpen &&
(variableSourceType === gd.VariablesContainer.Local ? (
Expand Down
Loading
Loading