cspell-lib 6.1.3-alpha.0 → 6.1.3-alpha.1
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.
|
@@ -22,8 +22,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
25
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
29
|
exports.__testing__ = exports.extractDependencies = exports.getSources = exports.checkFilenameMatchesGlob = exports.toInternalSettings = exports.finalizeSettings = exports.calcOverrideSettings = exports.mergeInDocSettings = exports.mergeSettings = exports.ENV_CSPELL_GLOB_ROOT = exports.currentSettingsFileVersion = exports.configSettingsFileVersion0_2 = exports.configSettingsFileVersion0_1 = void 0;
|
|
30
|
+
const assert_1 = __importDefault(require("assert"));
|
|
27
31
|
const cspell_glob_1 = require("cspell-glob");
|
|
28
32
|
const path = __importStar(require("path"));
|
|
29
33
|
const CSpellSettingsInternalDef_1 = require("../Models/CSpellSettingsInternalDef");
|
|
@@ -224,6 +228,7 @@ function _finalizeSettings(settings) {
|
|
|
224
228
|
finalized: true,
|
|
225
229
|
ignoreRegExpList: (0, patterns_1.resolvePatterns)(settings.ignoreRegExpList, settings.patterns),
|
|
226
230
|
includeRegExpList: (0, patterns_1.resolvePatterns)(settings.includeRegExpList, settings.patterns),
|
|
231
|
+
parser: resolveParser(settings),
|
|
227
232
|
};
|
|
228
233
|
finalized.name = 'Finalized ' + (finalized.name || '');
|
|
229
234
|
finalized.source = { name: settings.name || 'src', sources: [settings] };
|
|
@@ -320,6 +325,39 @@ function resolveCwd() {
|
|
|
320
325
|
const cwd = envGlobRoot || process.cwd();
|
|
321
326
|
return cwd;
|
|
322
327
|
}
|
|
328
|
+
function resolveParser(settings) {
|
|
329
|
+
if (!settings.parser)
|
|
330
|
+
return undefined;
|
|
331
|
+
if (typeof settings.parser === 'function')
|
|
332
|
+
return settings.parser;
|
|
333
|
+
const parserName = settings.parser;
|
|
334
|
+
(0, assert_1.default)(typeof parserName === 'string');
|
|
335
|
+
const parsers = extractParsers(settings.plugins);
|
|
336
|
+
const parser = parsers.get(parserName);
|
|
337
|
+
(0, assert_1.default)(parser, `Parser "${parserName}" not found.`);
|
|
338
|
+
return parser;
|
|
339
|
+
}
|
|
340
|
+
const parserCache = new WeakMap();
|
|
341
|
+
const emptyParserMap = new Map();
|
|
342
|
+
function extractParsers(plugins) {
|
|
343
|
+
if (!plugins || !plugins.length)
|
|
344
|
+
return emptyParserMap;
|
|
345
|
+
const found = parserCache.get(plugins);
|
|
346
|
+
if (found)
|
|
347
|
+
return found;
|
|
348
|
+
function* parsers(plugins) {
|
|
349
|
+
for (const plugin of plugins) {
|
|
350
|
+
if (!plugin.parsers)
|
|
351
|
+
continue;
|
|
352
|
+
for (const parser of plugin.parsers) {
|
|
353
|
+
yield [parser.name, parser];
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
const map = new Map(parsers(plugins));
|
|
358
|
+
parserCache.set(plugins, map);
|
|
359
|
+
return map;
|
|
360
|
+
}
|
|
323
361
|
exports.__testing__ = {
|
|
324
362
|
mergeObjects,
|
|
325
363
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { CSpellUserSettings } from '@cspell/cspell-types';
|
|
2
|
-
import { CSpellSettingsInternal } from '../Models/CSpellSettingsInternalDef';
|
|
1
|
+
import type { CSpellUserSettings, ParsedText } from '@cspell/cspell-types';
|
|
2
|
+
import { CSpellSettingsInternal, CSpellSettingsInternalFinalized } from '../Models/CSpellSettingsInternalDef';
|
|
3
3
|
import { TextDocument } from '../Models/TextDocument';
|
|
4
4
|
import { SpellingDictionaryCollection } from '../SpellingDictionary';
|
|
5
5
|
import { MatchRange } from '../util/TextRange';
|
|
6
|
-
import {
|
|
6
|
+
import { SimpleRange } from './parsedText';
|
|
7
7
|
import { LineValidator, ValidationOptions, type LineSegment } from './textValidator';
|
|
8
8
|
import { ValidateTextOptions, ValidationIssue } from './validator';
|
|
9
9
|
export interface DocumentValidatorOptions extends ValidateTextOptions {
|
|
@@ -51,10 +51,12 @@ export declare class DocumentValidator {
|
|
|
51
51
|
checkDocument(forceCheck?: boolean): ValidationIssue[];
|
|
52
52
|
get document(): TextDocument;
|
|
53
53
|
updateDocumentText(text: string): void;
|
|
54
|
-
private
|
|
54
|
+
private defaultParser;
|
|
55
|
+
private _checkParsedText;
|
|
55
56
|
private addPossibleError;
|
|
56
57
|
private catchError;
|
|
57
58
|
private errorCatcherWrapper;
|
|
59
|
+
private _parse;
|
|
58
60
|
private suggest;
|
|
59
61
|
private genSuggestions;
|
|
60
62
|
getFinalizedDocSettings(): CSpellSettingsInternal;
|
|
@@ -77,6 +79,7 @@ interface Preparations {
|
|
|
77
79
|
dictionary: SpellingDictionaryCollection;
|
|
78
80
|
/** configuration after applying in-doc settings */
|
|
79
81
|
docSettings: CSpellSettingsInternal;
|
|
82
|
+
finalSettings: CSpellSettingsInternalFinalized;
|
|
80
83
|
includeRanges: MatchRange[];
|
|
81
84
|
lineValidator: LineValidator;
|
|
82
85
|
segmenter: (lineSegment: LineSegment) => LineSegment[];
|
|
@@ -70,6 +70,7 @@ class DocumentValidator {
|
|
|
70
70
|
config,
|
|
71
71
|
dictionary: dict,
|
|
72
72
|
docSettings,
|
|
73
|
+
finalSettings,
|
|
73
74
|
shouldCheck,
|
|
74
75
|
validateOptions,
|
|
75
76
|
includeRanges,
|
|
@@ -117,6 +118,7 @@ class DocumentValidator {
|
|
|
117
118
|
config,
|
|
118
119
|
dictionary: dict,
|
|
119
120
|
docSettings,
|
|
121
|
+
finalSettings,
|
|
120
122
|
shouldCheck,
|
|
121
123
|
validateOptions,
|
|
122
124
|
includeRanges,
|
|
@@ -160,7 +162,7 @@ class DocumentValidator {
|
|
|
160
162
|
}
|
|
161
163
|
checkText(range, _text, scope) {
|
|
162
164
|
const text = this._document.text.slice(range[0], range[1]);
|
|
163
|
-
return this.check({ text, range, scope });
|
|
165
|
+
return this.check({ text, range, scope: scope.join(' ') });
|
|
164
166
|
}
|
|
165
167
|
check(parsedText) {
|
|
166
168
|
(0, assert_1.default)(this._ready);
|
|
@@ -195,7 +197,7 @@ class DocumentValidator {
|
|
|
195
197
|
checkDocument(forceCheck = false) {
|
|
196
198
|
(0, assert_1.default)(this._ready);
|
|
197
199
|
(0, assert_1.default)(this._preparations, ERROR_NOT_PREPARED);
|
|
198
|
-
return forceCheck || this.shouldCheckDocument() ? [...this.
|
|
200
|
+
return forceCheck || this.shouldCheckDocument() ? [...this._checkParsedText(this._parse())] : [];
|
|
199
201
|
}
|
|
200
202
|
get document() {
|
|
201
203
|
return this._document;
|
|
@@ -204,15 +206,20 @@ class DocumentValidator {
|
|
|
204
206
|
(0, TextDocument_1.updateTextDocument)(this._document, [{ text }]);
|
|
205
207
|
this._updatePrep();
|
|
206
208
|
}
|
|
207
|
-
|
|
209
|
+
defaultParser() {
|
|
210
|
+
return (0, cspell_pipe_1.pipeSync)(this.document.getLines(), (0, cspell_pipe_1.opMap)((line) => {
|
|
211
|
+
const { text, offset } = line;
|
|
212
|
+
const range = [offset, offset + text.length];
|
|
213
|
+
return { text, range };
|
|
214
|
+
}));
|
|
215
|
+
}
|
|
216
|
+
*_checkParsedText(parsedTexts) {
|
|
208
217
|
(0, assert_1.default)(this._preparations, ERROR_NOT_PREPARED);
|
|
209
218
|
const { maxNumberOfProblems = textValidator_1.defaultMaxNumberOfProblems, maxDuplicateProblems = textValidator_1.defaultMaxDuplicateProblems } = this._preparations.validateOptions;
|
|
210
219
|
let numProblems = 0;
|
|
211
220
|
const mapOfProblems = new Map();
|
|
212
|
-
for (const
|
|
213
|
-
const
|
|
214
|
-
const range = [offset, offset + text.length];
|
|
215
|
-
for (const issue of this.check({ text, range })) {
|
|
221
|
+
for (const pText of parsedTexts) {
|
|
222
|
+
for (const issue of this.check(pText)) {
|
|
216
223
|
const { text } = issue;
|
|
217
224
|
const n = (mapOfProblems.get(text) || 0) + 1;
|
|
218
225
|
mapOfProblems.set(text, n);
|
|
@@ -244,6 +251,13 @@ class DocumentValidator {
|
|
|
244
251
|
}
|
|
245
252
|
return undefined;
|
|
246
253
|
}
|
|
254
|
+
_parse() {
|
|
255
|
+
(0, assert_1.default)(this._preparations, ERROR_NOT_PREPARED);
|
|
256
|
+
const parser = this._preparations.finalSettings.parser;
|
|
257
|
+
if (typeof parser !== 'object')
|
|
258
|
+
return this.defaultParser();
|
|
259
|
+
return parser.parse(this.document.text, this.document.uri.path).parsedTexts;
|
|
260
|
+
}
|
|
247
261
|
suggest(text) {
|
|
248
262
|
return this._suggestions.get(text);
|
|
249
263
|
}
|
|
@@ -4,5 +4,5 @@ export { checkText, IncludeExcludeFlag, validateText } from './validator';
|
|
|
4
4
|
export type { CheckTextInfo, TextInfoItem, ValidateTextOptions, ValidationIssue } from './validator';
|
|
5
5
|
export { DocumentValidator } from './docValidator';
|
|
6
6
|
export type { DocumentValidatorOptions } from './docValidator';
|
|
7
|
-
export type { Offset, SimpleRange
|
|
7
|
+
export type { Offset, SimpleRange } from './parsedText';
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,21 +1,7 @@
|
|
|
1
|
+
import { ParsedText } from '@cspell/cspell-types';
|
|
1
2
|
import { ValidationIssue } from './validator';
|
|
2
3
|
export declare type Offset = number;
|
|
3
4
|
export declare type SimpleRange = readonly [Offset, Offset];
|
|
4
|
-
export interface ParsedText {
|
|
5
|
-
/**
|
|
6
|
-
* Transformed text
|
|
7
|
-
*/
|
|
8
|
-
text: string;
|
|
9
|
-
/**
|
|
10
|
-
* Offset pair of the original text
|
|
11
|
-
*/
|
|
12
|
-
range: SimpleRange;
|
|
13
|
-
/**
|
|
14
|
-
* Relative map to the original text.
|
|
15
|
-
*/
|
|
16
|
-
map?: number[];
|
|
17
|
-
scope?: string[];
|
|
18
|
-
}
|
|
19
5
|
export declare function mapIssueBackToOriginalPos(parsedText: ParsedText, issue: ValidationIssue): ValidationIssue;
|
|
20
6
|
export declare function mapRangeBackToOriginalPos(offRange: SimpleRange, map: number[]): SimpleRange;
|
|
21
7
|
//# sourceMappingURL=parsedText.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cspell-lib",
|
|
3
|
-
"version": "6.1.3-alpha.
|
|
3
|
+
"version": "6.1.3-alpha.1",
|
|
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,16 +48,16 @@
|
|
|
48
48
|
},
|
|
49
49
|
"homepage": "https://github.com/streetsidesoftware/cspell#readme",
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@cspell/cspell-bundled-dicts": "^6.1.3-alpha.
|
|
52
|
-
"@cspell/cspell-pipe": "^6.1.3-alpha.
|
|
53
|
-
"@cspell/cspell-types": "^6.1.3-alpha.
|
|
51
|
+
"@cspell/cspell-bundled-dicts": "^6.1.3-alpha.1",
|
|
52
|
+
"@cspell/cspell-pipe": "^6.1.3-alpha.1",
|
|
53
|
+
"@cspell/cspell-types": "^6.1.3-alpha.1",
|
|
54
54
|
"clear-module": "^4.1.2",
|
|
55
55
|
"comment-json": "^4.2.2",
|
|
56
56
|
"configstore": "^5.0.1",
|
|
57
57
|
"cosmiconfig": "^7.0.1",
|
|
58
|
-
"cspell-glob": "^6.1.3-alpha.
|
|
59
|
-
"cspell-io": "^6.1.3-alpha.
|
|
60
|
-
"cspell-trie-lib": "^6.1.3-alpha.
|
|
58
|
+
"cspell-glob": "^6.1.3-alpha.1",
|
|
59
|
+
"cspell-io": "^6.1.3-alpha.1",
|
|
60
|
+
"cspell-trie-lib": "^6.1.3-alpha.1",
|
|
61
61
|
"fast-equals": "^4.0.1",
|
|
62
62
|
"find-up": "^5.0.0",
|
|
63
63
|
"fs-extra": "^10.1.0",
|
|
@@ -92,5 +92,5 @@
|
|
|
92
92
|
"rollup-plugin-dts": "^4.2.2",
|
|
93
93
|
"ts-jest": "^28.0.5"
|
|
94
94
|
},
|
|
95
|
-
"gitHead": "
|
|
95
|
+
"gitHead": "3b0a99870292387ca96aba8a7da701575b56ed5b"
|
|
96
96
|
}
|