cspell-lib 6.1.2 → 6.1.3
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/LanguageIds.js +1 -2
- package/dist/Models/TextDocument.js +3 -3
- package/dist/Settings/CSpellSettingsServer.js +45 -10
- package/dist/Settings/DictionarySettings.js +1 -1
- package/dist/Settings/LanguageSettings.js +1 -2
- package/dist/Settings/configLoader.js +15 -19
- package/dist/Settings/link.js +5 -6
- package/dist/Settings/pnpLoader.js +1 -2
- package/dist/SpellingDictionary/DictionaryLoader.js +2 -2
- package/dist/SpellingDictionary/SpellingDictionary.d.ts +2 -2
- package/dist/SpellingDictionary/SpellingDictionaryCollection.js +1 -1
- package/dist/SpellingDictionary/SpellingDictionaryFromTrie.js +3 -4
- package/dist/SpellingDictionary/SpellingDictionaryMethods.d.ts +2 -2
- package/dist/SpellingDictionary/SpellingDictionaryMethods.js +4 -4
- package/dist/SpellingDictionary/createSpellingDictionary.js +1 -1
- package/dist/spellCheckFile.js +3 -3
- package/dist/suggestions.js +9 -13
- package/dist/textValidation/ValidationTypes.d.ts +41 -0
- package/dist/textValidation/ValidationTypes.js +3 -0
- package/dist/textValidation/determineTextDocumentSettings.js +2 -3
- package/dist/textValidation/docValidator.d.ts +11 -7
- package/dist/textValidation/docValidator.js +56 -43
- package/dist/textValidation/index.d.ts +2 -2
- package/dist/textValidation/isWordValid.d.ts +12 -0
- package/dist/textValidation/isWordValid.js +19 -0
- package/dist/textValidation/lineValidatorFactory.d.ts +5 -0
- package/dist/textValidation/lineValidatorFactory.js +145 -0
- package/dist/textValidation/parsedText.d.ts +11 -17
- package/dist/textValidation/parsedText.js +74 -10
- package/dist/textValidation/textValidator.d.ts +5 -42
- package/dist/textValidation/textValidator.js +8 -114
- package/dist/textValidation/validator.d.ts +5 -1
- package/dist/textValidation/validator.js +6 -4
- package/dist/trace.js +15 -19
- package/dist/util/Memorizer.d.ts +8 -1
- package/dist/util/Memorizer.js +10 -6
- package/dist/util/PairingHeap.js +1 -2
- package/dist/util/TextMap.d.ts +15 -0
- package/dist/util/TextMap.js +62 -0
- package/dist/util/memorizerWeak.js +2 -4
- package/dist/util/search.js +2 -2
- package/dist/util/text.js +1 -1
- package/dist/util/timer.js +1 -1
- package/dist/util/wordSplitter.js +2 -4
- package/package.json +13 -13
package/dist/LanguageIds.js
CHANGED
|
@@ -241,7 +241,6 @@ function doesSetContainAnyOf(setOfIds, languageId) {
|
|
|
241
241
|
}
|
|
242
242
|
function buildLanguageExtensionMapSet(defs) {
|
|
243
243
|
return defs.reduce((map, def) => {
|
|
244
|
-
var _a;
|
|
245
244
|
function getMapSet(value) {
|
|
246
245
|
const found = map.get(value);
|
|
247
246
|
if (found)
|
|
@@ -254,7 +253,7 @@ function buildLanguageExtensionMapSet(defs) {
|
|
|
254
253
|
getMapSet(value).add(def.id);
|
|
255
254
|
}
|
|
256
255
|
def.extensions.forEach(addId);
|
|
257
|
-
|
|
256
|
+
def.filenames?.forEach(addId);
|
|
258
257
|
return map;
|
|
259
258
|
}, new Map());
|
|
260
259
|
}
|
|
@@ -98,7 +98,7 @@ class TextDocumentImpl {
|
|
|
98
98
|
* @returns this
|
|
99
99
|
*/
|
|
100
100
|
update(edits, version) {
|
|
101
|
-
version = version
|
|
101
|
+
version = version ?? this.version + 1;
|
|
102
102
|
for (const edit of edits) {
|
|
103
103
|
const vsEdit = edit.range
|
|
104
104
|
? {
|
|
@@ -112,9 +112,9 @@ class TextDocumentImpl {
|
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
function createTextDocument({ uri, content, languageId, locale, version, }) {
|
|
115
|
-
version = version
|
|
115
|
+
version = version ?? 1;
|
|
116
116
|
uri = Uri.toUri(uri);
|
|
117
|
-
languageId = languageId
|
|
117
|
+
languageId = languageId ?? (0, LanguageIds_1.getLanguagesForBasename)(Uri.basename(uri));
|
|
118
118
|
languageId = languageId.length === 0 ? 'text' : languageId;
|
|
119
119
|
return new TextDocumentImpl(uri, content, languageId, locale, version);
|
|
120
120
|
}
|
|
@@ -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");
|
|
@@ -116,7 +120,7 @@ function merge(left, right) {
|
|
|
116
120
|
const leftId = _left.id || _left.languageId || '';
|
|
117
121
|
const rightId = _right.id || _right.languageId || '';
|
|
118
122
|
const includeRegExpList = takeRightOtherwiseLeft(_left.includeRegExpList, _right.includeRegExpList);
|
|
119
|
-
const optionals =
|
|
123
|
+
const optionals = includeRegExpList?.length ? { includeRegExpList } : {};
|
|
120
124
|
const version = max(_left.version, _right.version);
|
|
121
125
|
const settings = (0, CSpellSettingsInternalDef_1.createCSpellSettingsInternal)({
|
|
122
126
|
..._left,
|
|
@@ -146,6 +150,7 @@ function merge(left, right) {
|
|
|
146
150
|
description: undefined,
|
|
147
151
|
globRoot: undefined,
|
|
148
152
|
import: undefined,
|
|
153
|
+
plugins: mergeList(_left.plugins, _right.plugins),
|
|
149
154
|
__imports: mergeImportRefs(_left, _right),
|
|
150
155
|
__importRef: undefined,
|
|
151
156
|
});
|
|
@@ -176,8 +181,7 @@ function doesLeftHaveRightAncestor(left, right) {
|
|
|
176
181
|
return hasAncestor(left, right, 1);
|
|
177
182
|
}
|
|
178
183
|
function hasAncestor(s, ancestor, side) {
|
|
179
|
-
|
|
180
|
-
const sources = (_a = s.source) === null || _a === void 0 ? void 0 : _a.sources;
|
|
184
|
+
const sources = s.source?.sources;
|
|
181
185
|
if (!sources)
|
|
182
186
|
return false;
|
|
183
187
|
// calc the first or last index of the source array.
|
|
@@ -194,7 +198,7 @@ function mergeInDocSettings(left, right) {
|
|
|
194
198
|
}
|
|
195
199
|
exports.mergeInDocSettings = mergeInDocSettings;
|
|
196
200
|
function takeRightOtherwiseLeft(left, right) {
|
|
197
|
-
if (right
|
|
201
|
+
if (right?.length) {
|
|
198
202
|
return right;
|
|
199
203
|
}
|
|
200
204
|
return left || right;
|
|
@@ -224,19 +228,19 @@ 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] };
|
|
230
235
|
return finalized;
|
|
231
236
|
}
|
|
232
237
|
function toInternalSettings(settings) {
|
|
233
|
-
var _a;
|
|
234
238
|
if (settings === undefined)
|
|
235
239
|
return undefined;
|
|
236
240
|
if ((0, CSpellSettingsInternalDef_1.isCSpellSettingsInternal)(settings))
|
|
237
241
|
return settings;
|
|
238
242
|
const { dictionaryDefinitions: defs, ...rest } = settings;
|
|
239
|
-
const dictionaryDefinitions = (0, DictionarySettings_1.mapDictDefsToInternal)(defs, filenameToDirectory(
|
|
243
|
+
const dictionaryDefinitions = (0, DictionarySettings_1.mapDictDefsToInternal)(defs, filenameToDirectory(settings.source?.filename) || resolveCwd());
|
|
240
244
|
const setting = dictionaryDefinitions ? { ...rest, dictionaryDefinitions } : rest;
|
|
241
245
|
return (0, CSpellSettingsInternalDef_1.createCSpellSettingsInternal)(setting);
|
|
242
246
|
}
|
|
@@ -279,11 +283,10 @@ function getSources(settings) {
|
|
|
279
283
|
const visited = new Set();
|
|
280
284
|
const sources = [];
|
|
281
285
|
function _walkSourcesTree(settings) {
|
|
282
|
-
var _a, _b;
|
|
283
286
|
if (!settings || visited.has(settings))
|
|
284
287
|
return;
|
|
285
288
|
visited.add(settings);
|
|
286
|
-
if (!
|
|
289
|
+
if (!settings.source?.sources?.length) {
|
|
287
290
|
sources.push(settings);
|
|
288
291
|
return;
|
|
289
292
|
}
|
|
@@ -294,7 +297,6 @@ function getSources(settings) {
|
|
|
294
297
|
}
|
|
295
298
|
exports.getSources = getSources;
|
|
296
299
|
function mergeImportRefs(left, right = {}) {
|
|
297
|
-
var _a;
|
|
298
300
|
const imports = new Map(left.__imports || []);
|
|
299
301
|
if (left.__importRef) {
|
|
300
302
|
imports.set(left.__importRef.filename, left.__importRef);
|
|
@@ -302,7 +304,7 @@ function mergeImportRefs(left, right = {}) {
|
|
|
302
304
|
if (right.__importRef) {
|
|
303
305
|
imports.set(right.__importRef.filename, right.__importRef);
|
|
304
306
|
}
|
|
305
|
-
const rightImports =
|
|
307
|
+
const rightImports = right.__imports?.values() || [];
|
|
306
308
|
for (const ref of rightImports) {
|
|
307
309
|
imports.set(ref.filename, ref);
|
|
308
310
|
}
|
|
@@ -323,6 +325,39 @@ function resolveCwd() {
|
|
|
323
325
|
const cwd = envGlobRoot || process.cwd();
|
|
324
326
|
return cwd;
|
|
325
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
|
+
}
|
|
326
361
|
exports.__testing__ = {
|
|
327
362
|
mergeObjects,
|
|
328
363
|
};
|
|
@@ -59,7 +59,7 @@ function fixPath(def) {
|
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
61
|
function mapDictDefsToInternal(defs, pathToSettingsFile) {
|
|
62
|
-
return defs
|
|
62
|
+
return defs?.map((def) => mapDictDefToInternal(def, pathToSettingsFile));
|
|
63
63
|
}
|
|
64
64
|
exports.mapDictDefsToInternal = mapDictDefsToInternal;
|
|
65
65
|
function mapDictDefToInternal(def, pathToSettingsFile) {
|
|
@@ -85,8 +85,7 @@ function calcSettingsForLanguage(languageSettings, languageId, locale) {
|
|
|
85
85
|
exports.calcSettingsForLanguage = calcSettingsForLanguage;
|
|
86
86
|
const cacheDoesLanguageSettingMatchLanguageId = new WeakMap();
|
|
87
87
|
function doesLanguageSettingMatchLanguageId(s, languageId) {
|
|
88
|
-
|
|
89
|
-
const r = (_a = cacheDoesLanguageSettingMatchLanguageId.get(s)) !== null && _a !== void 0 ? _a : new Map();
|
|
88
|
+
const r = cacheDoesLanguageSettingMatchLanguageId.get(s) ?? new Map();
|
|
90
89
|
const f = r.get(languageId);
|
|
91
90
|
if (f !== undefined) {
|
|
92
91
|
return f;
|
|
@@ -105,7 +105,7 @@ function readConfig(fileRef) {
|
|
|
105
105
|
const s = {};
|
|
106
106
|
try {
|
|
107
107
|
const r = cspellConfigExplorerSync.load(filename);
|
|
108
|
-
if (!
|
|
108
|
+
if (!r?.config)
|
|
109
109
|
throw new Error(`not found: "${filename}"`);
|
|
110
110
|
Object.assign(s, r.config);
|
|
111
111
|
normalizeRawConfig(s);
|
|
@@ -190,7 +190,7 @@ function mergeSourceList(orig, append) {
|
|
|
190
190
|
return [...collection.values()];
|
|
191
191
|
}
|
|
192
192
|
function importSettings(fileRef, defaultValues, pnpSettings) {
|
|
193
|
-
defaultValues = defaultValues
|
|
193
|
+
defaultValues = defaultValues ?? defaultSettings;
|
|
194
194
|
let { filename } = fileRef;
|
|
195
195
|
filename = path.resolve(filename);
|
|
196
196
|
const importRef = { ...fileRef, filename };
|
|
@@ -230,10 +230,9 @@ async function normalizeSearchForConfigResultAsync(searchPath, searchResult, pnp
|
|
|
230
230
|
return normalizeSearchForConfigResult(searchPath, result, pnpSettings);
|
|
231
231
|
}
|
|
232
232
|
function normalizeSearchForConfigResult(searchPath, searchResult, pnpSettings) {
|
|
233
|
-
var _a;
|
|
234
233
|
const error = searchResult instanceof ImportError_1.ImportError ? searchResult : undefined;
|
|
235
234
|
const result = searchResult instanceof ImportError_1.ImportError ? undefined : searchResult;
|
|
236
|
-
const filepath = result
|
|
235
|
+
const filepath = result?.filepath;
|
|
237
236
|
if (filepath) {
|
|
238
237
|
const cached = cachedFiles.get(filepath);
|
|
239
238
|
if (cached) {
|
|
@@ -245,10 +244,10 @@ function normalizeSearchForConfigResult(searchPath, searchResult, pnpSettings) {
|
|
|
245
244
|
}
|
|
246
245
|
}
|
|
247
246
|
const { config = (0, CSpellSettingsInternalDef_1.createCSpellSettingsInternal)({}) } = result || {};
|
|
248
|
-
const filename =
|
|
247
|
+
const filename = result?.filepath ?? searchPath;
|
|
249
248
|
const importRef = { filename: filename, error };
|
|
250
249
|
const id = [path.basename(path.dirname(filename)), path.basename(filename)].join('/');
|
|
251
|
-
const name =
|
|
250
|
+
const name = result?.filepath ? id : `Config not found: ${id}`;
|
|
252
251
|
const finalizeSettings = (0, CSpellSettingsInternalDef_1.createCSpellSettingsInternal)({ id, name, __importRef: importRef });
|
|
253
252
|
const settings = { id, ...config };
|
|
254
253
|
cachedFiles.set(filename, finalizeSettings); // add an empty entry to prevent circular references.
|
|
@@ -371,7 +370,6 @@ function clearCachedSettingsFiles() {
|
|
|
371
370
|
}
|
|
372
371
|
exports.clearCachedSettingsFiles = clearCachedSettingsFiles;
|
|
373
372
|
function mergeImportRefs(left, right = {}) {
|
|
374
|
-
var _a;
|
|
375
373
|
const imports = new Map(left.__imports || []);
|
|
376
374
|
if (left.__importRef) {
|
|
377
375
|
imports.set(left.__importRef.filename, left.__importRef);
|
|
@@ -379,7 +377,7 @@ function mergeImportRefs(left, right = {}) {
|
|
|
379
377
|
if (right.__importRef) {
|
|
380
378
|
imports.set(right.__importRef.filename, right.__importRef);
|
|
381
379
|
}
|
|
382
|
-
const rightImports =
|
|
380
|
+
const rightImports = right.__imports?.values() || [];
|
|
383
381
|
for (const ref of rightImports) {
|
|
384
382
|
imports.set(ref.filename, ref);
|
|
385
383
|
}
|
|
@@ -394,17 +392,17 @@ function extractImportErrors(settings) {
|
|
|
394
392
|
}
|
|
395
393
|
exports.extractImportErrors = extractImportErrors;
|
|
396
394
|
function resolveGlobRoot(settings, pathToSettingsFile) {
|
|
397
|
-
var _a;
|
|
398
395
|
const settingsFileDirRaw = path.dirname(pathToSettingsFile);
|
|
399
396
|
const isVSCode = path.basename(settingsFileDirRaw) === '.vscode';
|
|
400
397
|
const settingsFileDir = isVSCode ? path.dirname(settingsFileDirRaw) : settingsFileDirRaw;
|
|
401
398
|
const envGlobRoot = process.env[CSpellSettingsServer_1.ENV_CSPELL_GLOB_ROOT];
|
|
402
|
-
const defaultGlobRoot = envGlobRoot
|
|
403
|
-
const rawRoot =
|
|
404
|
-
(
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
399
|
+
const defaultGlobRoot = envGlobRoot ?? '${cwd}';
|
|
400
|
+
const rawRoot = settings.globRoot ??
|
|
401
|
+
(settings.version === CSpellSettingsServer_1.configSettingsFileVersion0_1 ||
|
|
402
|
+
(envGlobRoot && !settings.version) ||
|
|
403
|
+
(isVSCode && !settings.version)
|
|
404
|
+
? defaultGlobRoot
|
|
405
|
+
: settingsFileDir);
|
|
408
406
|
const globRoot = rawRoot.startsWith('${cwd}') ? rawRoot : path.resolve(settingsFileDir, rawRoot);
|
|
409
407
|
return globRoot;
|
|
410
408
|
}
|
|
@@ -431,9 +429,8 @@ function toGlobDef(g, root, source) {
|
|
|
431
429
|
return g;
|
|
432
430
|
}
|
|
433
431
|
function normalizeDictionaryDefs(settings, pathToSettingsFile) {
|
|
434
|
-
var _a;
|
|
435
432
|
const dictionaryDefinitions = (0, DictionarySettings_1.mapDictDefsToInternal)(settings.dictionaryDefinitions, pathToSettingsFile);
|
|
436
|
-
const languageSettings =
|
|
433
|
+
const languageSettings = settings.languageSettings?.map((langSetting) => util.clean({
|
|
437
434
|
...langSetting,
|
|
438
435
|
dictionaryDefinitions: (0, DictionarySettings_1.mapDictDefsToInternal)(langSetting.dictionaryDefinitions, pathToSettingsFile),
|
|
439
436
|
}));
|
|
@@ -443,9 +440,8 @@ function normalizeDictionaryDefs(settings, pathToSettingsFile) {
|
|
|
443
440
|
});
|
|
444
441
|
}
|
|
445
442
|
function normalizeOverrides(settings, pathToSettingsFile) {
|
|
446
|
-
var _a;
|
|
447
443
|
const { globRoot = path.dirname(pathToSettingsFile) } = settings;
|
|
448
|
-
const overrides =
|
|
444
|
+
const overrides = settings.overrides?.map((override) => {
|
|
449
445
|
const filename = toGlobDef(override.filename, globRoot, pathToSettingsFile);
|
|
450
446
|
const { dictionaryDefinitions, languageSettings } = normalizeDictionaryDefs(override, pathToSettingsFile);
|
|
451
447
|
return util.clean({
|
package/dist/Settings/link.js
CHANGED
|
@@ -72,7 +72,7 @@ function addPathsToGlobalImports(paths) {
|
|
|
72
72
|
const error = (0, GlobalSettings_1.writeRawGlobalSettings)(globalSettings);
|
|
73
73
|
return {
|
|
74
74
|
success: !error,
|
|
75
|
-
error: error
|
|
75
|
+
error: error?.message,
|
|
76
76
|
resolvedSettings,
|
|
77
77
|
};
|
|
78
78
|
}
|
|
@@ -88,7 +88,7 @@ function removePathsFromGlobalImports(paths) {
|
|
|
88
88
|
const listResult = listGlobalImports();
|
|
89
89
|
const toRemove = new Set();
|
|
90
90
|
function matchPackage(pathToRemove) {
|
|
91
|
-
return ({ package: pkg, id }) => pathToRemove ===
|
|
91
|
+
return ({ package: pkg, id }) => pathToRemove === pkg?.name || pathToRemove === id;
|
|
92
92
|
}
|
|
93
93
|
function compareFilenames(fullPath, partialPath) {
|
|
94
94
|
if (fullPath === partialPath)
|
|
@@ -124,16 +124,15 @@ function removePathsFromGlobalImports(paths) {
|
|
|
124
124
|
return {
|
|
125
125
|
success: true,
|
|
126
126
|
removed: [...toRemove],
|
|
127
|
-
error: error
|
|
127
|
+
error: error?.toString(),
|
|
128
128
|
};
|
|
129
129
|
}
|
|
130
130
|
exports.removePathsFromGlobalImports = removePathsFromGlobalImports;
|
|
131
131
|
function resolveSettings(filename) {
|
|
132
|
-
var _a;
|
|
133
132
|
const settings = (0, configLoader_1.readRawSettings)(filename);
|
|
134
133
|
const ref = settings.__importRef;
|
|
135
|
-
const resolvedToFilename = ref
|
|
136
|
-
const error =
|
|
134
|
+
const resolvedToFilename = ref?.filename;
|
|
135
|
+
const error = ref?.error?.message || (!resolvedToFilename && 'File not Found') || undefined;
|
|
137
136
|
return (0, util_1.clean)({
|
|
138
137
|
filename,
|
|
139
138
|
resolvedToFilename,
|
|
@@ -40,10 +40,9 @@ class PnpLoader {
|
|
|
40
40
|
return result;
|
|
41
41
|
}
|
|
42
42
|
async peek(uriDirectory) {
|
|
43
|
-
var _a;
|
|
44
43
|
await lock;
|
|
45
44
|
const cacheKey = this.calcKey(uriDirectory);
|
|
46
|
-
return
|
|
45
|
+
return cachedRequests.get(cacheKey) ?? Promise.resolve(undefined);
|
|
47
46
|
}
|
|
48
47
|
/**
|
|
49
48
|
* Request that the nearest .pnp file gets loaded
|
|
@@ -89,7 +89,7 @@ function loadDictionary(def) {
|
|
|
89
89
|
exports.loadDictionary = loadDictionary;
|
|
90
90
|
function loadDictionarySync(def) {
|
|
91
91
|
const { key, entry } = getCacheEntry(def);
|
|
92
|
-
if (
|
|
92
|
+
if (entry?.dictionary && entry.loadingState === LoadingState.Loaded) {
|
|
93
93
|
return entry.dictionary;
|
|
94
94
|
}
|
|
95
95
|
const loadedEntry = loadEntrySync(def.path, def);
|
|
@@ -101,7 +101,7 @@ const importantOptionKeys = ['name', 'noSuggest', 'useCompounds', 'type'];
|
|
|
101
101
|
function calcKey(def) {
|
|
102
102
|
const path = def.path;
|
|
103
103
|
const loaderType = determineType(path, def);
|
|
104
|
-
const optValues = importantOptionKeys.map((k) =>
|
|
104
|
+
const optValues = importantOptionKeys.map((k) => def[k]?.toString() || '');
|
|
105
105
|
const parts = [path, loaderType].concat(optValues);
|
|
106
106
|
return parts.join('|');
|
|
107
107
|
}
|
|
@@ -2,8 +2,8 @@ import type { ReplaceMap, DictionaryInformation } from '@cspell/cspell-types';
|
|
|
2
2
|
import { CompoundWordsMethod, SuggestionCollector, SuggestionResult, WeightMap } from 'cspell-trie-lib';
|
|
3
3
|
export { CompoundWordsMethod, SuggestionCollector, SuggestionResult } from 'cspell-trie-lib';
|
|
4
4
|
export interface SearchOptions {
|
|
5
|
-
useCompounds?: boolean | number;
|
|
6
|
-
ignoreCase?: boolean;
|
|
5
|
+
useCompounds?: boolean | number | undefined;
|
|
6
|
+
ignoreCase?: boolean | undefined;
|
|
7
7
|
}
|
|
8
8
|
export interface SuggestOptions {
|
|
9
9
|
/**
|
|
@@ -82,7 +82,7 @@ class SpellingDictionaryCollection {
|
|
|
82
82
|
this.dictionaries.forEach((dict) => dict.genSuggestions(collector, _suggestOptions));
|
|
83
83
|
}
|
|
84
84
|
getErrors() {
|
|
85
|
-
return this.dictionaries.reduce((errors, dict) =>
|
|
85
|
+
return this.dictionaries.reduce((errors, dict) => errors.concat(dict.getErrors?.() || []), []);
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
exports.SpellingDictionaryCollection = SpellingDictionaryCollection;
|
|
@@ -9,7 +9,6 @@ const util_1 = require("../util/util");
|
|
|
9
9
|
const SpellingDictionaryMethods_1 = require("./SpellingDictionaryMethods");
|
|
10
10
|
class SpellingDictionaryFromTrie {
|
|
11
11
|
constructor(trie, name, options, source = 'from trie', size) {
|
|
12
|
-
var _a;
|
|
13
12
|
this.trie = trie;
|
|
14
13
|
this.name = name;
|
|
15
14
|
this.options = options;
|
|
@@ -20,7 +19,7 @@ class SpellingDictionaryFromTrie {
|
|
|
20
19
|
this.type = 'SpellingDictionaryFromTrie';
|
|
21
20
|
this._find = (0, Memorizer_1.memorizer)((word, useCompounds, ignoreCase) => this.findAnyForm(word, useCompounds, ignoreCase), SpellingDictionaryFromTrie.cachedWordsLimit);
|
|
22
21
|
this.mapWord = (0, repMap_1.createMapper)(options.repMap || []);
|
|
23
|
-
this.isDictionaryCaseSensitive =
|
|
22
|
+
this.isDictionaryCaseSensitive = options.caseSensitive ?? !trie.isLegacy;
|
|
24
23
|
this.containsNoSuggestWords = options.noSuggest || false;
|
|
25
24
|
this._size = size || 0;
|
|
26
25
|
this.weightMap = options.weightMap || (0, SpellingDictionaryMethods_1.createWeightMapFromDictionaryInformation)(options.dictionaryInformation);
|
|
@@ -114,10 +113,10 @@ class SpellingDictionaryFromTrie {
|
|
|
114
113
|
return collector.suggestions.map((r) => ({ ...r, word: r.word }));
|
|
115
114
|
}
|
|
116
115
|
genSuggestions(collector, suggestOptions) {
|
|
117
|
-
var _a;
|
|
118
116
|
if (this.options.noSuggest)
|
|
119
117
|
return;
|
|
120
|
-
const _compoundMethod =
|
|
118
|
+
const _compoundMethod = suggestOptions.compoundMethod ??
|
|
119
|
+
(this.options.useCompounds ? cspell_trie_lib_1.CompoundWordsMethod.JOIN_WORDS : cspell_trie_lib_1.CompoundWordsMethod.NONE);
|
|
121
120
|
(0, SpellingDictionaryMethods_1.wordSuggestFormsArray)(collector.word).forEach((w) => this.trie.genSuggestions((0, SpellingDictionaryMethods_1.impersonateCollector)(collector, w), _compoundMethod));
|
|
122
121
|
}
|
|
123
122
|
getErrors() {
|
|
@@ -5,7 +5,7 @@ export { impersonateCollector, suggestionCollector } from 'cspell-trie-lib';
|
|
|
5
5
|
export declare type FilterSuggestionsPredicate = (word: SuggestionResult) => boolean;
|
|
6
6
|
export declare type SuggestArgs = Parameters<SpellingDictionary['suggest']> | Parameters<(word: string, numSuggestions?: number, compoundMethod?: CompoundWordsMethod, numChanges?: number, ignoreCase?: boolean) => SuggestionResult[]>;
|
|
7
7
|
export declare const defaultNumSuggestions = 10;
|
|
8
|
-
|
|
8
|
+
declare function wordSearchFormsArray(word: string, isDictionaryCaseSensitive: boolean, ignoreCase: boolean): string[];
|
|
9
9
|
export declare function wordSearchForms(word: string, isDictionaryCaseSensitive: boolean, ignoreCase: boolean): Set<string>;
|
|
10
10
|
export declare function wordSuggestFormsArray(word: string): string[];
|
|
11
11
|
export declare function wordSuggestForms(word: string): Set<string>;
|
|
@@ -20,7 +20,7 @@ export declare function suggestArgsToSuggestOptions(args: SuggestArgs): SuggestO
|
|
|
20
20
|
export declare function createWeightMapFromDictionaryInformation(di: undefined): undefined;
|
|
21
21
|
export declare function createWeightMapFromDictionaryInformation(di: DictionaryInformation): WeightMap;
|
|
22
22
|
export declare function createWeightMapFromDictionaryInformation(di: DictionaryInformation | undefined): WeightMap | undefined;
|
|
23
|
-
export declare const
|
|
23
|
+
export declare const __testMethods__: {
|
|
24
24
|
wordSearchForms: typeof wordSearchForms;
|
|
25
25
|
wordSearchFormsArray: typeof wordSearchFormsArray;
|
|
26
26
|
wordDictionaryForms: typeof wordDictionaryForms;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.__testMethods__ = exports.createWeightMapFromDictionaryInformation = exports.suggestArgsToSuggestOptions = exports.hasOptionToSearchOption = exports.wordDictionaryFormsCollector = exports.wordSuggestForms = exports.wordSuggestFormsArray = exports.wordSearchForms = exports.defaultNumSuggestions = exports.suggestionCollector = exports.impersonateCollector = void 0;
|
|
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");
|
|
@@ -12,7 +12,6 @@ exports.defaultNumSuggestions = 10;
|
|
|
12
12
|
function wordSearchFormsArray(word, isDictionaryCaseSensitive, ignoreCase) {
|
|
13
13
|
return [...wordSearchForms(word, isDictionaryCaseSensitive, ignoreCase)];
|
|
14
14
|
}
|
|
15
|
-
exports.wordSearchFormsArray = wordSearchFormsArray;
|
|
16
15
|
function wordSearchForms(word, isDictionaryCaseSensitive, ignoreCase) {
|
|
17
16
|
const forms = new Set();
|
|
18
17
|
word = word.normalize('NFC');
|
|
@@ -82,8 +81,9 @@ function wordDictionaryFormsCollector(prefixNoCase) {
|
|
|
82
81
|
};
|
|
83
82
|
}
|
|
84
83
|
exports.wordDictionaryFormsCollector = wordDictionaryFormsCollector;
|
|
84
|
+
const DEFAULT_HAS_OPTIONS = Object.freeze({});
|
|
85
85
|
function hasOptionToSearchOption(opt) {
|
|
86
|
-
return !opt ?
|
|
86
|
+
return !opt ? DEFAULT_HAS_OPTIONS : opt;
|
|
87
87
|
}
|
|
88
88
|
exports.hasOptionToSearchOption = hasOptionToSearchOption;
|
|
89
89
|
function suggestArgsToSuggestOptions(args) {
|
|
@@ -105,7 +105,7 @@ function createWeightMapFromDictionaryInformation(di) {
|
|
|
105
105
|
return di ? (0, cspell_trie_lib_1.mapDictionaryInformationToWeightMap)(di) : undefined;
|
|
106
106
|
}
|
|
107
107
|
exports.createWeightMapFromDictionaryInformation = createWeightMapFromDictionaryInformation;
|
|
108
|
-
exports.
|
|
108
|
+
exports.__testMethods__ = {
|
|
109
109
|
wordSearchForms,
|
|
110
110
|
wordSearchFormsArray,
|
|
111
111
|
wordDictionaryForms,
|
|
@@ -45,7 +45,7 @@ function _createSpellingDictionary(params) {
|
|
|
45
45
|
function createForbiddenWordsDictionary(wordList, name, source, options) {
|
|
46
46
|
// console.log(`createSpellingDictionary ${name} ${source}`);
|
|
47
47
|
const words = (0, cspell_trie_lib_1.parseDictionaryLines)(wordList.concat(wordList.map((a) => a.toLowerCase())), {
|
|
48
|
-
stripCaseAndAccents: !
|
|
48
|
+
stripCaseAndAccents: !options?.noSuggest,
|
|
49
49
|
});
|
|
50
50
|
const forbidWords = gensequence_1.operators.map((w) => '!' + w)(words);
|
|
51
51
|
const trie = (0, cspell_trie_lib_1.buildTrieFast)(forbidWords);
|
package/dist/spellCheckFile.js
CHANGED
|
@@ -69,8 +69,8 @@ async function spellCheckFullDocument(document, options, settings) {
|
|
|
69
69
|
return {
|
|
70
70
|
document,
|
|
71
71
|
options,
|
|
72
|
-
settingsUsed:
|
|
73
|
-
localConfigFilepath: prep
|
|
72
|
+
settingsUsed: prep?.localConfig || settings,
|
|
73
|
+
localConfigFilepath: prep?.localConfigFilepath,
|
|
74
74
|
issues: [],
|
|
75
75
|
checked: false,
|
|
76
76
|
errors: docValidator.errors,
|
|
@@ -81,7 +81,7 @@ async function spellCheckFullDocument(document, options, settings) {
|
|
|
81
81
|
document,
|
|
82
82
|
options,
|
|
83
83
|
settingsUsed: docValidator.getFinalizedDocSettings(),
|
|
84
|
-
localConfigFilepath: prep
|
|
84
|
+
localConfigFilepath: prep?.localConfigFilepath,
|
|
85
85
|
issues,
|
|
86
86
|
checked: docValidator.shouldCheckDocument(),
|
|
87
87
|
errors: undefined,
|
package/dist/suggestions.js
CHANGED
|
@@ -35,21 +35,19 @@ async function* suggestionsForWords(words, options, settings = {}) {
|
|
|
35
35
|
}
|
|
36
36
|
exports.suggestionsForWords = suggestionsForWords;
|
|
37
37
|
async function suggestionsForWord(word, options, settings = {}) {
|
|
38
|
-
var _a;
|
|
39
38
|
const { languageId, locale: language, strict = true, numChanges = 4, numSuggestions = 8, includeTies = true, includeDefaultConfig = true, dictionaries, } = options || {};
|
|
40
39
|
const ignoreCase = !strict;
|
|
41
40
|
async function determineDictionaries(config) {
|
|
42
|
-
var _a, _b;
|
|
43
41
|
const withLocale = (0, Settings_1.mergeSettings)(config, util.clean({
|
|
44
42
|
language: language || config.language,
|
|
45
43
|
// dictionaries: dictionaries?.length ? dictionaries : config.dictionaries,
|
|
46
44
|
}));
|
|
47
|
-
const withLanguageId = (0, LanguageSettings_1.calcSettingsForLanguageId)(withLocale,
|
|
45
|
+
const withLanguageId = (0, LanguageSettings_1.calcSettingsForLanguageId)(withLocale, languageId ?? withLocale.languageId ?? 'plaintext');
|
|
48
46
|
const settings = (0, Settings_1.finalizeSettings)(withLanguageId);
|
|
49
|
-
settings.dictionaries =
|
|
47
|
+
settings.dictionaries = dictionaries?.length ? dictionaries : settings.dictionaries || [];
|
|
50
48
|
validateDictionaries(settings, dictionaries);
|
|
51
49
|
const dictionaryCollection = await (0, SpellingDictionary_1.getDictionaryInternal)(settings);
|
|
52
|
-
settings.dictionaries =
|
|
50
|
+
settings.dictionaries = settings.dictionaryDefinitions?.map((def) => def.name) || [];
|
|
53
51
|
const allDictionaryCollection = await (0, SpellingDictionary_1.getDictionaryInternal)(settings);
|
|
54
52
|
return {
|
|
55
53
|
dictionaryCollection,
|
|
@@ -58,7 +56,7 @@ async function suggestionsForWord(word, options, settings = {}) {
|
|
|
58
56
|
}
|
|
59
57
|
await (0, SpellingDictionary_1.refreshDictionaryCache)();
|
|
60
58
|
const config = includeDefaultConfig
|
|
61
|
-
? (0, Settings_1.mergeSettings)((0, Settings_1.getDefaultSettings)(
|
|
59
|
+
? (0, Settings_1.mergeSettings)((0, Settings_1.getDefaultSettings)(settings.loadDefaultConfiguration ?? true), (0, Settings_1.getGlobalSettings)(), settings)
|
|
62
60
|
: settings;
|
|
63
61
|
const { dictionaryCollection, allDictionaryCollection } = await determineDictionaries(config);
|
|
64
62
|
const opts = { ignoreCase, numChanges, numSuggestions, includeTies };
|
|
@@ -69,8 +67,8 @@ async function suggestionsForWord(word, options, settings = {}) {
|
|
|
69
67
|
const found = allDictionaryCollection.find(sug.word, findOpts);
|
|
70
68
|
return {
|
|
71
69
|
...sug,
|
|
72
|
-
forbidden:
|
|
73
|
-
noSuggest:
|
|
70
|
+
forbidden: found?.forbidden || false,
|
|
71
|
+
noSuggest: found?.noSuggest || false,
|
|
74
72
|
};
|
|
75
73
|
});
|
|
76
74
|
return {
|
|
@@ -92,8 +90,7 @@ function combine(suggestions) {
|
|
|
92
90
|
return [...words.values()];
|
|
93
91
|
}
|
|
94
92
|
function limitResults(suggestions, numSuggestions, includeTies) {
|
|
95
|
-
|
|
96
|
-
let cost = (_a = suggestions[0]) === null || _a === void 0 ? void 0 : _a.cost;
|
|
93
|
+
let cost = suggestions[0]?.cost;
|
|
97
94
|
let i = 0;
|
|
98
95
|
for (; i < suggestions.length; ++i) {
|
|
99
96
|
if (i >= numSuggestions && (!includeTies || suggestions[i].cost > cost)) {
|
|
@@ -104,10 +101,9 @@ function limitResults(suggestions, numSuggestions, includeTies) {
|
|
|
104
101
|
return suggestions.slice(0, i);
|
|
105
102
|
}
|
|
106
103
|
function validateDictionaries(settings, dictionaries) {
|
|
107
|
-
|
|
108
|
-
if (!(dictionaries === null || dictionaries === void 0 ? void 0 : dictionaries.length))
|
|
104
|
+
if (!dictionaries?.length)
|
|
109
105
|
return;
|
|
110
|
-
const knownDicts = new Set(
|
|
106
|
+
const knownDicts = new Set(settings.dictionaryDefinitions?.map((def) => def.name) || []);
|
|
111
107
|
for (const dict of dictionaries) {
|
|
112
108
|
if (!knownDicts.has(dict)) {
|
|
113
109
|
throw new SuggestionError(`Unknown dictionary: "${dict}"`, 'E_dictionary_unknown');
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { MappedText, TextOffset as TextOffsetRW } from '@cspell/cspell-types';
|
|
2
|
+
export declare type TextOffsetRO = Readonly<TextOffsetRW>;
|
|
3
|
+
export interface ValidationOptions extends IncludeExcludeOptions {
|
|
4
|
+
maxNumberOfProblems?: number;
|
|
5
|
+
maxDuplicateProblems?: number;
|
|
6
|
+
minWordLength?: number;
|
|
7
|
+
flagWords?: string[];
|
|
8
|
+
allowCompoundWords?: boolean;
|
|
9
|
+
/** ignore case when checking words against dictionary or ignore words list */
|
|
10
|
+
ignoreCase: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface CheckOptions extends ValidationOptions {
|
|
13
|
+
allowCompoundWords: boolean;
|
|
14
|
+
ignoreCase: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface IncludeExcludeOptions {
|
|
17
|
+
ignoreRegExpList?: RegExp[];
|
|
18
|
+
includeRegExpList?: RegExp[];
|
|
19
|
+
}
|
|
20
|
+
export interface WordRangeAcc {
|
|
21
|
+
textOffset: TextOffsetRO;
|
|
22
|
+
isIncluded: boolean;
|
|
23
|
+
rangePos: number;
|
|
24
|
+
}
|
|
25
|
+
export interface ValidationResult extends TextOffsetRW {
|
|
26
|
+
line: TextOffsetRW;
|
|
27
|
+
isFlagged?: boolean | undefined;
|
|
28
|
+
isFound?: boolean | undefined;
|
|
29
|
+
}
|
|
30
|
+
export declare type ValidationResultRO = Readonly<ValidationResult>;
|
|
31
|
+
export declare type LineValidator = (line: LineSegment) => Iterable<ValidationResult>;
|
|
32
|
+
export interface LineSegment {
|
|
33
|
+
line: TextOffsetRO;
|
|
34
|
+
segment: TextOffsetRO;
|
|
35
|
+
}
|
|
36
|
+
export interface MappedTextValidationResult extends MappedText {
|
|
37
|
+
isFlagged?: boolean | undefined;
|
|
38
|
+
isFound?: boolean | undefined;
|
|
39
|
+
}
|
|
40
|
+
export declare type TextValidator = (text: MappedText) => Iterable<MappedTextValidationResult>;
|
|
41
|
+
//# sourceMappingURL=ValidationTypes.d.ts.map
|
|
@@ -41,11 +41,10 @@ const TextDocumentSettings_1 = require("../Settings/TextDocumentSettings");
|
|
|
41
41
|
* @param settings - The near final settings. Should already be the combination of all configuration files.
|
|
42
42
|
*/
|
|
43
43
|
function determineTextDocumentSettings(doc, settings) {
|
|
44
|
-
var _a, _b;
|
|
45
44
|
const filename = doc.uri.fsPath;
|
|
46
|
-
const settingsWithDefaults = (0, Settings_1.mergeSettings)((0, Settings_1.getDefaultSettings)(
|
|
45
|
+
const settingsWithDefaults = (0, Settings_1.mergeSettings)((0, Settings_1.getDefaultSettings)(settings.loadDefaultConfiguration ?? true), (0, Settings_1.getGlobalSettings)(), settings);
|
|
47
46
|
const fileSettings = (0, Settings_1.calcOverrideSettings)(settingsWithDefaults, filename);
|
|
48
|
-
const languageIds =
|
|
47
|
+
const languageIds = fileSettings?.languageId?.length
|
|
49
48
|
? fileSettings.languageId
|
|
50
49
|
: doc.languageId
|
|
51
50
|
? doc.languageId
|