-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,599 additions
and
2,683 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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; |
Oops, something went wrong.
e671e8a
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
185
ms244
ms0.76
eda-sourceToMdapi-linux
2367
ms2432
ms0.97
eda-sourceToZip-linux
1864
ms1864
ms1
eda-mdapiToSource-linux
2970
ms2878
ms1.03
lotsOfClasses-componentSetCreate-linux
377
ms420
ms0.90
lotsOfClasses-sourceToMdapi-linux
3727
ms3701
ms1.01
lotsOfClasses-sourceToZip-linux
3183
ms3291
ms0.97
lotsOfClasses-mdapiToSource-linux
3572
ms3636
ms0.98
lotsOfClassesOneDir-componentSetCreate-linux
645
ms766
ms0.84
lotsOfClassesOneDir-sourceToMdapi-linux
6517
ms6707
ms0.97
lotsOfClassesOneDir-sourceToZip-linux
5683
ms5956
ms0.95
lotsOfClassesOneDir-mdapiToSource-linux
6521
ms6498
ms1.00
This comment was automatically generated by workflow using github-action-benchmark.
e671e8a
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
428
ms645
ms0.66
eda-sourceToMdapi-win32
4275
ms4279
ms1.00
eda-sourceToZip-win32
2931
ms3104
ms0.94
eda-mdapiToSource-win32
5728
ms5919
ms0.97
lotsOfClasses-componentSetCreate-win32
877
ms1237
ms0.71
lotsOfClasses-sourceToMdapi-win32
7339
ms8018
ms0.92
lotsOfClasses-sourceToZip-win32
4753
ms5318
ms0.89
lotsOfClasses-mdapiToSource-win32
7568
ms8377
ms0.90
lotsOfClassesOneDir-componentSetCreate-win32
1482
ms2194
ms0.68
lotsOfClassesOneDir-sourceToMdapi-win32
13470
ms14751
ms0.91
lotsOfClassesOneDir-sourceToZip-win32
8615
ms9756
ms0.88
lotsOfClassesOneDir-mdapiToSource-win32
13679
ms14662
ms0.93
This comment was automatically generated by workflow using github-action-benchmark.