Skip to content

Commit 903cff3

Browse files
committed
fix add Constructor interfaces in description namespace
1 parent c5e5cf7 commit 903cff3

File tree

1 file changed

+40
-38
lines changed

1 file changed

+40
-38
lines changed

rostsd_gen/index.js

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,16 @@ function generateRosMsgInterfaces(
232232
fd,
233233
descriptorInterfaceType = false
234234
) {
235+
const descriptorNamespaceName = descriptorInterfaceType
236+
? `${descriptorInterfaceNamespace}/`
237+
: '';
238+
const descriptorNamespacePath = descriptorInterfaceType
239+
? `${descriptorInterfaceNamespace}.`
240+
: '';
235241
for (const rosInterface of pkgInfo.subfolders.get(subfolder)) {
236242
const type = rosInterface.type();
237-
const fullInterfaceName = `${type.pkgName}/${type.subFolder}/${type.interfaceName}`;
238-
const fullInterfacePath = `${type.pkgName}.${type.subFolder}.${type.interfaceName}`;
243+
const fullInterfaceName = `${type.pkgName}/${type.subFolder}/${descriptorNamespaceName}${type.interfaceName}`;
244+
const fullInterfacePath = `${type.pkgName}.${type.subFolder}.${descriptorNamespacePath}${type.interfaceName}`;
239245
const fullInterfaceConstructor = fullInterfacePath + 'Constructor';
240246

241247
if (isMsgInterface(rosInterface)) {
@@ -371,54 +377,50 @@ function saveMsgConstructorAsTSD(
371377
) {
372378
const type = rosMsgInterface.type();
373379
const msgName = type.interfaceName;
374-
if (!descriptorInterfaceType) {
375-
fs.writeSync(fd, ` export interface ${msgName}Constructor {\n`);
380+
let interfaceTmpl = [`export interface ${msgName}Constructor {`];
376381

377-
for (const constant of rosMsgInterface.ROSMessageDef.constants) {
378-
const constantType = primitiveType2JSName(constant.type);
379-
fs.writeSync(fd, ` readonly ${constant.name}: ${constantType};\n`);
380-
}
381-
382-
fs.writeSync(fd, ` new(other?: ${msgName}): ${msgName};\n`);
383-
fs.writeSync(fd, ' }\n');
382+
for (const constant of rosMsgInterface.ROSMessageDef.constants) {
383+
const constantType = primitiveType2JSName(constant.type);
384+
interfaceTmpl.push(` readonly ${constant.name}: ${constantType};`);
384385
}
386+
interfaceTmpl.push(` new(other?: ${msgName}): ${msgName};`);
387+
interfaceTmpl.push('}');
388+
interfaceTmpl.push('');
389+
const indentLevel = descriptorInterfaceType ? 8 : 6;
390+
fs.writeSync(fd, indentLines(interfaceTmpl, indentLevel).join('\n'));
385391
}
386392

387393
function saveSrvAsTSD(rosSrvInterface, fd, descriptorInterfaceType = false) {
388-
if (!descriptorInterfaceType) {
389-
const serviceName = rosSrvInterface.type().interfaceName;
390-
391-
const interfaceTemplate = [
392-
`export interface ${serviceName}Constructor extends ROSService {`,
393-
` readonly Request: ${serviceName}_RequestConstructor;`,
394-
` readonly Response: ${serviceName}_ResponseConstructor;`,
395-
'}',
396-
'',
397-
];
398-
const indentLevel = 6;
399-
fs.writeSync(fd, indentLines(interfaceTemplate, indentLevel).join('\n'));
400-
}
394+
const serviceName = rosSrvInterface.type().interfaceName;
395+
396+
const interfaceTemplate = [
397+
`export interface ${serviceName}Constructor extends ROSService {`,
398+
` readonly Request: ${serviceName}_RequestConstructor;`,
399+
` readonly Response: ${serviceName}_ResponseConstructor;`,
400+
'}',
401+
'',
402+
];
403+
const indentLevel = descriptorInterfaceType ? 8 : 6;
404+
fs.writeSync(fd, indentLines(interfaceTemplate, indentLevel).join('\n'));
401405
}
402406

403407
function saveActionAsTSD(
404408
rosActionInterface,
405409
fd,
406410
descriptorInterfaceType = false
407411
) {
408-
if (!descriptorInterfaceType) {
409-
const actionName = rosActionInterface.type().interfaceName;
410-
411-
const interfaceTemplate = [
412-
`export interface ${actionName}Constructor {`,
413-
` readonly Goal: ${actionName}_GoalConstructor;`,
414-
` readonly Result: ${actionName}_ResultConstructor;`,
415-
` readonly Feedback: ${actionName}_FeedbackConstructor;`,
416-
'}',
417-
'',
418-
];
419-
const indentLevel = 6;
420-
fs.writeSync(fd, indentLines(interfaceTemplate, indentLevel).join('\n'));
421-
}
412+
const actionName = rosActionInterface.type().interfaceName;
413+
414+
const interfaceTemplate = [
415+
`export interface ${actionName}Constructor {`,
416+
` readonly Goal: ${actionName}_GoalConstructor;`,
417+
` readonly Result: ${actionName}_ResultConstructor;`,
418+
` readonly Feedback: ${actionName}_FeedbackConstructor;`,
419+
'}',
420+
'',
421+
];
422+
const indentLevel = descriptorInterfaceType ? 8 : 6;
423+
fs.writeSync(fd, indentLines(interfaceTemplate, indentLevel).join('\n'));
422424
}
423425

424426
function isMsgInterface(rosInterface) {

0 commit comments

Comments
 (0)