Skip to content

Commit

Permalink
Fix a crash when searching instructions after extension are re-generated
Browse files Browse the repository at this point in the history
  • Loading branch information
4ian committed Feb 6, 2025
1 parent 76c0990 commit 9da450b
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,10 @@ export class InstructionTreeViewItemContent implements TreeViewItemContent {
return {
instructionType: this.instructionMetadata.type.replace(/:/g, '-'),
object: this.instructionMetadata.scope.objectMetadata
? this.instructionMetadata.scope.objectMetadata
.getName()
.replace(/:/g, '-') + '-'
? this.instructionMetadata.scope.objectMetadata.name.replace(
/:/g,
'-'
) + '-'
: undefined,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const getInstructionListItemKey = (
) =>
`instruction-key-${instruction.fullGroupName}${
instruction.scope.objectMetadata
? '-' + instruction.scope.objectMetadata.getName()
? '-' + instruction.scope.objectMetadata.name
: ''
}-${instruction.type}`;

Expand All @@ -52,8 +52,9 @@ export const getInstructionOrExpressionIdentifier = (
): string =>
`instruction-or-expression-${
instructionOrExpressionMetadata.scope.objectMetadata
? instructionOrExpressionMetadata.scope.objectMetadata
.getName()
.replace(/:/g, '-') + '-'
? instructionOrExpressionMetadata.scope.objectMetadata.name.replace(
/:/g,
'-'
) + '-'
: ''
}${instructionOrExpressionMetadata.type.replace(/:/g, '-')}`;
7 changes: 4 additions & 3 deletions newIDE/app/src/EventsSheet/InstructionEditor/TreeViewItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,10 @@ export class InstructionTreeViewItemContent implements TreeViewItemContent {
return {
instructionType: this.instructionMetadata.type.replace(/:/g, '-'),
object: this.instructionMetadata.scope.objectMetadata
? this.instructionMetadata.scope.objectMetadata
.getName()
.replace(/:/g, '-') + '-'
? this.instructionMetadata.scope.objectMetadata.name.replace(
/:/g,
'-'
) + '-'
: undefined,
};
}
Expand Down
34 changes: 29 additions & 5 deletions newIDE/app/src/InstructionOrExpression/EnumerateExpressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const enumerateFreeExpressions = (
mapVector(allExtensions, extension => {
const prefix = getExtensionPrefix(extension, i18n);
const scope = {
extension,
extension: { name: extension.getName() },
objectMetadata: undefined,
behaviorMetadata: undefined,
};
Expand Down Expand Up @@ -100,7 +100,13 @@ export const enumerateObjectExpressions = (
);
const extension = extensionAndObjectMetadata.getExtension();
const objectMetadata = extensionAndObjectMetadata.getMetadata();
const scope = { extension, objectMetadata };
const scope = {
extension: { name: extension.getName() },
objectMetadata: {
name: objectMetadata.getName(),
isPrivate: objectMetadata.isPrivate(),
},
};

let objectsExpressions = [
...(shouldOnlyBeNumberType(type)
Expand Down Expand Up @@ -156,7 +162,13 @@ export const enumerateBehaviorExpressions = (
);
const extension = extensionAndBehaviorMetadata.getExtension();
const behaviorMetadata = extensionAndBehaviorMetadata.getMetadata();
const scope = { extension, behaviorMetadata };
const scope = {
extension: { name: extension.getName() },
behaviorMetadata: {
name: behaviorMetadata.getName(),
isPrivate: behaviorMetadata.isPrivate(),
},
};

return [
...(shouldOnlyBeNumberType(type)
Expand Down Expand Up @@ -192,7 +204,13 @@ export const enumerateAllExpressions = (
//Objects expressions:
mapVector(extension.getExtensionObjectsTypes(), objectType => {
const objectMetadata = extension.getObjectMetadata(objectType);
const scope = { extension, objectMetadata };
const scope = {
extension: { name: extension.getName() },
objectMetadata: {
name: objectMetadata.getName(),
isPrivate: objectMetadata.isPrivate(),
},
};

if (!shouldOnlyBeNumberType(type))
objectsExpressions.push.apply(
Expand All @@ -216,7 +234,13 @@ export const enumerateAllExpressions = (
//Behaviors expressions:
mapVector(extension.getBehaviorsTypes(), behaviorType => {
const behaviorMetadata = extension.getBehaviorMetadata(behaviorType);
const scope = { extension, behaviorMetadata };
const scope = {
extension: { name: extension.getName() },
behaviorMetadata: {
name: behaviorMetadata.getName(),
isPrivate: behaviorMetadata.isPrivate(),
},
};

if (!shouldOnlyBeNumberType(type))
behaviorsExpressions.push.apply(
Expand Down
46 changes: 38 additions & 8 deletions newIDE/app/src/InstructionOrExpression/EnumerateInstructions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { translateExtensionCategory } from '../Utils/Extension/ExtensionCategori

const gd: libGDevelop = global.gd;

const GROUP_DELIMITER = '/';
const GROUP_DELIMITER = '';

const freeInstructionsToKeep = {
BuiltinObject: [
Expand Down Expand Up @@ -360,7 +360,7 @@ export const enumerateAllInstructions = (
prefix,
isCondition ? extension.getAllConditions() : extension.getAllActions(),
{
extension,
extension: { name: extension.getName() },
objectMetadata: undefined,
behaviorMetadata: undefined,
},
Expand All @@ -372,7 +372,13 @@ export const enumerateAllInstructions = (
for (let j = 0; j < allObjectsTypes.size(); ++j) {
const objectType = allObjectsTypes.at(j);
const objectMetadata = extension.getObjectMetadata(objectType);
const scope = { extension, objectMetadata };
const scope = {
extension: { name: extension.getName() },
objectMetadata: {
name: objectMetadata.getName(),
isPrivate: objectMetadata.isPrivate(),
},
};
allInstructions = [
...allInstructions,
...enumerateExtensionInstructions(
Expand All @@ -390,7 +396,13 @@ export const enumerateAllInstructions = (
for (let j = 0; j < allBehaviorsTypes.size(); ++j) {
const behaviorType = allBehaviorsTypes.at(j);
const behaviorMetadata = extension.getBehaviorMetadata(behaviorType);
const scope = { extension, behaviorMetadata };
const scope = {
extension: { name: extension.getName() },
behaviorMetadata: {
name: behaviorMetadata.getName(),
isPrivate: behaviorMetadata.isPrivate(),
},
};

allInstructions = [
...allInstructions,
Expand Down Expand Up @@ -468,7 +480,13 @@ export const enumerateObjectAndBehaviorsInstructions = (
);
const extension = extensionAndObjectMetadata.getExtension();
const objectMetadata = extensionAndObjectMetadata.getMetadata();
const scope = { extension, objectMetadata };
const scope = {
extension: { name: extension.getName() },
objectMetadata: {
name: objectMetadata.getName(),
isPrivate: objectMetadata.isPrivate(),
},
};
const prefix = '';

// Free instructions
Expand All @@ -490,7 +508,13 @@ export const enumerateObjectAndBehaviorsInstructions = (
.getAllPlatformExtensions();
for (let i = 0; i < allExtensions.size(); ++i) {
const extension = allExtensions.at(i);
const scope = { extension, objectMetadata };
const scope = {
extension: { name: extension.getName() },
objectMetadata: {
name: objectMetadata.getName(),
isPrivate: objectMetadata.isPrivate(),
},
};

allInstructions = [
...allInstructions,
Expand Down Expand Up @@ -538,7 +562,13 @@ export const enumerateObjectAndBehaviorsInstructions = (
// eslint-disable-next-line
behaviorTypes.forEach(behaviorType => {
const behaviorMetadata = extension.getBehaviorMetadata(behaviorType);
const scope = { extension, behaviorMetadata };
const scope = {
extension: { name: extension.getName() },
behaviorMetadata: {
name: behaviorMetadata.getName(),
isPrivate: behaviorMetadata.isPrivate(),
},
};

// Free functions can require a behavior even if this behavior is from
// another extension.
Expand Down Expand Up @@ -613,7 +643,7 @@ export const enumerateFreeInstructions = (
isCondition,
extension,
{
extension,
extension: { name: extension.getName() },
objectMetadata: undefined,
behaviorMetadata: undefined,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@ import { type EventsScope } from './EventsScope';
const gd: libGDevelop = global.gd;

export type InstructionOrExpressionScope = {|
extension: gdPlatformExtension,
objectMetadata?: ?gdObjectMetadata,
behaviorMetadata?: ?gdBehaviorMetadata,
extension: {
name: string,
},
objectMetadata?: ?{
name: string,
isPrivate: boolean,
},
behaviorMetadata?: ?{
name: string,
isPrivate: boolean,
},
|};

export type EnumeratedInstructionMetadata = {|
Expand Down Expand Up @@ -93,8 +101,8 @@ const isFunctionVisibleInGivenScope = (
eventsBasedObject)) &&
// Check visibility.
((!enumeratedInstructionOrExpressionMetadata.isPrivate &&
(!behaviorMetadata || !behaviorMetadata.isPrivate()) &&
(!objectMetadata || !objectMetadata.isPrivate())) ||
(!behaviorMetadata || !behaviorMetadata.isPrivate) &&
(!objectMetadata || !objectMetadata.isPrivate)) ||
// The instruction or expression is marked as "private":
// we now compare its scope (where it was declared) and the current scope
// (where we are) to see if we should filter it or not.
Expand All @@ -106,17 +114,17 @@ const isFunctionVisibleInGivenScope = (
gd.PlatformExtension.getBehaviorFullType(
eventsFunctionsExtension.getName(),
eventsBasedBehavior.getName()
) === behaviorMetadata.getName()) ||
) === behaviorMetadata.name) ||
(objectMetadata &&
eventsBasedObject &&
eventsFunctionsExtension &&
gd.PlatformExtension.getObjectFullType(
eventsFunctionsExtension.getName(),
eventsBasedObject.getName()
) === objectMetadata.getName()) ||
) === objectMetadata.name) ||
// When editing the extension...
(eventsFunctionsExtension &&
eventsFunctionsExtension.getName() === extension.getName() &&
eventsFunctionsExtension.getName() === extension.name &&
// ...show public functions of a private behavior
(!enumeratedInstructionOrExpressionMetadata.isPrivate ||
// ...show private non-behavior functions
Expand Down
6 changes: 5 additions & 1 deletion newIDE/app/src/fixtures/TestExpressionAutocompletions.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ const makeFakeEnumeratedExpressionMetadata = (
parameterIndex =>
expressionMetadata.getParameters().getParameterAt(parameterIndex)
),
scope: { extension },
scope: {
extension: {
name: extension.getName(),
},
},
isPrivate: false,
isRelevantForLayoutEvents: true,
isRelevantForFunctionEvents: true,
Expand Down

0 comments on commit 9da450b

Please sign in to comment.