cspell-lib 10.2.0-alpha.5 → 10.2.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/lib/Settings/LanguageSettings.js +17 -1
- package/dist/lib/Settings/sanitizeSettings.js +3 -0
- package/dist/lib/Transform/IntlSegmentTextTransformer.d.ts +10 -0
- package/dist/lib/Transform/IntlSegmentTextTransformer.js +40 -0
- package/dist/lib/Transform/SubstitutionTransformer.d.ts +3 -1
- package/dist/lib/Transform/SubstitutionTransformer.js +10 -28
- package/dist/lib/Transform/TextMapEdit.d.ts +5 -0
- package/dist/lib/Transform/TextMapEdit.js +42 -0
- package/dist/lib/Transform/Transformer.d.ts +25 -0
- package/dist/lib/Transform/Transformer.js +27 -0
- package/dist/lib/Transform/index.d.ts +3 -0
- package/dist/lib/Transform/index.js +2 -0
- package/dist/lib/textValidation/docValidator.d.ts +3 -2
- package/dist/lib/textValidation/docValidator.js +22 -20
- package/dist/lib/textValidation/lineValidatorFactory.d.ts +2 -2
- package/dist/lib/textValidation/textValidator.d.ts +2 -2
- package/package.json +19 -19
|
@@ -38,9 +38,25 @@ export function normalizeLocale(locale) {
|
|
|
38
38
|
return _normalizeLocale(locale);
|
|
39
39
|
}
|
|
40
40
|
export function normalizeLocaleIntl(locale) {
|
|
41
|
-
const values = [...normalizeLocale(locale)].map((locale) => locale.replace(/^([a-z]{2})
|
|
41
|
+
const values = [...normalizeLocale(locale)].map((locale) => locale.replace(/^([a-z]{2})(?:-?([a-z]{4}))?-?([a-z]{2})$/, (_, lang, script, region) => toLocaleIntl(lang, script, region)));
|
|
42
42
|
return new Set(values);
|
|
43
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* See: https://developer.mozilla.org/en-US/docs/Glossary/BCP_47_language_tag
|
|
46
|
+
* @returns locale normalized to BCP_47
|
|
47
|
+
*/
|
|
48
|
+
function toLocaleIntl(lang, script, region) {
|
|
49
|
+
const parts = [lang];
|
|
50
|
+
if (script)
|
|
51
|
+
parts.push(firstUpper(script.toLowerCase()));
|
|
52
|
+
if (region)
|
|
53
|
+
parts.push(region.toUpperCase());
|
|
54
|
+
return parts.join('-');
|
|
55
|
+
}
|
|
56
|
+
function firstUpper(str) {
|
|
57
|
+
const [first, ...rest] = [...str];
|
|
58
|
+
return [first.toUpperCase(), ...rest].join('');
|
|
59
|
+
}
|
|
44
60
|
export function isLocaleInSet(locale, setOfLocals) {
|
|
45
61
|
const locales = normalizeLocale(locale);
|
|
46
62
|
return doSetsIntersect(locales, setOfLocals);
|
|
@@ -68,6 +68,7 @@ const handlers = {
|
|
|
68
68
|
suggestWords: copy1,
|
|
69
69
|
unknownWords: copy1,
|
|
70
70
|
useGitignore: copy1,
|
|
71
|
+
useIntlWordSegmentation: copy1,
|
|
71
72
|
usePnP: skip,
|
|
72
73
|
userWords: copy1,
|
|
73
74
|
validateDirectives: copy1,
|
|
@@ -183,6 +184,7 @@ const LanguageSettingsHandlers = {
|
|
|
183
184
|
substitutions: copy1,
|
|
184
185
|
suggestWords: copy1,
|
|
185
186
|
unknownWords: copy1,
|
|
187
|
+
useIntlWordSegmentation: copy1,
|
|
186
188
|
words: copy1,
|
|
187
189
|
// Experimental
|
|
188
190
|
parser: skip,
|
|
@@ -245,6 +247,7 @@ const OverridesHandlers = {
|
|
|
245
247
|
suggestionsTimeout: copy1,
|
|
246
248
|
suggestWords: copy1,
|
|
247
249
|
unknownWords: copy1,
|
|
250
|
+
useIntlWordSegmentation: copy1,
|
|
248
251
|
usePnP: skip,
|
|
249
252
|
words: copy1,
|
|
250
253
|
parser: skip,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MappedText } from '@cspell/cspell-types';
|
|
2
|
+
import type { TextTransformer } from './Transformer.js';
|
|
3
|
+
export declare class IntlSegmentTextTransformer implements TextTransformer {
|
|
4
|
+
#private;
|
|
5
|
+
constructor(locale: string | string[]);
|
|
6
|
+
transform(text: string | MappedText): MappedText;
|
|
7
|
+
transformAll(src: Iterable<string | MappedText>): Iterable<MappedText>;
|
|
8
|
+
}
|
|
9
|
+
export declare function createIntlSegmentTextTransformer(locale: string | string[]): IntlSegmentTextTransformer;
|
|
10
|
+
//# sourceMappingURL=IntlSegmentTextTransformer.d.ts.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { normalizeLocaleIntl } from '../Settings/LanguageSettings.js';
|
|
2
|
+
import { applyEditsToMappedText } from './TextMapEdit.js';
|
|
3
|
+
import { toMappedText } from './Transformer.js';
|
|
4
|
+
const regExSplitWordCharacters = /(?<=[\p{L}\p{M}])[\p{L}\p{M}]/uy;
|
|
5
|
+
export class IntlSegmentTextTransformer {
|
|
6
|
+
#locale;
|
|
7
|
+
constructor(locale) {
|
|
8
|
+
this.#locale = [...normalizeLocaleIntl(locale)];
|
|
9
|
+
}
|
|
10
|
+
transform(text) {
|
|
11
|
+
// Implement the transformation logic here
|
|
12
|
+
text = toMappedText(text);
|
|
13
|
+
return segmentText(text, new Intl.Segmenter(this.#locale, { granularity: 'word' }));
|
|
14
|
+
}
|
|
15
|
+
*transformAll(src) {
|
|
16
|
+
for (const item of src) {
|
|
17
|
+
yield this.transform(item);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function segmentText(mText, segmenter) {
|
|
22
|
+
const edits = [];
|
|
23
|
+
let lastIndex = -1;
|
|
24
|
+
const reg = new RegExp(regExSplitWordCharacters);
|
|
25
|
+
const text = mText.text;
|
|
26
|
+
for (const { segment, index } of segmenter.segment(mText.text)) {
|
|
27
|
+
const endIndex = index + segment.length;
|
|
28
|
+
reg.lastIndex = index;
|
|
29
|
+
if (index === lastIndex && reg.test(text)) {
|
|
30
|
+
const edit = { text: ' ' + segment, range: [index, endIndex] };
|
|
31
|
+
edits.push(edit);
|
|
32
|
+
}
|
|
33
|
+
lastIndex = endIndex;
|
|
34
|
+
}
|
|
35
|
+
return applyEditsToMappedText(mText, edits);
|
|
36
|
+
}
|
|
37
|
+
export function createIntlSegmentTextTransformer(locale) {
|
|
38
|
+
return new IntlSegmentTextTransformer(locale);
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=IntlSegmentTextTransformer.js.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { MappedText, SubstitutionDefinitions, Substitutions } from '@cspell/cspell-types';
|
|
2
|
+
import type { TextTransformer } from './Transformer.js';
|
|
2
3
|
type DeepReadonly<T> = T extends object ? {
|
|
3
4
|
readonly [K in keyof T]: DeepReadonly<T[K]>;
|
|
4
5
|
} : T;
|
|
@@ -7,10 +8,11 @@ export interface SubstitutionInfo {
|
|
|
7
8
|
substitutionDefinitions?: SubstitutionDefinitions | undefined;
|
|
8
9
|
}
|
|
9
10
|
export type ReadonlySubstitutionInfo = DeepReadonly<SubstitutionInfo>;
|
|
10
|
-
export declare class SubstitutionTransformer {
|
|
11
|
+
export declare class SubstitutionTransformer implements TextTransformer {
|
|
11
12
|
#private;
|
|
12
13
|
constructor(subMap: Map<string, string> | undefined);
|
|
13
14
|
transform(text: string | MappedText): MappedText;
|
|
15
|
+
transformAll(src: Iterable<string | MappedText>): Iterable<MappedText>;
|
|
14
16
|
transformString(text: string): MappedText;
|
|
15
17
|
}
|
|
16
18
|
export interface CreateSubstitutionTransformerResult {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { GTrie } from 'cspell-trie-lib';
|
|
2
|
-
import {
|
|
2
|
+
import { mergeSourceMaps } from './SourceMap.js';
|
|
3
|
+
import { applyEditsToText } from './TextMapEdit.js';
|
|
4
|
+
import { toMappedText } from './Transformer.js';
|
|
3
5
|
export class SubstitutionTransformer {
|
|
4
6
|
#trie;
|
|
5
7
|
constructor(subMap) {
|
|
@@ -21,36 +23,16 @@ export class SubstitutionTransformer {
|
|
|
21
23
|
};
|
|
22
24
|
return result;
|
|
23
25
|
}
|
|
26
|
+
*transformAll(src) {
|
|
27
|
+
for (const item of src) {
|
|
28
|
+
yield this.transform(item);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
24
31
|
transformString(text) {
|
|
25
32
|
if (!this.#trie) {
|
|
26
|
-
return
|
|
27
|
-
}
|
|
28
|
-
const map = [0, 0];
|
|
29
|
-
let repText = '';
|
|
30
|
-
let lastEnd = 0;
|
|
31
|
-
for (const edit of calcEdits(text, this.#trie)) {
|
|
32
|
-
if (edit.range[0] > lastEnd) {
|
|
33
|
-
repText += text.slice(lastEnd, edit.range[0]);
|
|
34
|
-
map.push(edit.range[0], repText.length);
|
|
35
|
-
}
|
|
36
|
-
repText += edit.text;
|
|
37
|
-
map.push(edit.range[1], repText.length);
|
|
38
|
-
lastEnd = edit.range[1];
|
|
39
|
-
}
|
|
40
|
-
if (lastEnd === 0) {
|
|
41
|
-
return { text, range: [0, text.length], rawText: text };
|
|
33
|
+
return toMappedText(text);
|
|
42
34
|
}
|
|
43
|
-
|
|
44
|
-
repText += text.slice(lastEnd);
|
|
45
|
-
map.push(text.length, repText.length);
|
|
46
|
-
}
|
|
47
|
-
const result = {
|
|
48
|
-
text: repText,
|
|
49
|
-
range: [0, text.length],
|
|
50
|
-
map: mapOffsetPairsToSourceMap(map),
|
|
51
|
-
rawText: text,
|
|
52
|
-
};
|
|
53
|
-
return result;
|
|
35
|
+
return applyEditsToText(text, calcEdits(text, this.#trie));
|
|
54
36
|
}
|
|
55
37
|
}
|
|
56
38
|
function* calcEdits(text, subTrie) {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { MappedText } from '@cspell/cspell-types';
|
|
2
|
+
import type { Edit } from './Transformer.js';
|
|
3
|
+
export declare function applyEditsToMappedText(text: MappedText, edits: Iterable<Edit>): MappedText;
|
|
4
|
+
export declare function applyEditsToText(text: string, edits: Iterable<Edit>): MappedText;
|
|
5
|
+
//# sourceMappingURL=TextMapEdit.d.ts.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { mapOffsetPairsToSourceMap, mergeSourceMaps } from './SourceMap.js';
|
|
2
|
+
import { toMappedText } from './Transformer.js';
|
|
3
|
+
export function applyEditsToMappedText(text, edits) {
|
|
4
|
+
const transformed = applyEditsToText(text.text, edits);
|
|
5
|
+
const rawText = text.rawText ?? text.text;
|
|
6
|
+
const result = {
|
|
7
|
+
...text,
|
|
8
|
+
text: transformed.text,
|
|
9
|
+
map: mergeSourceMaps(text.map, transformed.map),
|
|
10
|
+
rawText,
|
|
11
|
+
};
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
export function applyEditsToText(text, edits) {
|
|
15
|
+
const map = [0, 0];
|
|
16
|
+
let repText = '';
|
|
17
|
+
let lastEnd = 0;
|
|
18
|
+
for (const edit of edits) {
|
|
19
|
+
if (edit.range[0] > lastEnd) {
|
|
20
|
+
repText += text.slice(lastEnd, edit.range[0]);
|
|
21
|
+
map.push(edit.range[0], repText.length);
|
|
22
|
+
}
|
|
23
|
+
repText += edit.text;
|
|
24
|
+
map.push(edit.range[1], repText.length);
|
|
25
|
+
lastEnd = edit.range[1];
|
|
26
|
+
}
|
|
27
|
+
if (lastEnd === 0) {
|
|
28
|
+
return toMappedText(text);
|
|
29
|
+
}
|
|
30
|
+
if (lastEnd < text.length) {
|
|
31
|
+
repText += text.slice(lastEnd);
|
|
32
|
+
map.push(text.length, repText.length);
|
|
33
|
+
}
|
|
34
|
+
const result = {
|
|
35
|
+
text: repText,
|
|
36
|
+
range: [0, text.length],
|
|
37
|
+
map: mapOffsetPairsToSourceMap(map),
|
|
38
|
+
rawText: text,
|
|
39
|
+
};
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=TextMapEdit.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { MappedText } from '@cspell/cspell-types';
|
|
2
|
+
import type { Range } from '@cspell/cspell-types/Parser';
|
|
3
|
+
export interface TextTransformer {
|
|
4
|
+
transform(text: string | MappedText): MappedText;
|
|
5
|
+
transformAll(src: Iterable<string | MappedText>): Iterable<MappedText>;
|
|
6
|
+
}
|
|
7
|
+
export interface Edit {
|
|
8
|
+
/**
|
|
9
|
+
* The replacement text for the edit. This is the text that will replace the original text in the string.
|
|
10
|
+
*/
|
|
11
|
+
text: string;
|
|
12
|
+
/**
|
|
13
|
+
* The range of the text to be replaced. This is a tuple of the form `[start, end]`,
|
|
14
|
+
* where start is the index of the first character to be replaced,
|
|
15
|
+
* and end is the index of the first character after the last character to be replaced.
|
|
16
|
+
*/
|
|
17
|
+
range: Range;
|
|
18
|
+
}
|
|
19
|
+
export declare function toMappedText(text: string | MappedText): MappedText;
|
|
20
|
+
export declare function chainTransformers(...transformers: TextTransformer[]): TextTransformer;
|
|
21
|
+
export declare class IdentityTextTransformer implements TextTransformer {
|
|
22
|
+
transform(text: string | MappedText): MappedText;
|
|
23
|
+
transformAll(src: Iterable<string | MappedText>): Iterable<MappedText>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=Transformer.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export function toMappedText(text) {
|
|
2
|
+
if (typeof text === 'string') {
|
|
3
|
+
return { text, range: [0, text.length], rawText: text };
|
|
4
|
+
}
|
|
5
|
+
return text;
|
|
6
|
+
}
|
|
7
|
+
export function chainTransformers(...transformers) {
|
|
8
|
+
return {
|
|
9
|
+
transform(text) {
|
|
10
|
+
return transformers.reduce((acc, transformer) => transformer.transform(acc), toMappedText(text));
|
|
11
|
+
},
|
|
12
|
+
transformAll(src) {
|
|
13
|
+
return Array.from(src, (text) => transformers.reduce((acc, transformer) => transformer.transform(acc), toMappedText(text)));
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export class IdentityTextTransformer {
|
|
18
|
+
transform(text) {
|
|
19
|
+
return toMappedText(text);
|
|
20
|
+
}
|
|
21
|
+
*transformAll(src) {
|
|
22
|
+
for (const item of src) {
|
|
23
|
+
yield this.transform(item);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=Transformer.js.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { createIntlSegmentTextTransformer } from './IntlSegmentTextTransformer.js';
|
|
1
2
|
export { createMappedTextSegmenter, mapRangeBackToOriginalPos } from './parsedText.js';
|
|
2
3
|
export type { SourceMapCursor } from './SourceMap.js';
|
|
3
4
|
export { createSourceMapCursor } from './SourceMap.js';
|
|
@@ -5,5 +6,7 @@ export type { SubstitutionInfo } from './SubstitutionTransformer.js';
|
|
|
5
6
|
export { createSubstitutionTransformer, SubstitutionTransformer } from './SubstitutionTransformer.js';
|
|
6
7
|
export type { MatchRange } from './TextRange.js';
|
|
7
8
|
export { excludeRanges, extractRangeText, findMatchingRanges, findMatchingRangesForPatterns } from './TextRange.js';
|
|
9
|
+
export type { TextTransformer } from './Transformer.js';
|
|
10
|
+
export { chainTransformers } from './Transformer.js';
|
|
8
11
|
export type { Offset, SimpleRange } from './types.js';
|
|
9
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
export { createIntlSegmentTextTransformer } from './IntlSegmentTextTransformer.js';
|
|
1
2
|
export { createMappedTextSegmenter, mapRangeBackToOriginalPos } from './parsedText.js';
|
|
2
3
|
export { createSourceMapCursor } from './SourceMap.js';
|
|
3
4
|
export { createSubstitutionTransformer, SubstitutionTransformer } from './SubstitutionTransformer.js';
|
|
4
5
|
export { excludeRanges, extractRangeText, findMatchingRanges, findMatchingRangesForPatterns } from './TextRange.js';
|
|
6
|
+
export { chainTransformers } from './Transformer.js';
|
|
5
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -6,7 +6,7 @@ import type { ValidationIssue } from '../Models/ValidationIssue.js';
|
|
|
6
6
|
import type { CSpellSettingsInternal, CSpellSettingsInternalFinalized, ImportFileRefWithError } from '../Settings/index.js';
|
|
7
7
|
import type { SpellingDictionaryCollection } from '../SpellingDictionary/index.js';
|
|
8
8
|
import type { WordSuggestion } from '../suggestions.js';
|
|
9
|
-
import type { MatchRange, SimpleRange,
|
|
9
|
+
import type { MatchRange, SimpleRange, TextTransformer } from '../Transform/index.js';
|
|
10
10
|
import type { TextValidationFactoryOptions, TextValidator } from './lineValidatorFactory.js';
|
|
11
11
|
import type { TraceResult } from './traceWord.js';
|
|
12
12
|
import type { ValidateTextOptions } from './ValidateTextOptions.js';
|
|
@@ -37,6 +37,7 @@ export interface DocumentValidatorOptions extends ValidateTextOptions {
|
|
|
37
37
|
}
|
|
38
38
|
type PerfTimings = Record<string, number>;
|
|
39
39
|
export declare class DocumentValidator {
|
|
40
|
+
#private;
|
|
40
41
|
readonly settings: CSpellUserSettings;
|
|
41
42
|
private _document;
|
|
42
43
|
private _ready;
|
|
@@ -133,7 +134,7 @@ interface Preparations {
|
|
|
133
134
|
validateOptions: TextValidationFactoryOptions;
|
|
134
135
|
localConfig: CSpellUserSettings | undefined;
|
|
135
136
|
localConfigFilepath: string | undefined;
|
|
136
|
-
|
|
137
|
+
transformer: TextTransformer;
|
|
137
138
|
}
|
|
138
139
|
interface ShouldCheckDocumentResult {
|
|
139
140
|
/** possible errors found while loading configuration. */
|
|
@@ -10,7 +10,7 @@ import { extractImportErrors, finalizeSettings, loadConfig, mergeSettings, resol
|
|
|
10
10
|
import { validateInDocumentSettings } from '../Settings/InDocSettings.js';
|
|
11
11
|
import { getDictionaryInternal } from '../SpellingDictionary/index.js';
|
|
12
12
|
import { calcSuggestionAdjustedToToMatchCase } from '../suggestions.js';
|
|
13
|
-
import { createMappedTextSegmenter, createSubstitutionTransformer } from '../Transform/index.js';
|
|
13
|
+
import { chainTransformers, createIntlSegmentTextTransformer, createMappedTextSegmenter, createSubstitutionTransformer, } from '../Transform/index.js';
|
|
14
14
|
import { catchPromiseError, toError } from '../util/errors.js';
|
|
15
15
|
import { AutoCache } from '../util/simpleCache.js';
|
|
16
16
|
import { uriToFilePath } from '../util/Uri.js';
|
|
@@ -101,15 +101,7 @@ export class DocumentValidator {
|
|
|
101
101
|
recShouldCheckTime();
|
|
102
102
|
const recFinalizeTime = recordPerfTime(this.perfTiming, '_finalizeSettings');
|
|
103
103
|
const finalSettings = finalizeSettings(docSettings);
|
|
104
|
-
const
|
|
105
|
-
if (sub.missing) {
|
|
106
|
-
this.addPossibleError(`Missing substitutions: ${sub.missing.join(', ')}`);
|
|
107
|
-
}
|
|
108
|
-
const validateOptions = { ...settingsToValidateOptions(finalSettings), transformer: sub.transformer };
|
|
109
|
-
const rangeTransformer = finalSettings.substitutions?.length ? sub.transformer : undefined;
|
|
110
|
-
const includeRanges = calcTextInclusionRanges(this._document.text, validateOptions, rangeTransformer);
|
|
111
|
-
const segmenter = createMappedTextSegmenter(includeRanges);
|
|
112
|
-
const textValidator = textValidatorFactory(dict, validateOptions);
|
|
104
|
+
const { transformer, validateOptions, includeRanges, segmenter, textValidator } = this.#calcSharedPrep(finalSettings, dict);
|
|
113
105
|
recFinalizeTime();
|
|
114
106
|
this._preparations = {
|
|
115
107
|
config,
|
|
@@ -123,7 +115,7 @@ export class DocumentValidator {
|
|
|
123
115
|
textValidator,
|
|
124
116
|
localConfig,
|
|
125
117
|
localConfigFilepath: localConfig?.__importRef?.filename,
|
|
126
|
-
|
|
118
|
+
transformer,
|
|
127
119
|
};
|
|
128
120
|
this._ready = true;
|
|
129
121
|
this._preparationTime = timer.elapsed;
|
|
@@ -139,28 +131,38 @@ export class DocumentValidator {
|
|
|
139
131
|
const stopMeasure = measurePerf('DocumentValidator._updatePrep');
|
|
140
132
|
const shouldCheck = docSettings.enabled ?? true;
|
|
141
133
|
const finalSettings = finalizeSettings(docSettings);
|
|
142
|
-
const
|
|
143
|
-
if (sub.missing) {
|
|
144
|
-
this.addPossibleError(`Missing substitutions: ${sub.missing.join(', ')}`);
|
|
145
|
-
}
|
|
146
|
-
const validateOptions = { ...settingsToValidateOptions(finalSettings), transformer: sub.transformer };
|
|
147
|
-
const rangeTransformer = finalSettings.substitutions?.length ? sub.transformer : undefined;
|
|
148
|
-
const includeRanges = calcTextInclusionRanges(this._document.text, validateOptions, rangeTransformer);
|
|
149
|
-
const segmenter = createMappedTextSegmenter(includeRanges);
|
|
150
|
-
const textValidator = textValidatorFactory(dict, validateOptions);
|
|
134
|
+
const { transformer, validateOptions, includeRanges, segmenter, textValidator } = this.#calcSharedPrep(finalSettings, dict);
|
|
151
135
|
this._preparations = {
|
|
152
136
|
...prep,
|
|
153
137
|
dictionary: dict,
|
|
154
138
|
docSettings,
|
|
139
|
+
finalSettings,
|
|
155
140
|
shouldCheck,
|
|
156
141
|
validateOptions,
|
|
157
142
|
includeRanges,
|
|
158
143
|
segmenter,
|
|
159
144
|
textValidator,
|
|
145
|
+
transformer,
|
|
160
146
|
};
|
|
161
147
|
this._preparationTime = timer.elapsed;
|
|
162
148
|
stopMeasure();
|
|
163
149
|
}
|
|
150
|
+
#calcSharedPrep(finalSettings, dict) {
|
|
151
|
+
const sub = createSubstitutionTransformer(finalSettings);
|
|
152
|
+
if (sub.missing) {
|
|
153
|
+
this.addPossibleError(`Missing substitutions: ${sub.missing.join(', ')}`);
|
|
154
|
+
}
|
|
155
|
+
const transformer = finalSettings.useIntlWordSegmentation
|
|
156
|
+
? chainTransformers(sub.transformer, createIntlSegmentTextTransformer(finalSettings.language || ''))
|
|
157
|
+
: sub.transformer;
|
|
158
|
+
const validateOptions = { ...settingsToValidateOptions(finalSettings), transformer };
|
|
159
|
+
// Avoid excluding text ranges that have a full substitution applied.
|
|
160
|
+
const rangeTransformer = finalSettings.substitutions?.length ? sub.transformer : undefined;
|
|
161
|
+
const includeRanges = calcTextInclusionRanges(this._document.text, validateOptions, rangeTransformer);
|
|
162
|
+
const segmenter = createMappedTextSegmenter(includeRanges);
|
|
163
|
+
const textValidator = textValidatorFactory(dict, validateOptions);
|
|
164
|
+
return { segmenter, textValidator, includeRanges, validateOptions, transformer };
|
|
165
|
+
}
|
|
164
166
|
/**
|
|
165
167
|
* The amount of time in ms to prepare for validation.
|
|
166
168
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CachingDictionary, SpellingDictionary } from 'cspell-dictionary';
|
|
2
|
-
import type {
|
|
2
|
+
import type { TextTransformer } from '../Transform/index.js';
|
|
3
3
|
import type { LineValidatorFn, TextValidatorFn, ValidationOptions } from './ValidationTypes.js';
|
|
4
4
|
interface LineValidator {
|
|
5
5
|
fn: LineValidatorFn;
|
|
@@ -11,7 +11,7 @@ export interface TextValidator {
|
|
|
11
11
|
lineValidator: LineValidator;
|
|
12
12
|
}
|
|
13
13
|
export interface TextValidationFactoryOptions extends ValidationOptions {
|
|
14
|
-
transformer:
|
|
14
|
+
transformer: TextTransformer | undefined;
|
|
15
15
|
}
|
|
16
16
|
export declare function textValidatorFactory(dict: SpellingDictionary, options: TextValidationFactoryOptions): TextValidator;
|
|
17
17
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SpellingDictionary } from 'cspell-dictionary';
|
|
2
2
|
import type { ValidationResult } from '../Models/ValidationResult.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { TextTransformer } from '../Transform/index.js';
|
|
4
4
|
import * as TextRange from '../Transform/index.js';
|
|
5
5
|
import type { IncludeExcludeOptions, LineSegment, ValidationOptions } from './ValidationTypes.js';
|
|
6
6
|
/**
|
|
@@ -8,7 +8,7 @@ import type { IncludeExcludeOptions, LineSegment, ValidationOptions } from './Va
|
|
|
8
8
|
* @deprecation Use spellCheckDocument
|
|
9
9
|
*/
|
|
10
10
|
export declare function validateText(text: string, dict: SpellingDictionary, options: ValidationOptions): Iterable<ValidationResult>;
|
|
11
|
-
export declare function calcTextInclusionRanges(text: string, options: IncludeExcludeOptions, transformer?:
|
|
11
|
+
export declare function calcTextInclusionRanges(text: string, options: IncludeExcludeOptions, transformer?: TextTransformer): TextRange.MatchRange[];
|
|
12
12
|
/**
|
|
13
13
|
* Returns a mapper function that will segment a TextOffset based upon the includeRanges.
|
|
14
14
|
* This function is optimized for forward scanning. It will perform poorly for randomly ordered offsets.
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public",
|
|
5
5
|
"provenance": true
|
|
6
6
|
},
|
|
7
|
-
"version": "10.2.0
|
|
7
|
+
"version": "10.2.0",
|
|
8
8
|
"description": "A library of useful functions used across various cspell tools.",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"sideEffects": false,
|
|
@@ -75,22 +75,22 @@
|
|
|
75
75
|
},
|
|
76
76
|
"homepage": "https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell-lib#readme",
|
|
77
77
|
"dependencies": {
|
|
78
|
-
"@cspell/cspell-bundled-dicts": "10.2.0
|
|
79
|
-
"@cspell/cspell-performance-monitor": "10.2.0
|
|
80
|
-
"@cspell/cspell-pipe": "10.2.0
|
|
81
|
-
"@cspell/cspell-resolver": "10.2.0
|
|
82
|
-
"@cspell/cspell-types": "10.2.0
|
|
83
|
-
"@cspell/dynamic-import": "10.2.0
|
|
84
|
-
"@cspell/filetypes": "10.2.0
|
|
85
|
-
"@cspell/rpc": "10.2.0
|
|
86
|
-
"@cspell/strong-weak-map": "10.2.0
|
|
87
|
-
"@cspell/url": "10.2.0
|
|
88
|
-
"cspell-config-lib": "10.2.0
|
|
89
|
-
"cspell-dictionary": "10.2.0
|
|
90
|
-
"cspell-glob": "10.2.0
|
|
91
|
-
"cspell-grammar": "10.2.0
|
|
92
|
-
"cspell-io": "10.2.0
|
|
93
|
-
"cspell-trie-lib": "10.2.0
|
|
78
|
+
"@cspell/cspell-bundled-dicts": "10.2.0",
|
|
79
|
+
"@cspell/cspell-performance-monitor": "10.2.0",
|
|
80
|
+
"@cspell/cspell-pipe": "10.2.0",
|
|
81
|
+
"@cspell/cspell-resolver": "10.2.0",
|
|
82
|
+
"@cspell/cspell-types": "10.2.0",
|
|
83
|
+
"@cspell/dynamic-import": "10.2.0",
|
|
84
|
+
"@cspell/filetypes": "10.2.0",
|
|
85
|
+
"@cspell/rpc": "10.2.0",
|
|
86
|
+
"@cspell/strong-weak-map": "10.2.0",
|
|
87
|
+
"@cspell/url": "10.2.0",
|
|
88
|
+
"cspell-config-lib": "10.2.0",
|
|
89
|
+
"cspell-dictionary": "10.2.0",
|
|
90
|
+
"cspell-glob": "10.2.0",
|
|
91
|
+
"cspell-grammar": "10.2.0",
|
|
92
|
+
"cspell-io": "10.2.0",
|
|
93
|
+
"cspell-trie-lib": "10.2.0",
|
|
94
94
|
"env-paths": "^4.0.0",
|
|
95
95
|
"gensequence": "^8.0.8",
|
|
96
96
|
"import-fresh": "^4.0.0",
|
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
"node": ">=22.18.0"
|
|
104
104
|
},
|
|
105
105
|
"devDependencies": {
|
|
106
|
-
"@cspell/cspell-tools": "10.2.0
|
|
106
|
+
"@cspell/cspell-tools": "10.2.0",
|
|
107
107
|
"@cspell/dict-cpp": "^7.1.0",
|
|
108
108
|
"@cspell/dict-csharp": "^4.0.8",
|
|
109
109
|
"@cspell/dict-css": "^4.1.2",
|
|
@@ -122,5 +122,5 @@
|
|
|
122
122
|
"lorem-ipsum": "^3.0.0",
|
|
123
123
|
"perf-insight": "^2.0.1"
|
|
124
124
|
},
|
|
125
|
-
"gitHead": "
|
|
125
|
+
"gitHead": "2d310afc22fa500b1be07e3c2e2d3897ec00daad"
|
|
126
126
|
}
|