Skip to content

Commit

Permalink
fix: better meta suffix guesses
Browse files Browse the repository at this point in the history
  • Loading branch information
iowillhoit committed May 8, 2023
1 parent a301b8e commit 6c5d1b9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion messages/sdr.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ The uniqueIdElement %s was not found the child (reading %s at %s).

# suggest_type_header

A search for the %s suffix found the following close matches:
A metadata type lookup for "%s" found the following close matches:

# suggest_type_did_you_mean

Expand Down
22 changes: 14 additions & 8 deletions src/resolve/metadataResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,22 +262,28 @@ export class MetadataResolver {
private getSuggestionsForUnresolvedTypes(fsPath: string): string[] {
const parsedMetaXml = parseMetadataXml(fsPath);
const metaSuffix = parsedMetaXml?.suffix;
// Finds close matches for meta suffixes
// Examples: https://regex101.com/r/vbRjwy/1
const closeMetaSuffix = new RegExp(/.+\.([^.-]+)(?:-.*)?\.xml/).exec(basename(fsPath));

// Analogous to "attempt 2" and "attempt 3" above
const guesses = metaSuffix
? this.registry.guessTypeBySuffix(metaSuffix)
: this.registry.guessTypeBySuffix(extName(fsPath));
let guesses;

if (metaSuffix) {
guesses = this.registry.guessTypeBySuffix(metaSuffix)
} else if (!metaSuffix && closeMetaSuffix) {
guesses = this.registry.guessTypeBySuffix(closeMetaSuffix[1]);
} else {
this.registry.guessTypeBySuffix(extName(fsPath));
}

// If guesses were found, format an array of strings to be passed to SfError's actions
return guesses && guesses.length > 0
? [
messages.getMessage('suggest_type_header', [
metaSuffix ? `".${parsedMetaXml.suffix}-meta.xml" metadata` : `".${extName(fsPath)}" filename`,
]),
messages.getMessage('suggest_type_header', [ basename(fsPath) ]),
...guesses.map((guess) =>
messages.getMessage('suggest_type_did_you_mean', [
guess.suffixGuess,
metaSuffix ? '-meta.xml' : '',
(metaSuffix || closeMetaSuffix) ? '-meta.xml' : '',
guess.metadataTypeGuess.name,
])
),
Expand Down

2 comments on commit 6c5d1b9

@svc-cli-bot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 6c5d1b9 Previous: 3c2fcf5 Ratio
eda-componentSetCreate-linux 313 ms 316 ms 0.99
eda-sourceToMdapi-linux 7080 ms 7946 ms 0.89
eda-sourceToZip-linux 6110 ms 6023 ms 1.01
eda-mdapiToSource-linux 5284 ms 5382 ms 0.98
lotsOfClasses-componentSetCreate-linux 563 ms 611 ms 0.92
lotsOfClasses-sourceToMdapi-linux 10949 ms 11012 ms 0.99
lotsOfClasses-sourceToZip-linux 8086 ms 8815 ms 0.92
lotsOfClasses-mdapiToSource-linux 6608 ms 6663 ms 0.99
lotsOfClassesOneDir-componentSetCreate-linux 917 ms 1057 ms 0.87
lotsOfClassesOneDir-sourceToMdapi-linux 15280 ms 16405 ms 0.93
lotsOfClassesOneDir-sourceToZip-linux 12803 ms 12898 ms 0.99
lotsOfClassesOneDir-mdapiToSource-linux 12024 ms 12013 ms 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 6c5d1b9 Previous: 3c2fcf5 Ratio
eda-componentSetCreate-win32 482 ms 398 ms 1.21
eda-sourceToMdapi-win32 8897 ms 8654 ms 1.03
eda-sourceToZip-win32 6126 ms 6086 ms 1.01
eda-mdapiToSource-win32 9808 ms 8129 ms 1.21
lotsOfClasses-componentSetCreate-win32 1082 ms 842 ms 1.29
lotsOfClasses-sourceToMdapi-win32 12923 ms 11220 ms 1.15
lotsOfClasses-sourceToZip-win32 8574 ms 8021 ms 1.07
lotsOfClasses-mdapiToSource-win32 11478 ms 9596 ms 1.20
lotsOfClassesOneDir-componentSetCreate-win32 1873 ms 1562 ms 1.20
lotsOfClassesOneDir-sourceToMdapi-win32 22093 ms 19147 ms 1.15
lotsOfClassesOneDir-sourceToZip-win32 14655 ms 12569 ms 1.17
lotsOfClassesOneDir-mdapiToSource-win32 20747 ms 17364 ms 1.19

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.