cspell-lib 6.10.1 → 6.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/FeatureFlags/FeatureFlags.d.ts +30 -0
- package/dist/FeatureFlags/FeatureFlags.js +77 -0
- package/dist/FeatureFlags/index.d.ts +2 -0
- package/dist/FeatureFlags/index.js +8 -0
- package/dist/Settings/InDocSettings.js +7 -7
- package/dist/SpellingDictionary/Dictionaries.d.ts +1 -2
- package/dist/SpellingDictionary/Dictionaries.js +7 -11
- package/dist/SpellingDictionary/DictionaryController/DictionaryLoader.d.ts +1 -1
- package/dist/SpellingDictionary/DictionaryController/DictionaryLoader.js +9 -9
- package/dist/SpellingDictionary/DictionaryLoader.d.ts +1 -1
- package/dist/SpellingDictionary/SpellingDictionary.d.ts +14 -87
- package/dist/SpellingDictionary/SpellingDictionary.js +42 -1
- package/dist/SpellingDictionary/SpellingDictionaryLibOld/SpellingDictionary.d.ts +4 -0
- package/dist/SpellingDictionary/SpellingDictionaryLibOld/SpellingDictionary.js +6 -0
- package/dist/SpellingDictionary/{SpellingDictionaryCollection.d.ts → SpellingDictionaryLibOld/SpellingDictionaryCollection.d.ts} +2 -1
- package/dist/SpellingDictionary/{SpellingDictionaryCollection.js → SpellingDictionaryLibOld/SpellingDictionaryCollection.js} +5 -5
- package/dist/SpellingDictionary/{SpellingDictionaryFromTrie.d.ts → SpellingDictionaryLibOld/SpellingDictionaryFromTrie.d.ts} +0 -0
- package/dist/SpellingDictionary/{SpellingDictionaryFromTrie.js → SpellingDictionaryLibOld/SpellingDictionaryFromTrie.js} +4 -4
- package/dist/SpellingDictionary/{SpellingDictionaryMethods.d.ts → SpellingDictionaryLibOld/SpellingDictionaryMethods.d.ts} +0 -0
- package/dist/SpellingDictionary/{SpellingDictionaryMethods.js → SpellingDictionaryLibOld/SpellingDictionaryMethods.js} +1 -1
- package/dist/SpellingDictionary/{charset.d.ts → SpellingDictionaryLibOld/charset.d.ts} +0 -0
- package/dist/SpellingDictionary/{charset.js → SpellingDictionaryLibOld/charset.js} +0 -0
- package/dist/SpellingDictionary/{createSpellingDictionary.d.ts → SpellingDictionaryLibOld/createSpellingDictionary.d.ts} +3 -2
- package/dist/SpellingDictionary/{createSpellingDictionary.js → SpellingDictionaryLibOld/createSpellingDictionary.js} +13 -3
- package/dist/SpellingDictionary/SpellingDictionaryLibOld/index.d.ts +11 -0
- package/dist/SpellingDictionary/SpellingDictionaryLibOld/index.js +28 -0
- package/dist/SpellingDictionary/index.d.ts +0 -2
- package/dist/SpellingDictionary/index.js +0 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +9 -3
- package/dist/textValidation/ValidationTypes.d.ts +2 -2
- package/dist/textValidation/docValidator.d.ts +1 -1
- package/dist/textValidation/docValidator.js +4 -3
- package/dist/textValidation/isWordValid.d.ts +3 -7
- package/dist/textValidation/isWordValid.js +5 -5
- package/dist/textValidation/lineValidatorFactory.d.ts +12 -3
- package/dist/textValidation/lineValidatorFactory.js +22 -20
- package/dist/textValidation/textValidator.d.ts +1 -1
- package/dist/textValidation/textValidator.js +5 -4
- package/dist/util/Memorizer.d.ts +0 -12
- package/dist/util/Memorizer.js +1 -15
- package/dist/util/memorizeLastCall.d.ts +13 -0
- package/dist/util/memorizeLastCall.js +18 -0
- package/dist/util/text.js +4 -4
- package/package.json +15 -14
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface FeatureFlag {
|
|
2
|
+
name: string;
|
|
3
|
+
description: string;
|
|
4
|
+
}
|
|
5
|
+
declare type FlagTypes = string | boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Feature Flags are used to turn on/off features.
|
|
8
|
+
* These are primarily used before a feature has been fully released.
|
|
9
|
+
*/
|
|
10
|
+
export declare class FeatureFlags {
|
|
11
|
+
private flags;
|
|
12
|
+
private flagValues;
|
|
13
|
+
constructor(flags?: FeatureFlag[]);
|
|
14
|
+
register(flag: FeatureFlag): this;
|
|
15
|
+
register(name: string, description: string): this;
|
|
16
|
+
getFlag(flag: string): FlagTypes | undefined;
|
|
17
|
+
getFlagBool(flag: string): boolean | undefined;
|
|
18
|
+
setFlag(flag: string, value?: FlagTypes): this;
|
|
19
|
+
getFlagInfo(flag: string): FeatureFlag | undefined;
|
|
20
|
+
getFlags(): FeatureFlag[];
|
|
21
|
+
getFlagValues(): Map<string, FlagTypes>;
|
|
22
|
+
reset(): this;
|
|
23
|
+
}
|
|
24
|
+
export declare class UnknownFeatureFlagError extends Error {
|
|
25
|
+
readonly flag: string;
|
|
26
|
+
constructor(flag: string);
|
|
27
|
+
}
|
|
28
|
+
export declare function getSystemFeatureFlags(): FeatureFlags;
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=FeatureFlags.d.ts.map
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSystemFeatureFlags = exports.UnknownFeatureFlagError = exports.FeatureFlags = void 0;
|
|
4
|
+
let systemFeatureFlags;
|
|
5
|
+
/**
|
|
6
|
+
* Feature Flags are used to turn on/off features.
|
|
7
|
+
* These are primarily used before a feature has been fully released.
|
|
8
|
+
*/
|
|
9
|
+
class FeatureFlags {
|
|
10
|
+
constructor(flags = []) {
|
|
11
|
+
this.flagValues = new Map();
|
|
12
|
+
this.flags = new Map(flags.map((f) => [f.name, f]));
|
|
13
|
+
}
|
|
14
|
+
register(flagOrName, description) {
|
|
15
|
+
if (typeof flagOrName === 'string') {
|
|
16
|
+
return this.register({ name: flagOrName, description: description || '' });
|
|
17
|
+
}
|
|
18
|
+
this.flags.set(flagOrName.name, flagOrName);
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
21
|
+
getFlag(flag) {
|
|
22
|
+
return this.flagValues.get(flag);
|
|
23
|
+
}
|
|
24
|
+
getFlagBool(flag) {
|
|
25
|
+
return toBool(this.getFlag(flag));
|
|
26
|
+
}
|
|
27
|
+
setFlag(flag, value = true) {
|
|
28
|
+
if (!this.flags.has(flag)) {
|
|
29
|
+
throw new UnknownFeatureFlagError(flag);
|
|
30
|
+
}
|
|
31
|
+
this.flagValues.set(flag, value);
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
getFlagInfo(flag) {
|
|
35
|
+
return this.flags.get(flag);
|
|
36
|
+
}
|
|
37
|
+
getFlags() {
|
|
38
|
+
return [...this.flags.values()];
|
|
39
|
+
}
|
|
40
|
+
getFlagValues() {
|
|
41
|
+
return new Map(this.flagValues);
|
|
42
|
+
}
|
|
43
|
+
reset() {
|
|
44
|
+
this.flagValues.clear();
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.FeatureFlags = FeatureFlags;
|
|
49
|
+
class UnknownFeatureFlagError extends Error {
|
|
50
|
+
constructor(flag) {
|
|
51
|
+
super(`Unknown feature flag: ${flag}`);
|
|
52
|
+
this.flag = flag;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.UnknownFeatureFlagError = UnknownFeatureFlagError;
|
|
56
|
+
function getSystemFeatureFlags() {
|
|
57
|
+
return systemFeatureFlags || (systemFeatureFlags = new FeatureFlags());
|
|
58
|
+
}
|
|
59
|
+
exports.getSystemFeatureFlags = getSystemFeatureFlags;
|
|
60
|
+
const boolValues = {
|
|
61
|
+
0: false,
|
|
62
|
+
1: true,
|
|
63
|
+
f: false,
|
|
64
|
+
false: false,
|
|
65
|
+
n: false,
|
|
66
|
+
no: false,
|
|
67
|
+
t: true,
|
|
68
|
+
true: true,
|
|
69
|
+
y: true,
|
|
70
|
+
yes: true,
|
|
71
|
+
};
|
|
72
|
+
function toBool(value) {
|
|
73
|
+
if (typeof value !== 'string')
|
|
74
|
+
return value;
|
|
75
|
+
return boolValues[value.toLowerCase()];
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=FeatureFlags.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UnknownFeatureFlagError = exports.getSystemFeatureFlags = exports.FeatureFlags = void 0;
|
|
4
|
+
var FeatureFlags_1 = require("./FeatureFlags");
|
|
5
|
+
Object.defineProperty(exports, "FeatureFlags", { enumerable: true, get: function () { return FeatureFlags_1.FeatureFlags; } });
|
|
6
|
+
Object.defineProperty(exports, "getSystemFeatureFlags", { enumerable: true, get: function () { return FeatureFlags_1.getSystemFeatureFlags; } });
|
|
7
|
+
Object.defineProperty(exports, "UnknownFeatureFlagError", { enumerable: true, get: function () { return FeatureFlags_1.UnknownFeatureFlagError; } });
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -24,7 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.internal = exports.getIgnoreRegExpFromDocument = exports.getIgnoreWordsFromDocument = exports.regExSpellingGuardLine = exports.regExSpellingGuardNext = exports.regExSpellingGuardBlock = exports.validateInDocumentSettings = exports.getInDocumentSettings = void 0;
|
|
27
|
-
const
|
|
27
|
+
const sync_1 = require("@cspell/cspell-pipe/sync");
|
|
28
28
|
const gensequence_1 = require("gensequence");
|
|
29
29
|
const SpellingDictionary_1 = require("../SpellingDictionary");
|
|
30
30
|
const Text = __importStar(require("../util/text"));
|
|
@@ -32,9 +32,9 @@ const util_1 = require("../util/util");
|
|
|
32
32
|
const CSpellSettingsServer_1 = require("./CSpellSettingsServer");
|
|
33
33
|
// cspell:ignore gimuy
|
|
34
34
|
const regExMatchRegEx = /\/.*\/[gimuy]*/;
|
|
35
|
-
const regExCSpellInDocDirective =
|
|
36
|
-
const regExCSpellDirectiveKey = /(
|
|
37
|
-
const regExInFileSettings = [regExCSpellInDocDirective,
|
|
35
|
+
const regExCSpellInDocDirective = /\b(?:spell-?checker|c?spell)::?(.*)/gi;
|
|
36
|
+
const regExCSpellDirectiveKey = /(?<=\b(?:spell-?checker|c?spell)::?)(?!:)(.*)/i;
|
|
37
|
+
const regExInFileSettings = [regExCSpellInDocDirective, /\b(LocalWords:?.*)/g];
|
|
38
38
|
const officialDirectives = [
|
|
39
39
|
'enable',
|
|
40
40
|
'disable',
|
|
@@ -84,7 +84,7 @@ const preferredDirectives = [
|
|
|
84
84
|
'disableCaseSensitive',
|
|
85
85
|
];
|
|
86
86
|
const allDirectives = new Set(preferredDirectives.concat(officialDirectives));
|
|
87
|
-
const dictInDocSettings = (0, SpellingDictionary_1.
|
|
87
|
+
const dictInDocSettings = (0, SpellingDictionary_1.getSpellDictInterface)().createSpellingDictionary(allDirectives, 'Directives', 'Directive List', {
|
|
88
88
|
supportNonStrictSearches: false,
|
|
89
89
|
});
|
|
90
90
|
const EmptyWords = [];
|
|
@@ -100,7 +100,7 @@ function getInDocumentSettings(text) {
|
|
|
100
100
|
}
|
|
101
101
|
exports.getInDocumentSettings = getInDocumentSettings;
|
|
102
102
|
function validateInDocumentSettings(docText, _settings) {
|
|
103
|
-
return (0,
|
|
103
|
+
return (0, sync_1.pipeSync)(getPossibleInDocSettings(docText), (0, sync_1.opMap)(parseSettingMatchValidation), (0, sync_1.opFilter)(util_1.isDefined));
|
|
104
104
|
}
|
|
105
105
|
exports.validateInDocumentSettings = validateInDocumentSettings;
|
|
106
106
|
const settingParsers = [
|
|
@@ -146,7 +146,7 @@ function parseSettingMatchValidation(matchArray) {
|
|
|
146
146
|
.suggest(text, { ignoreCase: false })
|
|
147
147
|
.map((sug) => sug.word)
|
|
148
148
|
.filter((a) => !noSuggestDirectives.has(a));
|
|
149
|
-
const sugs = new Set((0,
|
|
149
|
+
const sugs = new Set((0, sync_1.pipeSync)(dictSugs, (0, sync_1.opAppend)(allDirectives)));
|
|
150
150
|
const suggestions = [...sugs].slice(0, 8);
|
|
151
151
|
const issue = {
|
|
152
152
|
range: [start, end],
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { CSpellSettingsInternal, DictionaryDefinitionInternal } from '../Models/CSpellSettingsInternalDef';
|
|
2
|
-
import { SpellingDictionary } from './SpellingDictionary';
|
|
3
|
-
import { SpellingDictionaryCollection } from './SpellingDictionaryCollection';
|
|
2
|
+
import { SpellingDictionary, SpellingDictionaryCollection } from './SpellingDictionary';
|
|
4
3
|
export declare function loadDictionaryDefs(defsToLoad: DictionaryDefinitionInternal[]): Promise<SpellingDictionary>[];
|
|
5
4
|
export declare function loadDictionaryDefsSync(defsToLoad: DictionaryDefinitionInternal[]): SpellingDictionary[];
|
|
6
5
|
export declare function refreshDictionaryCache(maxAge?: number): Promise<void>;
|
|
@@ -3,9 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getDictionaryInternalSync = exports.getDictionaryInternal = exports.refreshDictionaryCache = exports.loadDictionaryDefsSync = exports.loadDictionaryDefs = void 0;
|
|
4
4
|
const DictionarySettings_1 = require("../Settings/DictionarySettings");
|
|
5
5
|
const util_1 = require("../util/util");
|
|
6
|
-
const createSpellingDictionary_1 = require("./createSpellingDictionary");
|
|
7
6
|
const DictionaryLoader_1 = require("./DictionaryLoader");
|
|
8
|
-
const
|
|
7
|
+
const SpellingDictionary_1 = require("./SpellingDictionary");
|
|
9
8
|
function loadDictionaryDefs(defsToLoad) {
|
|
10
9
|
return defsToLoad.map(DictionaryLoader_1.loadDictionary);
|
|
11
10
|
}
|
|
@@ -31,22 +30,19 @@ function getDictionaryInternalSync(settings) {
|
|
|
31
30
|
exports.getDictionaryInternalSync = getDictionaryInternalSync;
|
|
32
31
|
function _getDictionaryInternal(settings, spellDictionaries) {
|
|
33
32
|
const { words = emptyWords, userWords = emptyWords, flagWords = emptyWords, ignoreWords = emptyWords } = settings;
|
|
34
|
-
const
|
|
33
|
+
const { createSpellingDictionary, createIgnoreWordsDictionary, createCollection, createForbiddenWordsDictionary } = (0, SpellingDictionary_1.getSpellDictInterface)();
|
|
34
|
+
const settingsWordsDictionary = createSpellingDictionary(words, '[words]', 'From Settings `words`', {
|
|
35
35
|
caseSensitive: true,
|
|
36
36
|
weightMap: undefined,
|
|
37
37
|
});
|
|
38
38
|
const settingsUserWordsDictionary = userWords.length
|
|
39
|
-
?
|
|
39
|
+
? createSpellingDictionary(userWords, '[userWords]', 'From Settings `userWords`', {
|
|
40
40
|
caseSensitive: true,
|
|
41
41
|
weightMap: undefined,
|
|
42
42
|
})
|
|
43
43
|
: undefined;
|
|
44
|
-
const ignoreWordsDictionary = (
|
|
45
|
-
|
|
46
|
-
noSuggest: true,
|
|
47
|
-
weightMap: undefined,
|
|
48
|
-
});
|
|
49
|
-
const flagWordsDictionary = (0, createSpellingDictionary_1.createForbiddenWordsDictionary)(flagWords, '[flagWords]', 'From Settings `flagWords`', {
|
|
44
|
+
const ignoreWordsDictionary = createIgnoreWordsDictionary(ignoreWords, '[ignoreWords]', 'From Settings `ignoreWords`');
|
|
45
|
+
const flagWordsDictionary = createForbiddenWordsDictionary(flagWords, '[flagWords]', 'From Settings `flagWords`', {
|
|
50
46
|
weightMap: undefined,
|
|
51
47
|
});
|
|
52
48
|
const dictionaries = [
|
|
@@ -56,6 +52,6 @@ function _getDictionaryInternal(settings, spellDictionaries) {
|
|
|
56
52
|
ignoreWordsDictionary,
|
|
57
53
|
flagWordsDictionary,
|
|
58
54
|
].filter(util_1.isDefined);
|
|
59
|
-
return
|
|
55
|
+
return createCollection(dictionaries, 'dictionary collection');
|
|
60
56
|
}
|
|
61
57
|
//# sourceMappingURL=Dictionaries.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CSpellIO } from 'cspell-io';
|
|
2
2
|
import { DictionaryDefinitionInternal } from '../../Models/CSpellSettingsInternalDef';
|
|
3
|
-
import { SpellingDictionary } from '../SpellingDictionary';
|
|
3
|
+
import { SpellingDictionary } from '../SpellingDictionaryLibOld/SpellingDictionary';
|
|
4
4
|
export declare type LoadOptions = DictionaryDefinitionInternal;
|
|
5
5
|
export declare class DictionaryLoader {
|
|
6
6
|
private cspellIO;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DictionaryLoader = void 0;
|
|
4
|
-
const
|
|
4
|
+
const sync_1 = require("@cspell/cspell-pipe/sync");
|
|
5
5
|
const errors_1 = require("../../util/errors");
|
|
6
|
-
const createSpellingDictionary_1 = require("../createSpellingDictionary");
|
|
6
|
+
const createSpellingDictionary_1 = require("../SpellingDictionaryLibOld/createSpellingDictionary");
|
|
7
7
|
const SpellingDictionaryError_1 = require("../SpellingDictionaryError");
|
|
8
|
-
const SpellingDictionaryFromTrie_1 = require("../SpellingDictionaryFromTrie");
|
|
8
|
+
const SpellingDictionaryFromTrie_1 = require("../SpellingDictionaryLibOld/SpellingDictionaryFromTrie");
|
|
9
9
|
const MAX_AGE = 10000;
|
|
10
10
|
const loaders = {
|
|
11
11
|
S: loadSimpleWordList,
|
|
@@ -231,11 +231,11 @@ function legacyWordListSync(readLinesSync, filename, options) {
|
|
|
231
231
|
return _legacyWordListSync(lines, filename, options);
|
|
232
232
|
}
|
|
233
233
|
function _legacyWordListSync(lines, filename, options) {
|
|
234
|
-
const words = (0,
|
|
234
|
+
const words = (0, sync_1.pipe)(lines,
|
|
235
235
|
// Remove comments
|
|
236
|
-
(0,
|
|
236
|
+
(0, sync_1.opMap)((line) => line.replace(/#.*/g, '')),
|
|
237
237
|
// Split on everything else
|
|
238
|
-
(0,
|
|
238
|
+
(0, sync_1.opConcatMap)((line) => line.split(/[^\w\p{L}\p{M}'’]+/gu)), (0, sync_1.opFilter)((word) => !!word));
|
|
239
239
|
return (0, createSpellingDictionary_1.createSpellingDictionary)(words, options.name, filename, options);
|
|
240
240
|
}
|
|
241
241
|
async function wordsPerLineWordList(readLines, filename, options) {
|
|
@@ -247,11 +247,11 @@ function wordsPerLineWordListSync(readLinesSync, filename, options) {
|
|
|
247
247
|
return _wordsPerLineWordList(lines, filename, options);
|
|
248
248
|
}
|
|
249
249
|
function _wordsPerLineWordList(lines, filename, options) {
|
|
250
|
-
const words = (0,
|
|
250
|
+
const words = (0, sync_1.pipe)(lines,
|
|
251
251
|
// Remove comments
|
|
252
|
-
(0,
|
|
252
|
+
(0, sync_1.opMap)((line) => line.replace(/#.*/g, '')),
|
|
253
253
|
// Split on everything else
|
|
254
|
-
(0,
|
|
254
|
+
(0, sync_1.opConcatMap)((line) => line.split(/\s+/gu)), (0, sync_1.opFilter)((word) => !!word));
|
|
255
255
|
return (0, createSpellingDictionary_1.createSpellingDictionary)(words, options.name, filename, options);
|
|
256
256
|
}
|
|
257
257
|
async function loadSimpleWordList(reader, filename, options) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CSpellIO } from 'cspell-io';
|
|
2
2
|
import { DictionaryDefinitionInternal } from '../Models/CSpellSettingsInternalDef';
|
|
3
3
|
import { DictionaryLoader } from './DictionaryController';
|
|
4
|
-
import { SpellingDictionary } from './SpellingDictionary';
|
|
4
|
+
import { SpellingDictionary } from './SpellingDictionaryLibOld/SpellingDictionary';
|
|
5
5
|
export type { LoadOptions } from './DictionaryController';
|
|
6
6
|
export declare function getDictionaryLoader(cspellIO?: CSpellIO): DictionaryLoader;
|
|
7
7
|
export declare function loadDictionary(def: DictionaryDefinitionInternal): Promise<SpellingDictionary>;
|
|
@@ -1,88 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
export { CompoundWordsMethod
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* The limit on the number of suggestions to generate. If `allowTies` is true, it is possible
|
|
16
|
-
* for more suggestions to be generated.
|
|
17
|
-
*/
|
|
18
|
-
numSuggestions?: number;
|
|
19
|
-
/**
|
|
20
|
-
* Max number of changes / edits to the word to get to a suggestion matching suggestion.
|
|
21
|
-
*/
|
|
22
|
-
numChanges?: number;
|
|
23
|
-
/**
|
|
24
|
-
* Allow for case-ingestive checking.
|
|
25
|
-
*/
|
|
26
|
-
ignoreCase?: boolean;
|
|
27
|
-
/**
|
|
28
|
-
* If multiple suggestions have the same edit / change "cost", then included them even if
|
|
29
|
-
* it causes more than `numSuggestions` to be returned.
|
|
30
|
-
* @default false
|
|
31
|
-
*/
|
|
32
|
-
includeTies?: boolean;
|
|
33
|
-
/**
|
|
34
|
-
* Maximum amount of time to allow for generating suggestions.
|
|
35
|
-
*/
|
|
36
|
-
timeout?: number;
|
|
37
|
-
}
|
|
38
|
-
export declare type FindOptions = SearchOptions;
|
|
39
|
-
export interface FindResult {
|
|
40
|
-
/** the text found, otherwise `false` */
|
|
41
|
-
found: string | false;
|
|
42
|
-
/** `true` if it is considered a forbidden word. */
|
|
43
|
-
forbidden: boolean;
|
|
44
|
-
/** `true` if it is a no-suggest word. */
|
|
45
|
-
noSuggest: boolean;
|
|
46
|
-
}
|
|
47
|
-
export declare type HasOptions = SearchOptions;
|
|
48
|
-
export interface SpellingDictionaryOptions {
|
|
49
|
-
repMap?: ReplaceMap;
|
|
50
|
-
useCompounds?: boolean;
|
|
51
|
-
/**
|
|
52
|
-
* The dictionary is case aware.
|
|
53
|
-
*/
|
|
54
|
-
caseSensitive?: boolean;
|
|
55
|
-
noSuggest?: boolean;
|
|
56
|
-
weightMap?: WeightMap | undefined;
|
|
57
|
-
dictionaryInformation?: DictionaryInformation;
|
|
58
|
-
/**
|
|
59
|
-
* Strip Case and Accents to allow for case insensitive searches and
|
|
60
|
-
* words without accents.
|
|
61
|
-
*
|
|
62
|
-
* Note: this setting only applies to word lists. It has no-impact on trie
|
|
63
|
-
* dictionaries.
|
|
64
|
-
*
|
|
65
|
-
* @default true
|
|
66
|
-
*/
|
|
67
|
-
supportNonStrictSearches?: boolean;
|
|
68
|
-
}
|
|
69
|
-
export interface SpellingDictionary {
|
|
70
|
-
readonly name: string;
|
|
71
|
-
readonly type: string;
|
|
72
|
-
readonly source: string;
|
|
73
|
-
readonly containsNoSuggestWords: boolean;
|
|
74
|
-
has(word: string, options?: HasOptions): boolean;
|
|
75
|
-
/** A more detailed search for a word, might take longer than `has` */
|
|
76
|
-
find(word: string, options?: SearchOptions): FindResult | undefined;
|
|
77
|
-
isForbidden(word: string): boolean;
|
|
78
|
-
isNoSuggestWord(word: string, options: HasOptions): boolean;
|
|
79
|
-
suggest(word: string, numSuggestions?: number, compoundMethod?: CompoundWordsMethod, numChanges?: number, ignoreCase?: boolean): SuggestionResult[];
|
|
80
|
-
suggest(word: string, suggestOptions: SuggestOptions): SuggestionResult[];
|
|
81
|
-
genSuggestions(collector: SuggestionCollector, suggestOptions: SuggestOptions): void;
|
|
82
|
-
mapWord(word: string): string;
|
|
83
|
-
readonly size: number;
|
|
84
|
-
readonly options: SpellingDictionaryOptions;
|
|
85
|
-
readonly isDictionaryCaseSensitive: boolean;
|
|
86
|
-
getErrors?(): Error[];
|
|
87
|
-
}
|
|
1
|
+
import * as cspellDictModule from 'cspell-dictionary';
|
|
2
|
+
import { SpellingDictionaryLibOld } from './SpellingDictionaryLibOld';
|
|
3
|
+
export { CompoundWordsMethod } from 'cspell-trie-lib';
|
|
4
|
+
declare const SpellingDictionaryModule: {
|
|
5
|
+
readonly createCollection: typeof cspellDictModule.createCollection;
|
|
6
|
+
readonly createForbiddenWordsDictionary: typeof cspellDictModule.createForbiddenWordsDictionary;
|
|
7
|
+
readonly createSpellingDictionary: typeof cspellDictModule.createSpellingDictionary;
|
|
8
|
+
readonly createIgnoreWordsDictionary: typeof cspellDictModule.createIgnoreWordsDictionary;
|
|
9
|
+
};
|
|
10
|
+
declare type SpellDictInterface = typeof SpellingDictionaryModule | typeof SpellingDictionaryLibOld;
|
|
11
|
+
export type { FindOptions, FindResult, HasOptions, SearchOptions, SpellingDictionary, SpellingDictionaryCollection, SpellingDictionaryOptions, SuggestionCollector, SuggestionResult, SuggestOptions, } from 'cspell-dictionary';
|
|
12
|
+
export declare function getSpellDictInterface(): SpellDictInterface;
|
|
13
|
+
export declare const createSpellingDictionary: typeof import("./SpellingDictionaryLibOld/createSpellingDictionary").createSpellingDictionary | typeof cspellDictModule.createSpellingDictionary;
|
|
14
|
+
export declare const createCollection: typeof import("./SpellingDictionaryLibOld/SpellingDictionaryCollection").createCollection | typeof cspellDictModule.createCollection;
|
|
88
15
|
//# sourceMappingURL=SpellingDictionary.d.ts.map
|
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CompoundWordsMethod = void 0;
|
|
26
|
+
exports.createCollection = exports.createSpellingDictionary = exports.getSpellDictInterface = exports.CompoundWordsMethod = void 0;
|
|
27
|
+
const cspellDictModule = __importStar(require("cspell-dictionary"));
|
|
28
|
+
const FeatureFlags_1 = require("../FeatureFlags");
|
|
29
|
+
const SpellingDictionaryLibOld_1 = require("./SpellingDictionaryLibOld");
|
|
4
30
|
var cspell_trie_lib_1 = require("cspell-trie-lib");
|
|
5
31
|
Object.defineProperty(exports, "CompoundWordsMethod", { enumerable: true, get: function () { return cspell_trie_lib_1.CompoundWordsMethod; } });
|
|
32
|
+
const SpellingDictionaryModule = {
|
|
33
|
+
createCollection: cspellDictModule.createCollection,
|
|
34
|
+
createForbiddenWordsDictionary: cspellDictModule.createForbiddenWordsDictionary,
|
|
35
|
+
createSpellingDictionary: cspellDictModule.createSpellingDictionary,
|
|
36
|
+
createIgnoreWordsDictionary: cspellDictModule.createIgnoreWordsDictionary,
|
|
37
|
+
};
|
|
38
|
+
const flagUseCSpellDictionary = 'use-cspell-dictionary';
|
|
39
|
+
(0, FeatureFlags_1.getSystemFeatureFlags)().register(flagUseCSpellDictionary, 'Use the CSpell Dictionary module.');
|
|
40
|
+
function getSpellDictInterface() {
|
|
41
|
+
const useModule = (0, FeatureFlags_1.getSystemFeatureFlags)().getFlagBool(flagUseCSpellDictionary) ?? true;
|
|
42
|
+
return useModule ? SpellingDictionaryModule : SpellingDictionaryLibOld_1.SpellingDictionaryLibOld;
|
|
43
|
+
}
|
|
44
|
+
exports.getSpellDictInterface = getSpellDictInterface;
|
|
45
|
+
exports.createSpellingDictionary = getSpellDictInterface().createSpellingDictionary;
|
|
46
|
+
exports.createCollection = getSpellDictInterface().createCollection;
|
|
6
47
|
//# sourceMappingURL=SpellingDictionary.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { FindOptions, FindResult, HasOptions, SearchOptions, SpellingDictionary, SpellingDictionaryOptions, SuggestOptions, } from 'cspell-dictionary';
|
|
2
|
+
export { CompoundWordsMethod } from 'cspell-trie-lib';
|
|
3
|
+
export type { SuggestionCollector, SuggestionResult } from 'cspell-trie-lib';
|
|
4
|
+
//# sourceMappingURL=SpellingDictionary.d.ts.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CompoundWordsMethod = void 0;
|
|
4
|
+
var cspell_trie_lib_1 = require("cspell-trie-lib");
|
|
5
|
+
Object.defineProperty(exports, "CompoundWordsMethod", { enumerable: true, get: function () { return cspell_trie_lib_1.CompoundWordsMethod; } });
|
|
6
|
+
//# sourceMappingURL=SpellingDictionary.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CompoundWordsMethod, FindResult, HasOptions, SearchOptions, SpellingDictionary, SpellingDictionaryOptions, SuggestionCollector, SuggestionResult, SuggestOptions } from './SpellingDictionary';
|
|
2
2
|
declare function identityString(w: string): string;
|
|
3
|
-
|
|
3
|
+
declare class SpellingDictionaryCollection implements SpellingDictionary {
|
|
4
4
|
readonly dictionaries: SpellingDictionary[];
|
|
5
5
|
readonly name: string;
|
|
6
6
|
readonly options: SpellingDictionaryOptions;
|
|
@@ -23,6 +23,7 @@ export declare class SpellingDictionaryCollection implements SpellingDictionary
|
|
|
23
23
|
private _isForbiddenInDict;
|
|
24
24
|
private _isNoSuggestWord;
|
|
25
25
|
}
|
|
26
|
+
export declare const SpellingDictionaryCollectionLegacy: typeof SpellingDictionaryCollection;
|
|
26
27
|
export declare function createCollection(dictionaries: SpellingDictionary[], name: string): SpellingDictionaryCollection;
|
|
27
28
|
declare function isWordInAnyDictionary(dicts: SpellingDictionary[], word: string, options: SearchOptions): SpellingDictionary | undefined;
|
|
28
29
|
declare function isWordForbiddenInAnyDictionary(dicts: SpellingDictionary[], word: string): SpellingDictionary | undefined;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.__testing__ = exports.createCollection = exports.
|
|
3
|
+
exports.__testing__ = exports.createCollection = exports.SpellingDictionaryCollectionLegacy = void 0;
|
|
4
4
|
const cspell_trie_lib_1 = require("cspell-trie-lib");
|
|
5
5
|
const gensequence_1 = require("gensequence");
|
|
6
|
-
const Settings_1 = require("
|
|
7
|
-
const Memorizer_1 = require("
|
|
8
|
-
const util_1 = require("
|
|
6
|
+
const Settings_1 = require("../../Settings");
|
|
7
|
+
const Memorizer_1 = require("../../util/Memorizer");
|
|
8
|
+
const util_1 = require("../../util/util");
|
|
9
9
|
const SpellingDictionary_1 = require("./SpellingDictionary");
|
|
10
10
|
const SpellingDictionaryFromTrie_1 = require("./SpellingDictionaryFromTrie");
|
|
11
11
|
const SpellingDictionaryMethods_1 = require("./SpellingDictionaryMethods");
|
|
@@ -85,7 +85,7 @@ class SpellingDictionaryCollection {
|
|
|
85
85
|
return this.dictionaries.reduce((errors, dict) => errors.concat(dict.getErrors?.() || []), []);
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
-
exports.
|
|
88
|
+
exports.SpellingDictionaryCollectionLegacy = SpellingDictionaryCollection;
|
|
89
89
|
function createCollection(dictionaries, name) {
|
|
90
90
|
return new SpellingDictionaryCollection(dictionaries, name);
|
|
91
91
|
}
|
|
File without changes
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createSpellingDictionaryTrie = exports.SpellingDictionaryFromTrie = void 0;
|
|
4
4
|
const cspell_trie_lib_1 = require("cspell-trie-lib");
|
|
5
|
-
const Settings_1 = require("
|
|
6
|
-
const Memorizer_1 = require("
|
|
7
|
-
const repMap_1 = require("
|
|
8
|
-
const util_1 = require("
|
|
5
|
+
const Settings_1 = require("../../Settings");
|
|
6
|
+
const Memorizer_1 = require("../../util/Memorizer");
|
|
7
|
+
const repMap_1 = require("../../util/repMap");
|
|
8
|
+
const util_1 = require("../../util/util");
|
|
9
9
|
const charset_1 = require("./charset");
|
|
10
10
|
const SpellingDictionaryMethods_1 = require("./SpellingDictionaryMethods");
|
|
11
11
|
class SpellingDictionaryFromTrie {
|
|
File without changes
|
|
@@ -4,7 +4,7 @@ exports.__testMethods__ = exports.createWeightMapFromDictionaryInformation = exp
|
|
|
4
4
|
const cspell_trie_lib_1 = require("cspell-trie-lib");
|
|
5
5
|
const trie_util_1 = require("cspell-trie-lib/dist/lib/trie-util");
|
|
6
6
|
const gensequence_1 = require("gensequence");
|
|
7
|
-
const text_1 = require("
|
|
7
|
+
const text_1 = require("../../util/text");
|
|
8
8
|
var cspell_trie_lib_2 = require("cspell-trie-lib");
|
|
9
9
|
Object.defineProperty(exports, "impersonateCollector", { enumerable: true, get: function () { return cspell_trie_lib_2.impersonateCollector; } });
|
|
10
10
|
Object.defineProperty(exports, "suggestionCollector", { enumerable: true, get: function () { return cspell_trie_lib_2.suggestionCollector; } });
|
|
File without changes
|
|
File without changes
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { IterableLike } from '
|
|
1
|
+
import { IterableLike } from '../../util/IterableLike';
|
|
2
2
|
import { SpellingDictionary, SpellingDictionaryOptions } from './SpellingDictionary';
|
|
3
|
-
import { SpellingDictionaryLoadError } from '
|
|
3
|
+
import { SpellingDictionaryLoadError } from '../SpellingDictionaryError';
|
|
4
4
|
export declare function createSpellingDictionary(wordList: readonly string[] | IterableLike<string>, name: string, source: string, options: SpellingDictionaryOptions | undefined): SpellingDictionary;
|
|
5
5
|
export declare function createForbiddenWordsDictionary(wordList: readonly string[], name: string, source: string, options: SpellingDictionaryOptions | undefined): SpellingDictionary;
|
|
6
6
|
export declare function createFailedToLoadDictionary(error: SpellingDictionaryLoadError): SpellingDictionary;
|
|
7
|
+
export declare function createIgnoreWordsDictionary(wordList: readonly string[], name: string, source: string): SpellingDictionary;
|
|
7
8
|
//# sourceMappingURL=createSpellingDictionary.d.ts.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createFailedToLoadDictionary = exports.createForbiddenWordsDictionary = exports.createSpellingDictionary = void 0;
|
|
3
|
+
exports.createIgnoreWordsDictionary = exports.createFailedToLoadDictionary = exports.createForbiddenWordsDictionary = exports.createSpellingDictionary = void 0;
|
|
4
4
|
const cspell_trie_lib_1 = require("cspell-trie-lib");
|
|
5
5
|
const fast_equals_1 = require("fast-equals");
|
|
6
6
|
const gensequence_1 = require("gensequence");
|
|
7
|
-
const simpleCache_1 = require("
|
|
7
|
+
const simpleCache_1 = require("../../util/simpleCache");
|
|
8
8
|
const SpellingDictionaryFromTrie_1 = require("./SpellingDictionaryFromTrie");
|
|
9
9
|
const SpellingDictionaryMethods_1 = require("./SpellingDictionaryMethods");
|
|
10
10
|
const defaultOptions = Object.freeze({
|
|
@@ -44,7 +44,7 @@ function _createSpellingDictionary(params) {
|
|
|
44
44
|
return new SpellingDictionaryFromTrie_1.SpellingDictionaryFromTrie(trie, name, opts, source);
|
|
45
45
|
}
|
|
46
46
|
function createForbiddenWordsDictionary(wordList, name, source, options) {
|
|
47
|
-
// console.log(`
|
|
47
|
+
// console.log(`createForbiddenWordsDictionary ${name} ${source}`);
|
|
48
48
|
const words = (0, cspell_trie_lib_1.parseDictionaryLines)(wordList.concat(wordList.map((a) => a.toLowerCase())), {
|
|
49
49
|
stripCaseAndAccents: !options?.noSuggest,
|
|
50
50
|
});
|
|
@@ -77,4 +77,14 @@ function createFailedToLoadDictionary(error) {
|
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
79
|
exports.createFailedToLoadDictionary = createFailedToLoadDictionary;
|
|
80
|
+
function createIgnoreWordsDictionary(wordList, name, source) {
|
|
81
|
+
// console.log('createIgnoreWordsDictionary %o', wordList);
|
|
82
|
+
return createSpellingDictionary(wordList, name, source, {
|
|
83
|
+
caseSensitive: true,
|
|
84
|
+
noSuggest: true,
|
|
85
|
+
weightMap: undefined,
|
|
86
|
+
supportNonStrictSearches: true,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
exports.createIgnoreWordsDictionary = createIgnoreWordsDictionary;
|
|
80
90
|
//# sourceMappingURL=createSpellingDictionary.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './SpellingDictionary';
|
|
2
|
+
import { createCollection } from './SpellingDictionaryCollection';
|
|
3
|
+
import { createFailedToLoadDictionary, createForbiddenWordsDictionary, createIgnoreWordsDictionary, createSpellingDictionary } from './createSpellingDictionary';
|
|
4
|
+
export declare const SpellingDictionaryLibOld: {
|
|
5
|
+
readonly createCollection: typeof createCollection;
|
|
6
|
+
readonly createFailedToLoadDictionary: typeof createFailedToLoadDictionary;
|
|
7
|
+
readonly createForbiddenWordsDictionary: typeof createForbiddenWordsDictionary;
|
|
8
|
+
readonly createIgnoreWordsDictionary: typeof createIgnoreWordsDictionary;
|
|
9
|
+
readonly createSpellingDictionary: typeof createSpellingDictionary;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.SpellingDictionaryLibOld = void 0;
|
|
18
|
+
__exportStar(require("./SpellingDictionary"), exports);
|
|
19
|
+
const SpellingDictionaryCollection_1 = require("./SpellingDictionaryCollection");
|
|
20
|
+
const createSpellingDictionary_1 = require("./createSpellingDictionary");
|
|
21
|
+
exports.SpellingDictionaryLibOld = {
|
|
22
|
+
createCollection: SpellingDictionaryCollection_1.createCollection,
|
|
23
|
+
createFailedToLoadDictionary: createSpellingDictionary_1.createFailedToLoadDictionary,
|
|
24
|
+
createForbiddenWordsDictionary: createSpellingDictionary_1.createForbiddenWordsDictionary,
|
|
25
|
+
createIgnoreWordsDictionary: createSpellingDictionary_1.createIgnoreWordsDictionary,
|
|
26
|
+
createSpellingDictionary: createSpellingDictionary_1.createSpellingDictionary,
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -15,8 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./SpellingDictionary"), exports);
|
|
18
|
-
__exportStar(require("./SpellingDictionaryCollection"), exports);
|
|
19
18
|
__exportStar(require("./Dictionaries"), exports);
|
|
20
|
-
__exportStar(require("./createSpellingDictionary"), exports);
|
|
21
19
|
__exportStar(require("./SpellingDictionaryError"), exports);
|
|
22
20
|
//# sourceMappingURL=index.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -6,14 +6,16 @@ import * as Text from './util/text';
|
|
|
6
6
|
export * from '@cspell/cspell-types';
|
|
7
7
|
export { asyncIterableToArray, readFile, readFileSync, writeToFile, writeToFileIterable, writeToFileIterableP, } from 'cspell-io';
|
|
8
8
|
export { ExcludeFilesGlobMap, ExclusionFunction } from './exclusionHelper';
|
|
9
|
-
export {
|
|
9
|
+
export { FeatureFlag, FeatureFlags, getSystemFeatureFlags, UnknownFeatureFlagError } from './FeatureFlags';
|
|
10
|
+
export { getLanguagesForBasename as getLanguageIdsForBaseFilename, getLanguagesForExt } from './LanguageIds';
|
|
10
11
|
export { createTextDocument, updateTextDocument } from './Models/TextDocument';
|
|
11
12
|
export type { CreateTextDocumentParams, TextDocument, TextDocumentLine } from './Models/TextDocument';
|
|
12
13
|
export * from './Settings';
|
|
13
14
|
export { defaultFileName as defaultSettingsFilename } from './Settings';
|
|
14
15
|
export { combineTextAndLanguageSettings, combineTextAndLanguageSettings as constructSettingsForText, } from './Settings/TextDocumentSettings';
|
|
15
16
|
export { determineFinalDocumentSettings, DetermineFinalDocumentSettingsResult, Document, fileToDocument, fileToTextDocument, isBinaryFile, spellCheckDocument, spellCheckFile, SpellCheckFileOptions, SpellCheckFileResult, } from './spellCheckFile';
|
|
16
|
-
export { CompoundWordsMethod, createSpellingDictionary, isSpellingDictionaryLoadError, refreshDictionaryCache, SpellingDictionary,
|
|
17
|
+
export { CompoundWordsMethod, createSpellingDictionary, isSpellingDictionaryLoadError, refreshDictionaryCache, SpellingDictionary, SpellingDictionaryLoadError, SuggestionCollector, SuggestionResult, SuggestOptions, } from './SpellingDictionary';
|
|
18
|
+
export { SpellingDictionaryCollectionLegacy as SpellingDictionaryCollection } from './SpellingDictionary/SpellingDictionaryLibOld/SpellingDictionaryCollection';
|
|
17
19
|
export { SuggestionError, suggestionsForWord, suggestionsForWords } from './suggestions';
|
|
18
20
|
export type { SuggestedWord, SuggestionOptions, SuggestionsForWordResult } from './suggestions';
|
|
19
21
|
export { DocumentValidator, DocumentValidatorOptions } from './textValidation';
|
package/dist/index.js
CHANGED
|
@@ -26,7 +26,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
26
26
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.getDictionary = exports.clearCachedFiles = exports.ExclusionHelper = exports.Link = exports.Text = exports.validateText = exports.IncludeExcludeFlag = exports.checkTextDocument = exports.checkText = exports.resolveFile = exports.setLogger = exports.getLogger = exports.traceWordsAsync = exports.traceWords = exports.DocumentValidator = exports.suggestionsForWords = exports.suggestionsForWord = exports.SuggestionError = exports.
|
|
29
|
+
exports.getDictionary = exports.clearCachedFiles = exports.ExclusionHelper = exports.Link = exports.Text = exports.validateText = exports.IncludeExcludeFlag = exports.checkTextDocument = exports.checkText = exports.resolveFile = exports.setLogger = exports.getLogger = exports.traceWordsAsync = exports.traceWords = exports.DocumentValidator = exports.suggestionsForWords = exports.suggestionsForWord = exports.SuggestionError = exports.SpellingDictionaryCollection = exports.SpellingDictionaryLoadError = exports.refreshDictionaryCache = exports.isSpellingDictionaryLoadError = exports.createSpellingDictionary = exports.CompoundWordsMethod = exports.spellCheckFile = exports.spellCheckDocument = exports.isBinaryFile = exports.fileToTextDocument = exports.fileToDocument = exports.determineFinalDocumentSettings = exports.constructSettingsForText = exports.combineTextAndLanguageSettings = exports.defaultSettingsFilename = exports.updateTextDocument = exports.createTextDocument = exports.getLanguagesForExt = exports.getLanguageIdsForBaseFilename = exports.UnknownFeatureFlagError = exports.getSystemFeatureFlags = exports.FeatureFlags = exports.writeToFileIterableP = exports.writeToFileIterable = exports.writeToFile = exports.readFileSync = exports.readFile = exports.asyncIterableToArray = void 0;
|
|
30
30
|
const ExclusionHelper = __importStar(require("./exclusionHelper"));
|
|
31
31
|
exports.ExclusionHelper = ExclusionHelper;
|
|
32
32
|
const Settings_1 = require("./Settings");
|
|
@@ -44,9 +44,13 @@ Object.defineProperty(exports, "readFileSync", { enumerable: true, get: function
|
|
|
44
44
|
Object.defineProperty(exports, "writeToFile", { enumerable: true, get: function () { return cspell_io_1.writeToFile; } });
|
|
45
45
|
Object.defineProperty(exports, "writeToFileIterable", { enumerable: true, get: function () { return cspell_io_1.writeToFileIterable; } });
|
|
46
46
|
Object.defineProperty(exports, "writeToFileIterableP", { enumerable: true, get: function () { return cspell_io_1.writeToFileIterableP; } });
|
|
47
|
+
var FeatureFlags_1 = require("./FeatureFlags");
|
|
48
|
+
Object.defineProperty(exports, "FeatureFlags", { enumerable: true, get: function () { return FeatureFlags_1.FeatureFlags; } });
|
|
49
|
+
Object.defineProperty(exports, "getSystemFeatureFlags", { enumerable: true, get: function () { return FeatureFlags_1.getSystemFeatureFlags; } });
|
|
50
|
+
Object.defineProperty(exports, "UnknownFeatureFlagError", { enumerable: true, get: function () { return FeatureFlags_1.UnknownFeatureFlagError; } });
|
|
47
51
|
var LanguageIds_1 = require("./LanguageIds");
|
|
48
|
-
Object.defineProperty(exports, "getLanguagesForExt", { enumerable: true, get: function () { return LanguageIds_1.getLanguagesForExt; } });
|
|
49
52
|
Object.defineProperty(exports, "getLanguageIdsForBaseFilename", { enumerable: true, get: function () { return LanguageIds_1.getLanguagesForBasename; } });
|
|
53
|
+
Object.defineProperty(exports, "getLanguagesForExt", { enumerable: true, get: function () { return LanguageIds_1.getLanguagesForExt; } });
|
|
50
54
|
var TextDocument_1 = require("./Models/TextDocument");
|
|
51
55
|
Object.defineProperty(exports, "createTextDocument", { enumerable: true, get: function () { return TextDocument_1.createTextDocument; } });
|
|
52
56
|
Object.defineProperty(exports, "updateTextDocument", { enumerable: true, get: function () { return TextDocument_1.updateTextDocument; } });
|
|
@@ -68,8 +72,10 @@ Object.defineProperty(exports, "CompoundWordsMethod", { enumerable: true, get: f
|
|
|
68
72
|
Object.defineProperty(exports, "createSpellingDictionary", { enumerable: true, get: function () { return SpellingDictionary_2.createSpellingDictionary; } });
|
|
69
73
|
Object.defineProperty(exports, "isSpellingDictionaryLoadError", { enumerable: true, get: function () { return SpellingDictionary_2.isSpellingDictionaryLoadError; } });
|
|
70
74
|
Object.defineProperty(exports, "refreshDictionaryCache", { enumerable: true, get: function () { return SpellingDictionary_2.refreshDictionaryCache; } });
|
|
71
|
-
|
|
75
|
+
// SpellingDictionaryCollection,
|
|
72
76
|
Object.defineProperty(exports, "SpellingDictionaryLoadError", { enumerable: true, get: function () { return SpellingDictionary_2.SpellingDictionaryLoadError; } });
|
|
77
|
+
var SpellingDictionaryCollection_1 = require("./SpellingDictionary/SpellingDictionaryLibOld/SpellingDictionaryCollection");
|
|
78
|
+
Object.defineProperty(exports, "SpellingDictionaryCollection", { enumerable: true, get: function () { return SpellingDictionaryCollection_1.SpellingDictionaryCollectionLegacy; } });
|
|
73
79
|
var suggestions_1 = require("./suggestions");
|
|
74
80
|
Object.defineProperty(exports, "SuggestionError", { enumerable: true, get: function () { return suggestions_1.SuggestionError; } });
|
|
75
81
|
Object.defineProperty(exports, "suggestionsForWord", { enumerable: true, get: function () { return suggestions_1.suggestionsForWord; } });
|
|
@@ -28,7 +28,7 @@ export interface ValidationResult extends TextOffsetRW, Pick<Issue, 'message' |
|
|
|
28
28
|
isFound?: boolean | undefined;
|
|
29
29
|
}
|
|
30
30
|
export declare type ValidationResultRO = Readonly<ValidationResult>;
|
|
31
|
-
export declare type
|
|
31
|
+
export declare type LineValidatorFn = (line: LineSegment) => Iterable<ValidationResult>;
|
|
32
32
|
export interface LineSegment {
|
|
33
33
|
line: TextOffsetRO;
|
|
34
34
|
segment: TextOffsetRO;
|
|
@@ -37,5 +37,5 @@ export interface MappedTextValidationResult extends MappedText {
|
|
|
37
37
|
isFlagged?: boolean | undefined;
|
|
38
38
|
isFound?: boolean | undefined;
|
|
39
39
|
}
|
|
40
|
-
export declare type
|
|
40
|
+
export declare type TextValidatorFn = (text: MappedText) => Iterable<MappedTextValidationResult>;
|
|
41
41
|
//# sourceMappingURL=ValidationTypes.d.ts.map
|
|
@@ -3,8 +3,8 @@ import { CSpellSettingsInternal, CSpellSettingsInternalFinalized } from '../Mode
|
|
|
3
3
|
import { TextDocument } from '../Models/TextDocument';
|
|
4
4
|
import { SpellingDictionaryCollection } from '../SpellingDictionary';
|
|
5
5
|
import { MatchRange } from '../util/TextRange';
|
|
6
|
+
import { TextValidator } from './lineValidatorFactory';
|
|
6
7
|
import { SimpleRange } from './parsedText';
|
|
7
|
-
import type { TextValidator } from './ValidationTypes';
|
|
8
8
|
import { ValidationOptions } from './ValidationTypes';
|
|
9
9
|
import { ValidateTextOptions, ValidationIssue } from './validator';
|
|
10
10
|
export interface DocumentValidatorOptions extends ValidateTextOptions {
|
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.DocumentValidator = void 0;
|
|
7
|
-
const
|
|
7
|
+
const sync_1 = require("@cspell/cspell-pipe/sync");
|
|
8
8
|
const cspell_types_1 = require("@cspell/cspell-types");
|
|
9
9
|
const assert_1 = __importDefault(require("assert"));
|
|
10
10
|
const cspell_glob_1 = require("cspell-glob");
|
|
@@ -190,7 +190,7 @@ class DocumentValidator {
|
|
|
190
190
|
}
|
|
191
191
|
return { text, offset, line, length, isFlagged, isFound };
|
|
192
192
|
}
|
|
193
|
-
const issues = [...(0,
|
|
193
|
+
const issues = [...(0, sync_1.pipeSync)(segmenter(parsedText), (0, sync_1.opConcatMap)(textValidator.validate), (0, sync_1.opMap)(mapToIssue))];
|
|
194
194
|
if (!this.options.generateSuggestions) {
|
|
195
195
|
return issues;
|
|
196
196
|
}
|
|
@@ -223,6 +223,7 @@ class DocumentValidator {
|
|
|
223
223
|
(0, assert_1.default)(this._preparations, ERROR_NOT_PREPARED);
|
|
224
224
|
const spellingIssues = forceCheck || this.shouldCheckDocument() ? [...this._checkParsedText(this._parse())] : [];
|
|
225
225
|
const directiveIssues = this.checkDocumentDirectives();
|
|
226
|
+
// console.log('Stats: %o', this._preparations.textValidator.lineValidator.dict.stats());
|
|
226
227
|
const allIssues = spellingIssues.concat(directiveIssues).sort((a, b) => a.offset - b.offset);
|
|
227
228
|
return allIssues;
|
|
228
229
|
}
|
|
@@ -252,7 +253,7 @@ class DocumentValidator {
|
|
|
252
253
|
this._updatePrep();
|
|
253
254
|
}
|
|
254
255
|
defaultParser() {
|
|
255
|
-
return (0,
|
|
256
|
+
return (0, sync_1.pipeSync)(this.document.getLines(), (0, sync_1.opMap)((line) => {
|
|
256
257
|
const { text, offset } = line;
|
|
257
258
|
const range = [offset, offset + text.length];
|
|
258
259
|
return { text, range };
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CachingDictionary } from 'cspell-dictionary';
|
|
2
2
|
import { TextOffsetRO } from './ValidationTypes';
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
useCompounds: boolean | undefined;
|
|
6
|
-
}
|
|
7
|
-
export declare function hasWordCheck(dict: SpellingDictionary, word: string, options: IsWordValidOptions): boolean;
|
|
8
|
-
export declare function isWordValidWithEscapeRetry(dict: SpellingDictionary, wo: TextOffsetRO, line: TextOffsetRO, options: IsWordValidOptions): boolean;
|
|
3
|
+
export declare function hasWordCheck(dict: CachingDictionary, word: string): boolean;
|
|
4
|
+
export declare function isWordValidWithEscapeRetry(dict: CachingDictionary, wo: TextOffsetRO, line: TextOffsetRO): boolean;
|
|
9
5
|
export declare const __testing__: {
|
|
10
6
|
hasWordCheck: typeof hasWordCheck;
|
|
11
7
|
};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.__testing__ = exports.isWordValidWithEscapeRetry = exports.hasWordCheck = void 0;
|
|
4
|
-
function hasWordCheck(dict, word
|
|
4
|
+
function hasWordCheck(dict, word) {
|
|
5
5
|
word = word.replace(/\\/g, '');
|
|
6
|
-
return dict.has(word
|
|
6
|
+
return dict.has(word);
|
|
7
7
|
}
|
|
8
8
|
exports.hasWordCheck = hasWordCheck;
|
|
9
|
-
function isWordValidWithEscapeRetry(dict, wo, line
|
|
10
|
-
const firstTry = hasWordCheck(dict, wo.text
|
|
9
|
+
function isWordValidWithEscapeRetry(dict, wo, line) {
|
|
10
|
+
const firstTry = hasWordCheck(dict, wo.text);
|
|
11
11
|
return (firstTry ||
|
|
12
12
|
// Drop the first letter if it is preceded by a '\'.
|
|
13
|
-
(line.text[wo.offset - line.offset - 1] === '\\' && hasWordCheck(dict, wo.text.slice(1)
|
|
13
|
+
(line.text[wo.offset - line.offset - 1] === '\\' && hasWordCheck(dict, wo.text.slice(1))));
|
|
14
14
|
}
|
|
15
15
|
exports.isWordValidWithEscapeRetry = isWordValidWithEscapeRetry;
|
|
16
16
|
exports.__testing__ = {
|
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
import { SpellingDictionary } from '
|
|
2
|
-
import type {
|
|
3
|
-
|
|
1
|
+
import { CachingDictionary, SpellingDictionary } from 'cspell-dictionary';
|
|
2
|
+
import type { LineValidatorFn, TextValidatorFn, ValidationOptions } from './ValidationTypes';
|
|
3
|
+
interface LineValidator {
|
|
4
|
+
fn: LineValidatorFn;
|
|
5
|
+
dict: CachingDictionary;
|
|
6
|
+
}
|
|
7
|
+
export declare function lineValidatorFactory(sDict: SpellingDictionary, options: ValidationOptions): LineValidator;
|
|
8
|
+
export interface TextValidator {
|
|
9
|
+
validate: TextValidatorFn;
|
|
10
|
+
lineValidator: LineValidator;
|
|
11
|
+
}
|
|
4
12
|
export declare function textValidatorFactory(dict: SpellingDictionary, options: ValidationOptions): TextValidator;
|
|
13
|
+
export {};
|
|
5
14
|
//# sourceMappingURL=lineValidatorFactory.d.ts.map
|
|
@@ -24,22 +24,23 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.textValidatorFactory = exports.lineValidatorFactory = void 0;
|
|
27
|
-
const
|
|
27
|
+
const sync_1 = require("@cspell/cspell-pipe/sync");
|
|
28
|
+
const cspell_dictionary_1 = require("cspell-dictionary");
|
|
28
29
|
const gensequence_1 = require("gensequence");
|
|
29
30
|
const RxPat = __importStar(require("../Settings/RegExpPatterns"));
|
|
30
31
|
const Text = __importStar(require("../util/text"));
|
|
31
32
|
const util_1 = require("../util/util");
|
|
32
33
|
const wordSplitter_1 = require("../util/wordSplitter");
|
|
33
|
-
const textValidator_1 = require("./textValidator");
|
|
34
34
|
const isWordValid_1 = require("./isWordValid");
|
|
35
35
|
const parsedText_1 = require("./parsedText");
|
|
36
|
-
|
|
36
|
+
const textValidator_1 = require("./textValidator");
|
|
37
|
+
function lineValidatorFactory(sDict, options) {
|
|
37
38
|
const { minWordLength = textValidator_1.defaultMinWordLength, flagWords = [], allowCompoundWords = false, ignoreCase = true, } = options;
|
|
38
39
|
const hasWordOptions = {
|
|
39
40
|
ignoreCase,
|
|
40
41
|
useCompounds: allowCompoundWords || undefined, // let the dictionaries decide on useCompounds if allow is false
|
|
41
42
|
};
|
|
42
|
-
const dictCol =
|
|
43
|
+
const dictCol = (0, cspell_dictionary_1.createCachingDictionary)(sDict, hasWordOptions);
|
|
43
44
|
const setOfFlagWords = new Set(flagWords);
|
|
44
45
|
const setOfKnownSuccessfulWords = new Set();
|
|
45
46
|
const rememberFilter = (fn) => (v) => {
|
|
@@ -57,7 +58,7 @@ function lineValidatorFactory(dict, options) {
|
|
|
57
58
|
return setOfFlagWords.has(text) || setOfFlagWords.has(text.toLowerCase()) || dictCol.isForbidden(text);
|
|
58
59
|
}
|
|
59
60
|
function isWordIgnored(word) {
|
|
60
|
-
return
|
|
61
|
+
return dictCol.isNoSuggestWord(word);
|
|
61
62
|
}
|
|
62
63
|
function isWordFlagged(word) {
|
|
63
64
|
const isIgnored = isWordIgnored(word.text);
|
|
@@ -68,31 +69,28 @@ function lineValidatorFactory(dict, options) {
|
|
|
68
69
|
word.isFlagged = isWordFlagged(word);
|
|
69
70
|
return word;
|
|
70
71
|
}
|
|
71
|
-
function checkWord(word
|
|
72
|
+
function checkWord(word) {
|
|
72
73
|
const isIgnored = isWordIgnored(word.text);
|
|
73
74
|
const { isFlagged = !isIgnored && testForFlaggedWord(word) } = word;
|
|
74
|
-
const isFound = isFlagged
|
|
75
|
-
? undefined
|
|
76
|
-
: isIgnored || (0, isWordValid_1.isWordValidWithEscapeRetry)(dictCol, word, word.line, options);
|
|
75
|
+
const isFound = isFlagged ? undefined : isIgnored || (0, isWordValid_1.isWordValidWithEscapeRetry)(dictCol, word, word.line);
|
|
77
76
|
return (0, util_1.clean)({ ...word, isFlagged, isFound });
|
|
78
77
|
}
|
|
79
78
|
const fn = (lineSegment) => {
|
|
80
79
|
function splitterIsValid(word) {
|
|
81
80
|
return (setOfKnownSuccessfulWords.has(word.text) ||
|
|
82
|
-
(!testForFlaggedWord(word) &&
|
|
83
|
-
(0, isWordValid_1.isWordValidWithEscapeRetry)(dictCol, word, lineSegment.line, hasWordOptions)));
|
|
81
|
+
(!testForFlaggedWord(word) && (0, isWordValid_1.isWordValidWithEscapeRetry)(dictCol, word, lineSegment.line)));
|
|
84
82
|
}
|
|
85
83
|
function checkFullWord(vr) {
|
|
86
84
|
if (vr.isFlagged) {
|
|
87
85
|
return [vr];
|
|
88
86
|
}
|
|
89
|
-
const codeWordResults = (0,
|
|
87
|
+
const codeWordResults = (0, sync_1.toArray)((0, sync_1.pipe)(Text.extractWordsFromCodeTextOffset(vr), (0, sync_1.opFilter)(filterAlreadyChecked), (0, sync_1.opMap)((t) => ({ ...t, line: vr.line })), (0, sync_1.opMap)(checkFlagWords), (0, sync_1.opFilter)(rememberFilter((wo) => wo.text.length >= minWordLength || !!wo.isFlagged)), (0, sync_1.opMap)((wo) => (wo.isFlagged ? wo : checkWord(wo))), (0, sync_1.opFilter)(rememberFilter((wo) => wo.isFlagged || !wo.isFound)), (0, sync_1.opFilter)(rememberFilter((wo) => !RxPat.regExRepeatedChar.test(wo.text))),
|
|
90
88
|
// get back the original text.
|
|
91
|
-
(0,
|
|
89
|
+
(0, sync_1.opMap)((wo) => ({
|
|
92
90
|
...wo,
|
|
93
91
|
text: Text.extractText(lineSegment.segment, wo.offset, wo.offset + wo.text.length),
|
|
94
92
|
}))));
|
|
95
|
-
if (!codeWordResults.length || isWordIgnored(vr.text) || checkWord(vr
|
|
93
|
+
if (!codeWordResults.length || isWordIgnored(vr.text) || checkWord(vr).isFound) {
|
|
96
94
|
rememberFilter((_) => false)(vr);
|
|
97
95
|
return [];
|
|
98
96
|
}
|
|
@@ -107,7 +105,7 @@ function lineValidatorFactory(dict, options) {
|
|
|
107
105
|
};
|
|
108
106
|
return [vr];
|
|
109
107
|
}
|
|
110
|
-
const mismatches = (0,
|
|
108
|
+
const mismatches = (0, sync_1.toArray)((0, sync_1.pipe)(Text.extractWordsFromTextOffset(possibleWord), (0, sync_1.opFilter)(filterAlreadyChecked), (0, sync_1.opMap)((wo) => ({ ...wo, line: lineSegment.line })), (0, sync_1.opMap)(checkFlagWords), (0, sync_1.opFilter)(rememberFilter((wo) => wo.text.length >= minWordLength || !!wo.isFlagged)), (0, sync_1.opConcatMap)(checkFullWord)));
|
|
111
109
|
if (mismatches.length) {
|
|
112
110
|
// Try the more expensive word splitter
|
|
113
111
|
const splitResult = (0, wordSplitter_1.split)(lineSegment.segment, possibleWord.offset, splitterIsValid);
|
|
@@ -118,15 +116,16 @@ function lineValidatorFactory(dict, options) {
|
|
|
118
116
|
}
|
|
119
117
|
return mismatches;
|
|
120
118
|
}
|
|
121
|
-
const checkedPossibleWords = (0, gensequence_1.genSequence)((0,
|
|
119
|
+
const checkedPossibleWords = (0, gensequence_1.genSequence)((0, sync_1.pipe)(Text.extractPossibleWordsFromTextOffset(lineSegment.segment), (0, sync_1.opFilter)(filterAlreadyChecked), (0, sync_1.opConcatMap)(checkPossibleWords)));
|
|
122
120
|
return checkedPossibleWords;
|
|
123
121
|
};
|
|
124
|
-
return fn;
|
|
122
|
+
return { fn, dict: dictCol };
|
|
125
123
|
}
|
|
126
124
|
exports.lineValidatorFactory = lineValidatorFactory;
|
|
127
125
|
function textValidatorFactory(dict, options) {
|
|
128
126
|
const lineValidator = lineValidatorFactory(dict, options);
|
|
129
|
-
|
|
127
|
+
const lineValidatorFn = lineValidator.fn;
|
|
128
|
+
function validate(pText) {
|
|
130
129
|
const { text, range: srcRange, map } = pText;
|
|
131
130
|
const srcOffset = srcRange[0];
|
|
132
131
|
const segment = { text, offset: 0 };
|
|
@@ -137,9 +136,12 @@ function textValidatorFactory(dict, options) {
|
|
|
137
136
|
const range = [r[0] + srcOffset, r[1] + srcOffset];
|
|
138
137
|
return { text, range, isFlagged, isFound };
|
|
139
138
|
}
|
|
140
|
-
return [...
|
|
139
|
+
return [...lineValidatorFn(lineSegment)].map(mapBackToOriginSimple);
|
|
141
140
|
}
|
|
142
|
-
return
|
|
141
|
+
return {
|
|
142
|
+
validate,
|
|
143
|
+
lineValidator,
|
|
144
|
+
};
|
|
143
145
|
}
|
|
144
146
|
exports.textValidatorFactory = textValidatorFactory;
|
|
145
147
|
//# sourceMappingURL=lineValidatorFactory.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Sequence } from 'gensequence';
|
|
2
|
-
import { SpellingDictionary } from '../SpellingDictionary/SpellingDictionary';
|
|
2
|
+
import { SpellingDictionary } from '../SpellingDictionary/SpellingDictionaryLibOld/SpellingDictionary';
|
|
3
3
|
import * as TextRange from '../util/TextRange';
|
|
4
4
|
import { IncludeExcludeOptions, LineSegment, ValidationOptions, ValidationResult } from './ValidationTypes';
|
|
5
5
|
export declare const defaultMaxNumberOfProblems = 200;
|
|
@@ -24,7 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports._testMethods = exports.mapLineSegmentAgainstRangesFactory = exports.calcTextInclusionRanges = exports.validateText = exports.minWordSplitLen = exports.defaultMinWordLength = exports.defaultMaxDuplicateProblems = exports.defaultMaxNumberOfProblems = void 0;
|
|
27
|
-
const
|
|
27
|
+
const sync_1 = require("@cspell/cspell-pipe/sync");
|
|
28
28
|
const gensequence_1 = require("gensequence");
|
|
29
29
|
const Text = __importStar(require("../util/text"));
|
|
30
30
|
const TextRange = __importStar(require("../util/TextRange"));
|
|
@@ -41,15 +41,16 @@ function validateText(text, dict, options) {
|
|
|
41
41
|
const { maxNumberOfProblems = exports.defaultMaxNumberOfProblems, maxDuplicateProblems = exports.defaultMaxDuplicateProblems } = options;
|
|
42
42
|
const mapOfProblems = new Map();
|
|
43
43
|
const includeRanges = calcTextInclusionRanges(text, options);
|
|
44
|
-
const
|
|
45
|
-
const
|
|
44
|
+
const lineValidator = (0, lineValidatorFactory_1.lineValidatorFactory)(dict, options);
|
|
45
|
+
const validator = lineValidator.fn;
|
|
46
|
+
const iter = (0, sync_1.pipe)(Text.extractLinesOfText(text), (0, sync_1.opConcatMap)(mapLineToLineSegments(includeRanges)), (0, sync_1.opConcatMap)(validator), (0, sync_1.opFilter)((wo) => {
|
|
46
47
|
const word = wo.text;
|
|
47
48
|
// Keep track of the number of times we have seen the same problem
|
|
48
49
|
const n = (mapOfProblems.get(word) || 0) + 1;
|
|
49
50
|
mapOfProblems.set(word, n);
|
|
50
51
|
// Filter out if there is too many
|
|
51
52
|
return n <= maxDuplicateProblems;
|
|
52
|
-
}), (0,
|
|
53
|
+
}), (0, sync_1.opTake)(maxNumberOfProblems));
|
|
53
54
|
return (0, gensequence_1.genSequence)(iter);
|
|
54
55
|
}
|
|
55
56
|
exports.validateText = validateText;
|
package/dist/util/Memorizer.d.ts
CHANGED
|
@@ -35,18 +35,6 @@ export declare function memorizer<F extends (...args: Primitive[]) => any, Args
|
|
|
35
35
|
* @returns A function
|
|
36
36
|
*/
|
|
37
37
|
export declare function memorizerKeyBy<F extends (...args: any[]) => any, Args extends Parameters<F> = Parameters<F>, R extends ReturnType<F> = ReturnType<F>>(fn: F, keyFn: (...args: Args) => string, size?: number): (...args: Args) => R;
|
|
38
|
-
/**
|
|
39
|
-
* Create a function that memorizes the last call. If the next call is called with the same arguments, the
|
|
40
|
-
* the last value is returned.
|
|
41
|
-
* @param fn - function to memorize
|
|
42
|
-
* @returns a new function.
|
|
43
|
-
*/
|
|
44
|
-
export declare function memorizeLastCall<T>(fn: (...p: []) => T): (...p: []) => T;
|
|
45
|
-
export declare function memorizeLastCall<T, K0>(fn: (...p: [K0]) => T): (...p: [K0]) => T;
|
|
46
|
-
export declare function memorizeLastCall<T, K0, K1>(fn: (...p: [K0, K1]) => T): (...p: [K0, K1]) => T;
|
|
47
|
-
export declare function memorizeLastCall<T, K0, K1, K2>(fn: (...p: [K0, K1, K2]) => T): (...p: [K0, K1, K2]) => T;
|
|
48
|
-
export declare function memorizeLastCall<T, K0, K1, K2, K3>(fn: (...p: [K0, K1, K2, K3]) => T): (...p: [K0, K1, K2, K3]) => T;
|
|
49
|
-
export declare function memorizeLastCall<T, K>(fn: (...p: [...K[]]) => T): (...p: [...K[]]) => T;
|
|
50
38
|
/**
|
|
51
39
|
* Creates a function that will call `fn` exactly once when invoked and remember the value returned.
|
|
52
40
|
* All subsequent calls will return exactly same value.
|
package/dist/util/Memorizer.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.memorizerAll = exports.callOnce = exports.
|
|
4
|
-
const util_1 = require("./util");
|
|
3
|
+
exports.memorizerAll = exports.callOnce = exports.memorizerKeyBy = exports.memorizer = void 0;
|
|
5
4
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
6
5
|
const defaultSize = 50000;
|
|
7
6
|
/**
|
|
@@ -60,19 +59,6 @@ function memorizerKeyBy(fn, keyFn, size = defaultSize) {
|
|
|
60
59
|
};
|
|
61
60
|
}
|
|
62
61
|
exports.memorizerKeyBy = memorizerKeyBy;
|
|
63
|
-
function memorizeLastCall(fn) {
|
|
64
|
-
let last;
|
|
65
|
-
return (...p) => {
|
|
66
|
-
if (last && (0, util_1.isArrayEqual)(last.args, p)) {
|
|
67
|
-
return last.value;
|
|
68
|
-
}
|
|
69
|
-
const args = p;
|
|
70
|
-
const value = fn(...args);
|
|
71
|
-
last = { args, value };
|
|
72
|
-
return value;
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
exports.memorizeLastCall = memorizeLastCall;
|
|
76
62
|
/**
|
|
77
63
|
* Creates a function that will call `fn` exactly once when invoked and remember the value returned.
|
|
78
64
|
* All subsequent calls will return exactly same value.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a function that memorizes the last call. If the next call is called with the same arguments, the
|
|
3
|
+
* the last value is returned.
|
|
4
|
+
* @param fn - function to memorize
|
|
5
|
+
* @returns a new function.
|
|
6
|
+
*/
|
|
7
|
+
export declare function memorizeLastCall<T>(fn: (...p: []) => T): (...p: []) => T;
|
|
8
|
+
export declare function memorizeLastCall<T, K0>(fn: (...p: [K0]) => T): (...p: [K0]) => T;
|
|
9
|
+
export declare function memorizeLastCall<T, K0, K1>(fn: (...p: [K0, K1]) => T): (...p: [K0, K1]) => T;
|
|
10
|
+
export declare function memorizeLastCall<T, K0, K1, K2>(fn: (...p: [K0, K1, K2]) => T): (...p: [K0, K1, K2]) => T;
|
|
11
|
+
export declare function memorizeLastCall<T, K0, K1, K2, K3>(fn: (...p: [K0, K1, K2, K3]) => T): (...p: [K0, K1, K2, K3]) => T;
|
|
12
|
+
export declare function memorizeLastCall<T, K>(fn: (...p: [...K[]]) => T): (...p: [...K[]]) => T;
|
|
13
|
+
//# sourceMappingURL=memorizeLastCall.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.memorizeLastCall = void 0;
|
|
4
|
+
const util_1 = require("./util");
|
|
5
|
+
function memorizeLastCall(fn) {
|
|
6
|
+
let last;
|
|
7
|
+
return (...p) => {
|
|
8
|
+
if (last && (0, util_1.isArrayEqual)(last.args, p)) {
|
|
9
|
+
return last.value;
|
|
10
|
+
}
|
|
11
|
+
const args = p;
|
|
12
|
+
const value = fn(...args);
|
|
13
|
+
last = { args, value };
|
|
14
|
+
return value;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
exports.memorizeLastCall = memorizeLastCall;
|
|
18
|
+
//# sourceMappingURL=memorizeLastCall.js.map
|
package/dist/util/text.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.__testing__ = exports.removeAccents = exports.calculateTextDocumentOffsets = exports.extractText = exports.textOffset = exports.matchCase = exports.camelToSnake = exports.snakeToCamel = exports.lcFirst = exports.ucFirst = exports.isFirstCharacterLower = exports.isFirstCharacterUpper = exports.isLowerCase = exports.isUpperCase = exports.extractWordsFromCodeTextOffset = exports.extractWordsFromCode = exports.extractPossibleWordsFromTextOffset = exports.cleanTextOffset = exports.cleanText = exports.extractWordsFromTextOffset = exports.extractWordsFromText = exports.extractLinesOfText = exports.matchToTextOffset = exports.matchStringToTextOffset = exports.match = exports.splitCamelCaseWord = exports.splitCamelCaseWordWithOffset = exports.stringToRegExp = void 0;
|
|
4
|
-
const
|
|
4
|
+
const sync_1 = require("@cspell/cspell-pipe/sync");
|
|
5
5
|
const gensequence_1 = require("gensequence");
|
|
6
6
|
const search_1 = require("./search");
|
|
7
7
|
const textRegex_1 = require("./textRegex");
|
|
@@ -42,7 +42,7 @@ function matchToTextOffset(reg, text) {
|
|
|
42
42
|
const textOffset = text;
|
|
43
43
|
const fnOffsetMap = offsetMap(textOffset.offset);
|
|
44
44
|
textOffset.text.matchAll(reg);
|
|
45
|
-
return (0,
|
|
45
|
+
return (0, sync_1.pipe)(match(reg, textOffset.text), (0, sync_1.opMap)((m) => fnOffsetMap({ text: m[0], offset: m.index || 0 })));
|
|
46
46
|
}
|
|
47
47
|
exports.matchToTextOffset = matchToTextOffset;
|
|
48
48
|
function extractLinesOfText(text) {
|
|
@@ -89,7 +89,7 @@ function extractWordsFromCode(text) {
|
|
|
89
89
|
}
|
|
90
90
|
exports.extractWordsFromCode = extractWordsFromCode;
|
|
91
91
|
function extractWordsFromCodeTextOffset(textOffset) {
|
|
92
|
-
return (0,
|
|
92
|
+
return (0, sync_1.pipe)(extractWordsFromTextOffset(textOffset), (0, sync_1.opConcatMap)(splitCamelCaseWordWithOffset));
|
|
93
93
|
}
|
|
94
94
|
exports.extractWordsFromCodeTextOffset = extractWordsFromCodeTextOffset;
|
|
95
95
|
function isUpperCase(word) {
|
|
@@ -160,7 +160,7 @@ function offsetMap(offset) {
|
|
|
160
160
|
function calculateTextDocumentOffsets(uri, doc, wordOffsets) {
|
|
161
161
|
const lines = [
|
|
162
162
|
-1,
|
|
163
|
-
...(0,
|
|
163
|
+
...(0, sync_1.pipe)(match(/\n/g, doc), (0, sync_1.opMap)((a) => a.index)),
|
|
164
164
|
doc.length,
|
|
165
165
|
];
|
|
166
166
|
let lastRow = -1;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cspell-lib",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.11.0",
|
|
4
4
|
"description": "A library of useful functions used across various cspell tools.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -48,17 +48,18 @@
|
|
|
48
48
|
},
|
|
49
49
|
"homepage": "https://github.com/streetsidesoftware/cspell#readme",
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@cspell/cspell-bundled-dicts": "^6.
|
|
52
|
-
"@cspell/cspell-pipe": "^6.
|
|
53
|
-
"@cspell/cspell-types": "^6.
|
|
51
|
+
"@cspell/cspell-bundled-dicts": "^6.11.0",
|
|
52
|
+
"@cspell/cspell-pipe": "^6.11.0",
|
|
53
|
+
"@cspell/cspell-types": "^6.11.0",
|
|
54
54
|
"clear-module": "^4.1.2",
|
|
55
55
|
"comment-json": "^4.2.3",
|
|
56
56
|
"configstore": "^5.0.1",
|
|
57
57
|
"cosmiconfig": "^7.0.1",
|
|
58
|
-
"cspell-
|
|
59
|
-
"cspell-
|
|
60
|
-
"cspell-
|
|
61
|
-
"cspell-
|
|
58
|
+
"cspell-dictionary": "^6.11.0",
|
|
59
|
+
"cspell-glob": "^6.11.0",
|
|
60
|
+
"cspell-grammar": "^6.11.0",
|
|
61
|
+
"cspell-io": "^6.11.0",
|
|
62
|
+
"cspell-trie-lib": "^6.11.0",
|
|
62
63
|
"fast-equals": "^4.0.3",
|
|
63
64
|
"find-up": "^5.0.0",
|
|
64
65
|
"fs-extra": "^10.1.0",
|
|
@@ -83,15 +84,15 @@
|
|
|
83
84
|
"@cspell/dict-python": "^2.0.6",
|
|
84
85
|
"@types/configstore": "^5.0.1",
|
|
85
86
|
"@types/fs-extra": "^9.0.13",
|
|
86
|
-
"@types/jest": "^29.0
|
|
87
|
-
"@types/node": "^18.7.
|
|
87
|
+
"@types/jest": "^29.1.0",
|
|
88
|
+
"@types/node": "^18.7.23",
|
|
88
89
|
"cspell-dict-nl-nl": "^1.1.2",
|
|
89
|
-
"jest": "^29.
|
|
90
|
+
"jest": "^29.1.1",
|
|
90
91
|
"lorem-ipsum": "^2.0.8",
|
|
91
92
|
"rimraf": "^3.0.2",
|
|
92
|
-
"rollup": "^2.79.
|
|
93
|
+
"rollup": "^2.79.1",
|
|
93
94
|
"rollup-plugin-dts": "^4.2.2",
|
|
94
|
-
"ts-jest": "^29.0.
|
|
95
|
+
"ts-jest": "^29.0.3"
|
|
95
96
|
},
|
|
96
|
-
"gitHead": "
|
|
97
|
+
"gitHead": "664676692898c3b6aa150fb2c6656b56f49a54b8"
|
|
97
98
|
}
|