-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
handle duplicate types #45
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,11 @@ | |
// found at http://www.apache.org/licenses/LICENSE-2.0 | ||
// You may not use this file except in compliance with the License. | ||
|
||
import { MessageDefinition, MessageDefinitionField } from "@foxglove/message-definition"; | ||
import { | ||
MessageDefinition, | ||
MessageDefinitionField, | ||
isMsgDefEqual, | ||
} from "@foxglove/message-definition"; | ||
import { Grammar, Parser } from "nearley"; | ||
|
||
import { buildRos2Type } from "./buildRos2Type"; | ||
|
@@ -76,12 +80,21 @@ export function parse(messageDefinition: string, options: ParseOptions = {}): Me | |
: buildType(definitionLines, ROS1_GRAMMAR), | ||
); | ||
|
||
// Filter out duplicate types. | ||
// This will avoid that searching a type by name will return more than one result. | ||
const seenTypes: MessageDefinition[] = []; | ||
const uniqueTypes = types.filter((definition) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are we deduping instead of making the search function able to return multiple or return the first that matches? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 - seems weird to me that we would have duplicate types. At least it seems like we should confirm they are identical and throw an error if not (or always throw an error) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Turns out that duplicates were erroneously produced by |
||
return seenTypes.find((otherDefinition) => isMsgDefEqual(definition, otherDefinition)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this deduplication as performant as it could be or as performant as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Probably not. OK to add lodash as a dependency? If so then I'll change it to use `_.uniqBy There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please not add a dependency to this project for a bug fix? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I'd avoid adding the dep. Just wanted to see if we could get this down to a single iteration through the types, but it's not strictly necessary |
||
? false | ||
: seenTypes.push(definition); // Always evaluates to true; | ||
}); | ||
|
||
// Fix up complex type names | ||
if (options.skipTypeFixup !== true) { | ||
fixupTypes(types); | ||
fixupTypes(uniqueTypes); | ||
} | ||
|
||
return types; | ||
return uniqueTypes; | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be helpful to add some historical context about
mcap convert
, to explain why we shouldn't delete this code