Skip to content

Commit ced3289

Browse files
committed
Removed dependency on unused package "leven". No functional change.
1 parent d340ecc commit ced3289

File tree

4 files changed

+1
-63
lines changed

4 files changed

+1
-63
lines changed

packages/pyright-internal/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/pyright-internal/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
"chokidar": "^3.6.0",
2626
"command-line-args": "^5.2.1",
2727
"jsonc-parser": "^3.3.1",
28-
"leven": "3.1.0",
2928
"smol-toml": "^1.3.1",
3029
"source-map-support": "^0.5.21",
3130
"tmp": "^0.2.3",

packages/pyright-internal/src/common/stringUtils.ts

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,53 +7,8 @@
77
* Utility methods for manipulating and comparing strings.
88
*/
99

10-
import leven from 'leven';
11-
1210
import { compareComparableValues, Comparison } from './core';
1311

14-
// Determines how closely a typed string matches a symbol
15-
// name. An exact match returns 1. A match that differs
16-
// only in case returns a slightly lower number. A match
17-
// that involves a few missing or added characters returns
18-
// an even lower number.
19-
export function computeCompletionSimilarity(typedValue: string, symbolName: string): number {
20-
if (symbolName.startsWith(typedValue)) {
21-
return 1;
22-
}
23-
24-
const symbolLower = symbolName.toLocaleLowerCase();
25-
const typedLower = typedValue.toLocaleLowerCase();
26-
27-
if (symbolLower.startsWith(typedLower)) {
28-
return 0.75;
29-
}
30-
31-
// How far apart are the two strings? Find the smallest edit
32-
// distance for each of the substrings taken from the start of
33-
// symbolName.
34-
let symbolSubstrLength = symbolLower.length;
35-
let smallestEditDistance = Number.MAX_VALUE;
36-
while (symbolSubstrLength > 0) {
37-
const editDistance = leven(symbolLower.substr(0, symbolSubstrLength), typedLower);
38-
if (editDistance < smallestEditDistance) {
39-
smallestEditDistance = editDistance;
40-
}
41-
symbolSubstrLength--;
42-
}
43-
44-
// We'll take into account the length of the typed value. If the user
45-
// has typed more characters, and they largely match the symbol name,
46-
// it is considered more similar. If the the edit distance is similar
47-
// to the number of characters the user has typed, then there's almost
48-
// no similarity.
49-
if (smallestEditDistance >= typedValue.length) {
50-
return 0;
51-
}
52-
53-
const similarity = (typedValue.length - smallestEditDistance) / typedValue.length;
54-
return 0.5 * similarity;
55-
}
56-
5712
// Determines if typed string matches a symbol
5813
// name. Characters must appear in order.
5914
// Return true if all typed characters are in symbol

packages/pyright-internal/src/tests/stringUtils.test.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,6 @@ import * as assert from 'assert';
99
import * as core from '../common/core';
1010
import * as utils from '../common/stringUtils';
1111

12-
test('stringUtils computeCompletionSimilarity', () => {
13-
assert.equal(utils.computeCompletionSimilarity('', 'abcd'), 1);
14-
15-
assert.equal(utils.computeCompletionSimilarity('abcd', 'abcd'), 1);
16-
assert.equal(utils.computeCompletionSimilarity('abc', 'abcd'), 1);
17-
18-
assert.equal(utils.computeCompletionSimilarity('ABCD', 'abcd'), 0.75);
19-
assert.equal(utils.computeCompletionSimilarity('ABC', 'abcd'), 0.75);
20-
21-
assert.equal(utils.computeCompletionSimilarity('abce', 'abcd'), 0.375);
22-
assert.equal(utils.computeCompletionSimilarity('abcde', 'abcd'), 0.4);
23-
assert.equal(utils.computeCompletionSimilarity('azcde', 'abcd'), 0.3);
24-
assert.equal(utils.computeCompletionSimilarity('acde', 'abcd'), 0.25);
25-
assert.equal(utils.computeCompletionSimilarity('zbcd', 'abcd'), 0.375);
26-
});
27-
2812
test('stringUtils isPatternInSymbol', () => {
2913
assert.equal(utils.isPatternInSymbol('', 'abcd'), true);
3014

0 commit comments

Comments
 (0)