-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into devScripts2024-07-28
- Loading branch information
Showing
9 changed files
with
860 additions
and
793 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright (c) 2023, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import { Messages } from '@salesforce/core/messages'; | ||
import * as Levenshtein from 'fast-levenshtein'; | ||
import { MetadataRegistry } from './types'; | ||
|
||
Messages.importMessagesDirectory(__dirname); | ||
const messages = Messages.loadMessages('@salesforce/source-deploy-retrieve', 'sdr'); | ||
|
||
/** "did you mean" for Metadata type names */ | ||
export const getTypeSuggestions = (registry: MetadataRegistry, typeName: string): string[] => { | ||
const scores = getScores( | ||
Object.values(registry.types).map((t) => t.name), | ||
typeName | ||
); | ||
|
||
const guesses = getLowestScores(scores).map((guess) => guess.registryKey); | ||
return [ | ||
...(guesses.length | ||
? [ | ||
`Did you mean one of the following types? [${guesses.join(',')}]`, | ||
'', // Add a blank line for better readability | ||
] | ||
: []), | ||
messages.getMessage('type_name_suggestions'), | ||
]; | ||
}; | ||
|
||
export const getSuffixGuesses = (suffixes: string[], input: string): string[] => { | ||
const scores = getScores(suffixes, input); | ||
return getLowestScores(scores).map((g) => g.registryKey); | ||
}; | ||
|
||
type LevenshteinScore = { | ||
registryKey: string; | ||
score: number; | ||
}; | ||
|
||
const getScores = (choices: string[], input: string): LevenshteinScore[] => | ||
choices.map((registryKey) => ({ | ||
registryKey, | ||
score: Levenshtein.get(input, registryKey, { useCollator: true }), | ||
})); | ||
|
||
/** Levenshtein uses positive integers for scores, find all scores that match the lowest score */ | ||
const getLowestScores = (scores: LevenshteinScore[]): LevenshteinScore[] => { | ||
const sortedScores = scores.sort(levenshteinSorter); | ||
const lowestScore = scores[0].score; | ||
return sortedScores.filter((score) => score.score === lowestScore); | ||
}; | ||
|
||
const levenshteinSorter = (a: LevenshteinScore, b: LevenshteinScore): number => a.score - b.score; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
a6d0e7f
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.
Benchmark
eda-componentSetCreate-linux
176
ms189
ms0.93
eda-sourceToMdapi-linux
2314
ms2332
ms0.99
eda-sourceToZip-linux
1794
ms1821
ms0.99
eda-mdapiToSource-linux
2806
ms2936
ms0.96
lotsOfClasses-componentSetCreate-linux
358
ms368
ms0.97
lotsOfClasses-sourceToMdapi-linux
3639
ms3740
ms0.97
lotsOfClasses-sourceToZip-linux
3123
ms3065
ms1.02
lotsOfClasses-mdapiToSource-linux
3436
ms3548
ms0.97
lotsOfClassesOneDir-componentSetCreate-linux
610
ms618
ms0.99
lotsOfClassesOneDir-sourceToMdapi-linux
6375
ms6550
ms0.97
lotsOfClassesOneDir-sourceToZip-linux
5586
ms5696
ms0.98
lotsOfClassesOneDir-mdapiToSource-linux
6224
ms6354
ms0.98
This comment was automatically generated by workflow using github-action-benchmark.
a6d0e7f
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.
Benchmark
eda-componentSetCreate-win32
368
ms428
ms0.86
eda-sourceToMdapi-win32
4074
ms4097
ms0.99
eda-sourceToZip-win32
2698
ms2915
ms0.93
eda-mdapiToSource-win32
5708
ms6084
ms0.94
lotsOfClasses-componentSetCreate-win32
867
ms945
ms0.92
lotsOfClasses-sourceToMdapi-win32
7434
ms7854
ms0.95
lotsOfClasses-sourceToZip-win32
4834
ms4666
ms1.04
lotsOfClasses-mdapiToSource-win32
7370
ms7530
ms0.98
lotsOfClassesOneDir-componentSetCreate-win32
1473
ms1467
ms1.00
lotsOfClassesOneDir-sourceToMdapi-win32
13239
ms13244
ms1.00
lotsOfClassesOneDir-sourceToZip-win32
8687
ms9068
ms0.96
lotsOfClassesOneDir-mdapiToSource-win32
13491
ms13700
ms0.98
This comment was automatically generated by workflow using github-action-benchmark.