cspell-lib 10.0.0 → 10.1.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/Transform/SubstitutionTransformer.js +5 -2
- package/dist/lib/textValidation/checkText.js +3 -2
- package/dist/lib/textValidation/docValidator.js +4 -2
- package/dist/lib/textValidation/lineValidatorFactory.js +9 -1
- package/dist/lib/textValidation/textValidator.d.ts +2 -1
- package/dist/lib/textValidation/textValidator.js +11 -2
- package/package.json +26 -26
|
@@ -12,16 +12,18 @@ export class SubstitutionTransformer {
|
|
|
12
12
|
if (!this.#trie)
|
|
13
13
|
return text;
|
|
14
14
|
const transformed = this.transformString(text.text);
|
|
15
|
+
const rawText = text.rawText ?? text.text;
|
|
15
16
|
const result = {
|
|
16
17
|
...text,
|
|
17
18
|
text: transformed.text,
|
|
18
19
|
map: mergeSourceMaps(text.map, transformed.map),
|
|
20
|
+
rawText,
|
|
19
21
|
};
|
|
20
22
|
return result;
|
|
21
23
|
}
|
|
22
24
|
transformString(text) {
|
|
23
25
|
if (!this.#trie) {
|
|
24
|
-
return { text, range: [0, text.length] };
|
|
26
|
+
return { text, range: [0, text.length], rawText: text };
|
|
25
27
|
}
|
|
26
28
|
const map = [0, 0];
|
|
27
29
|
let repText = '';
|
|
@@ -36,7 +38,7 @@ export class SubstitutionTransformer {
|
|
|
36
38
|
lastEnd = edit.range[1];
|
|
37
39
|
}
|
|
38
40
|
if (lastEnd === 0) {
|
|
39
|
-
return { text, range: [0, text.length] };
|
|
41
|
+
return { text, range: [0, text.length], rawText: text };
|
|
40
42
|
}
|
|
41
43
|
if (lastEnd < text.length) {
|
|
42
44
|
repText += text.slice(lastEnd);
|
|
@@ -46,6 +48,7 @@ export class SubstitutionTransformer {
|
|
|
46
48
|
text: repText,
|
|
47
49
|
range: [0, text.length],
|
|
48
50
|
map: mapOffsetPairsToSourceMap(map),
|
|
51
|
+
rawText: text,
|
|
49
52
|
};
|
|
50
53
|
return result;
|
|
51
54
|
}
|
|
@@ -95,14 +95,15 @@ function genResult(text, issues, includeRanges) {
|
|
|
95
95
|
const issue = issues[i];
|
|
96
96
|
const endPos = issue.offset;
|
|
97
97
|
const text = span.text.slice(0, endPos - span.startPos);
|
|
98
|
-
const endPosError = issue.offset + issue.text.length;
|
|
98
|
+
const endPosError = issue.offset + (issue.length ?? issue.text.length);
|
|
99
|
+
const issueText = span.text.slice(endPos - span.startPos, endPosError - span.startPos);
|
|
99
100
|
yield { ...span, text, endPos };
|
|
100
101
|
yield {
|
|
101
102
|
...span,
|
|
102
103
|
isError: true,
|
|
103
104
|
startPos: issue.offset,
|
|
104
105
|
endPos: endPosError,
|
|
105
|
-
text:
|
|
106
|
+
text: issueText,
|
|
106
107
|
};
|
|
107
108
|
span.text = span.text.slice(endPosError - span.startPos);
|
|
108
109
|
span.startPos = endPosError;
|
|
@@ -106,7 +106,8 @@ export class DocumentValidator {
|
|
|
106
106
|
this.addPossibleError(`Missing substitutions: ${sub.missing.join(', ')}`);
|
|
107
107
|
}
|
|
108
108
|
const validateOptions = { ...settingsToValidateOptions(finalSettings), transformer: sub.transformer };
|
|
109
|
-
const
|
|
109
|
+
const rangeTransformer = finalSettings.substitutions?.length ? sub.transformer : undefined;
|
|
110
|
+
const includeRanges = calcTextInclusionRanges(this._document.text, validateOptions, rangeTransformer);
|
|
110
111
|
const segmenter = createMappedTextSegmenter(includeRanges);
|
|
111
112
|
const textValidator = textValidatorFactory(dict, validateOptions);
|
|
112
113
|
recFinalizeTime();
|
|
@@ -143,7 +144,8 @@ export class DocumentValidator {
|
|
|
143
144
|
this.addPossibleError(`Missing substitutions: ${sub.missing.join(', ')}`);
|
|
144
145
|
}
|
|
145
146
|
const validateOptions = { ...settingsToValidateOptions(finalSettings), transformer: sub.transformer };
|
|
146
|
-
const
|
|
147
|
+
const rangeTransformer = finalSettings.substitutions?.length ? sub.transformer : undefined;
|
|
148
|
+
const includeRanges = calcTextInclusionRanges(this._document.text, validateOptions, rangeTransformer);
|
|
147
149
|
const segmenter = createMappedTextSegmenter(includeRanges);
|
|
148
150
|
const textValidator = textValidatorFactory(dict, validateOptions);
|
|
149
151
|
this._preparations = {
|
|
@@ -366,7 +366,15 @@ export function textValidatorFactory(dict, options) {
|
|
|
366
366
|
const { text, offset, isFlagged, isFound, suggestionsEx, hasPreferredSuggestions, hasSimpleSuggestions } = vr;
|
|
367
367
|
const r = mapRangeBackToOriginalPos([offset, offset + text.length], map);
|
|
368
368
|
const range = [r[0] + srcOffset, r[1] + srcOffset];
|
|
369
|
-
return {
|
|
369
|
+
return {
|
|
370
|
+
text,
|
|
371
|
+
range,
|
|
372
|
+
isFlagged,
|
|
373
|
+
isFound,
|
|
374
|
+
suggestionsEx,
|
|
375
|
+
hasPreferredSuggestions,
|
|
376
|
+
hasSimpleSuggestions,
|
|
377
|
+
};
|
|
370
378
|
}
|
|
371
379
|
return [...lineValidatorFn(lineSegment)].map(mapBackToOriginSimple);
|
|
372
380
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { SpellingDictionary } from 'cspell-dictionary';
|
|
2
2
|
import type { ValidationResult } from '../Models/ValidationResult.js';
|
|
3
|
+
import type { SubstitutionTransformer } from '../Transform/index.js';
|
|
3
4
|
import * as TextRange from '../Transform/index.js';
|
|
4
5
|
import type { IncludeExcludeOptions, LineSegment, ValidationOptions } from './ValidationTypes.js';
|
|
5
6
|
/**
|
|
@@ -7,7 +8,7 @@ import type { IncludeExcludeOptions, LineSegment, ValidationOptions } from './Va
|
|
|
7
8
|
* @deprecation Use spellCheckDocument
|
|
8
9
|
*/
|
|
9
10
|
export declare function validateText(text: string, dict: SpellingDictionary, options: ValidationOptions): Iterable<ValidationResult>;
|
|
10
|
-
export declare function calcTextInclusionRanges(text: string, options: IncludeExcludeOptions): TextRange.MatchRange[];
|
|
11
|
+
export declare function calcTextInclusionRanges(text: string, options: IncludeExcludeOptions, transformer?: SubstitutionTransformer): TextRange.MatchRange[];
|
|
11
12
|
/**
|
|
12
13
|
* Returns a mapper function that will segment a TextOffset based upon the includeRanges.
|
|
13
14
|
* This function is optimized for forward scanning. It will perform poorly for randomly ordered offsets.
|
|
@@ -23,13 +23,22 @@ export function validateText(text, dict, options) {
|
|
|
23
23
|
}), opTake(maxNumberOfProblems));
|
|
24
24
|
return iter;
|
|
25
25
|
}
|
|
26
|
-
export function calcTextInclusionRanges(text, options) {
|
|
26
|
+
export function calcTextInclusionRanges(text, options, transformer) {
|
|
27
27
|
const { ignoreRegExpList = [], includeRegExpList = [] } = options;
|
|
28
28
|
const filteredIncludeList = includeRegExpList.filter((a) => !!a);
|
|
29
29
|
const finalIncludeList = filteredIncludeList.length ? filteredIncludeList : [/.*/gim];
|
|
30
|
-
const
|
|
30
|
+
const excludeRanges = TextRange.findMatchingRangesForPatterns(ignoreRegExpList, text).filter((range) => !isFullySubstitutedRange(text, range, transformer));
|
|
31
|
+
const includeRanges = TextRange.excludeRanges(TextRange.findMatchingRangesForPatterns(finalIncludeList, text), excludeRanges);
|
|
31
32
|
return includeRanges;
|
|
32
33
|
}
|
|
34
|
+
function isFullySubstitutedRange(text, range, transformer) {
|
|
35
|
+
if (!transformer)
|
|
36
|
+
return false;
|
|
37
|
+
const source = text.slice(range.startPos, range.endPos);
|
|
38
|
+
const transformed = transformer.transform(source);
|
|
39
|
+
// One source-map segment means a single substitution consumed the entire ignored range.
|
|
40
|
+
return transformed.text !== source && transformed.map?.length === 2 && transformed.map[0] === source.length;
|
|
41
|
+
}
|
|
33
42
|
function mapLineToLineSegments(includeRanges) {
|
|
34
43
|
const mapAgainstRanges = mapLineSegmentAgainstRangesFactory(includeRanges);
|
|
35
44
|
return (line) => {
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public",
|
|
5
5
|
"provenance": true
|
|
6
6
|
},
|
|
7
|
-
"version": "10.
|
|
7
|
+
"version": "10.1.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.
|
|
79
|
-
"@cspell/cspell-performance-monitor": "10.
|
|
80
|
-
"@cspell/cspell-pipe": "10.
|
|
81
|
-
"@cspell/cspell-resolver": "10.
|
|
82
|
-
"@cspell/cspell-types": "10.
|
|
83
|
-
"@cspell/dynamic-import": "10.
|
|
84
|
-
"@cspell/filetypes": "10.
|
|
85
|
-
"@cspell/rpc": "10.
|
|
86
|
-
"@cspell/strong-weak-map": "10.
|
|
87
|
-
"@cspell/url": "10.
|
|
88
|
-
"cspell-config-lib": "10.
|
|
89
|
-
"cspell-dictionary": "10.
|
|
90
|
-
"cspell-glob": "10.
|
|
91
|
-
"cspell-grammar": "10.
|
|
92
|
-
"cspell-io": "10.
|
|
93
|
-
"cspell-trie-lib": "10.
|
|
78
|
+
"@cspell/cspell-bundled-dicts": "10.1.0",
|
|
79
|
+
"@cspell/cspell-performance-monitor": "10.1.0",
|
|
80
|
+
"@cspell/cspell-pipe": "10.1.0",
|
|
81
|
+
"@cspell/cspell-resolver": "10.1.0",
|
|
82
|
+
"@cspell/cspell-types": "10.1.0",
|
|
83
|
+
"@cspell/dynamic-import": "10.1.0",
|
|
84
|
+
"@cspell/filetypes": "10.1.0",
|
|
85
|
+
"@cspell/rpc": "10.1.0",
|
|
86
|
+
"@cspell/strong-weak-map": "10.1.0",
|
|
87
|
+
"@cspell/url": "10.1.0",
|
|
88
|
+
"cspell-config-lib": "10.1.0",
|
|
89
|
+
"cspell-dictionary": "10.1.0",
|
|
90
|
+
"cspell-glob": "10.1.0",
|
|
91
|
+
"cspell-grammar": "10.1.0",
|
|
92
|
+
"cspell-io": "10.1.0",
|
|
93
|
+
"cspell-trie-lib": "10.1.0",
|
|
94
94
|
"env-paths": "^4.0.0",
|
|
95
95
|
"gensequence": "^8.0.8",
|
|
96
96
|
"import-fresh": "^4.0.0",
|
|
@@ -103,24 +103,24 @@
|
|
|
103
103
|
"node": ">=22.18.0"
|
|
104
104
|
},
|
|
105
105
|
"devDependencies": {
|
|
106
|
-
"@cspell/cspell-tools": "10.
|
|
107
|
-
"@cspell/dict-cpp": "^7.0
|
|
106
|
+
"@cspell/cspell-tools": "10.1.0",
|
|
107
|
+
"@cspell/dict-cpp": "^7.1.0",
|
|
108
108
|
"@cspell/dict-csharp": "^4.0.8",
|
|
109
|
-
"@cspell/dict-css": "^4.1.
|
|
110
|
-
"@cspell/dict-en_us": "^4.4.
|
|
109
|
+
"@cspell/dict-css": "^4.1.2",
|
|
110
|
+
"@cspell/dict-en_us": "^4.4.36",
|
|
111
111
|
"@cspell/dict-fa-ir": "^4.0.5",
|
|
112
112
|
"@cspell/dict-fr-fr": "^2.3.2",
|
|
113
|
-
"@cspell/dict-html": "^4.0.
|
|
113
|
+
"@cspell/dict-html": "^4.0.16",
|
|
114
114
|
"@cspell/dict-nl-nl": "^2.4.2",
|
|
115
|
-
"@cspell/dict-python": "^4.
|
|
115
|
+
"@cspell/dict-python": "^4.4.0",
|
|
116
116
|
"@cspell/dictionary-bundler-plugin": "",
|
|
117
117
|
"@types/configstore": "^6.0.2",
|
|
118
|
-
"comment-json": "^
|
|
118
|
+
"comment-json": "^5.0.0",
|
|
119
119
|
"configstore": "^8.0.0",
|
|
120
120
|
"cspell-dict-nl-nl": "^1.1.2",
|
|
121
121
|
"leaked-handles": "^5.2.0",
|
|
122
|
-
"lorem-ipsum": "^
|
|
122
|
+
"lorem-ipsum": "^3.0.0",
|
|
123
123
|
"perf-insight": "^2.0.1"
|
|
124
124
|
},
|
|
125
|
-
"gitHead": "
|
|
125
|
+
"gitHead": "401518c5e37c06fb406aedadb3fc7a1c27eca8e6"
|
|
126
126
|
}
|