cspell-lib 5.19.0 → 5.19.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/Models/CSpellSettingsInternalDef.d.ts +5 -0
- package/dist/Models/TextDocument.d.ts +9 -0
- package/dist/Models/TextDocument.js +36 -3
- package/dist/Settings/CSpellSettingsServer.d.ts +3 -3
- package/dist/Settings/CSpellSettingsServer.js +11 -10
- package/dist/Settings/DictionarySettings.d.ts +5 -3
- package/dist/Settings/DictionarySettings.js +19 -19
- package/dist/Settings/LanguageSettings.d.ts +2 -2
- package/dist/Settings/LanguageSettings.js +37 -27
- package/dist/Settings/patterns.d.ts +1 -1
- package/dist/Settings/patterns.js +5 -1
- package/dist/SpellingDictionary/Dictionaries.js +2 -2
- package/dist/SpellingDictionary/DictionaryLoader.d.ts +2 -2
- package/dist/SpellingDictionary/DictionaryLoader.js +34 -30
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/dist/textValidation/docValidator.d.ts +10 -0
- package/dist/textValidation/docValidator.js +84 -21
- package/dist/textValidation/textValidator.d.ts +2 -2
- package/dist/textValidation/textValidator.js +1 -1
- package/dist/textValidation/validator.d.ts +2 -1
- package/dist/textValidation/validator.js +5 -2
- package/dist/trace.js +2 -1
- package/dist/util/Memorizer.d.ts +8 -0
- package/dist/util/Memorizer.js +59 -1
- package/dist/util/TextRange.d.ts +2 -2
- package/dist/util/TextRange.js +8 -18
- package/dist/util/debugPerf.d.ts +9 -0
- package/dist/util/debugPerf.js +22 -0
- package/dist/util/simpleCache.d.ts +4 -2
- package/dist/util/simpleCache.js +18 -15
- package/dist/util/timer.d.ts +26 -0
- package/dist/util/timer.js +58 -0
- package/dist/util/util.d.ts +7 -0
- package/dist/util/util.js +18 -1
- package/package.json +10 -10
|
@@ -6,6 +6,11 @@ export interface CSpellSettingsInternal extends Omit<CSpellSettingsWithSourceTra
|
|
|
6
6
|
[SymbolCSpellSettingsInternal]: true;
|
|
7
7
|
dictionaryDefinitions?: DictionaryDefinitionInternal[];
|
|
8
8
|
}
|
|
9
|
+
export interface CSpellSettingsInternalFinalized extends CSpellSettingsInternal {
|
|
10
|
+
finalized: true;
|
|
11
|
+
ignoreRegExpList: RegExp[];
|
|
12
|
+
includeRegExpList: RegExp[];
|
|
13
|
+
}
|
|
9
14
|
declare type DictionaryDefinitionCustomUniqueFields = Omit<DictionaryDefinitionCustom, keyof DictionaryDefinitionPreferred>;
|
|
10
15
|
export interface DictionaryDefinitionInternal extends Readonly<DictionaryDefinitionPreferred>, Readonly<Partial<DictionaryDefinitionCustomUniqueFields>>, Readonly<DictionaryDefinitionAugmented> {
|
|
11
16
|
/**
|
|
@@ -4,6 +4,10 @@ export interface Position {
|
|
|
4
4
|
line: number;
|
|
5
5
|
character: number;
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Range offset tuple.
|
|
9
|
+
*/
|
|
10
|
+
export declare type SimpleRange = [start: number, end: number];
|
|
7
11
|
export interface TextDocumentLine {
|
|
8
12
|
readonly text: string;
|
|
9
13
|
readonly offset: number;
|
|
@@ -48,5 +52,10 @@ export interface CreateTextDocumentParams {
|
|
|
48
52
|
locale?: string | undefined;
|
|
49
53
|
version?: number | undefined;
|
|
50
54
|
}
|
|
55
|
+
export interface TextDocumentContentChangeEvent {
|
|
56
|
+
range?: SimpleRange;
|
|
57
|
+
text: string;
|
|
58
|
+
}
|
|
51
59
|
export declare function createTextDocument({ uri, content, languageId, locale, version, }: CreateTextDocumentParams): TextDocument;
|
|
60
|
+
export declare function updateTextDocument(doc: TextDocument, edits: TextDocumentContentChangeEvent[], version?: number): TextDocument;
|
|
52
61
|
//# sourceMappingURL=TextDocument.d.ts.map
|
|
@@ -22,21 +22,29 @@ 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
|
-
exports.createTextDocument = void 0;
|
|
29
|
+
exports.updateTextDocument = exports.createTextDocument = void 0;
|
|
27
30
|
const LanguageIds_1 = require("../LanguageIds");
|
|
28
31
|
const Uri = __importStar(require("./Uri"));
|
|
29
32
|
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
|
33
|
+
const assert_1 = __importDefault(require("assert"));
|
|
30
34
|
class TextDocumentImpl {
|
|
31
35
|
constructor(uri, text, languageId, locale, version) {
|
|
32
36
|
this.uri = uri;
|
|
33
|
-
this.text = text;
|
|
34
37
|
this.languageId = languageId;
|
|
35
38
|
this.locale = locale;
|
|
36
|
-
this.version = version;
|
|
37
39
|
const primaryLanguageId = typeof languageId === 'string' ? languageId : languageId[0] || 'plaintext';
|
|
38
40
|
this.vsTextDoc = vscode_languageserver_textdocument_1.TextDocument.create(uri.toString(), primaryLanguageId, version, text);
|
|
39
41
|
}
|
|
42
|
+
get version() {
|
|
43
|
+
return this.vsTextDoc.version;
|
|
44
|
+
}
|
|
45
|
+
get text() {
|
|
46
|
+
return this.vsTextDoc.getText();
|
|
47
|
+
}
|
|
40
48
|
positionAt(offset) {
|
|
41
49
|
return this.vsTextDoc.positionAt(offset);
|
|
42
50
|
}
|
|
@@ -61,6 +69,26 @@ class TextDocumentImpl {
|
|
|
61
69
|
position,
|
|
62
70
|
};
|
|
63
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Apply edits to the text.
|
|
74
|
+
* Note: the edits are applied one after the other.
|
|
75
|
+
* @param edits - changes to the text
|
|
76
|
+
* @param version - optional version to use.
|
|
77
|
+
* @returns this
|
|
78
|
+
*/
|
|
79
|
+
update(edits, version) {
|
|
80
|
+
version = version !== null && version !== void 0 ? version : this.version + 1;
|
|
81
|
+
for (const edit of edits) {
|
|
82
|
+
const vsEdit = edit.range
|
|
83
|
+
? {
|
|
84
|
+
range: { start: this.positionAt(edit.range[0]), end: this.positionAt(edit.range[1]) },
|
|
85
|
+
text: edit.text,
|
|
86
|
+
}
|
|
87
|
+
: edit;
|
|
88
|
+
vscode_languageserver_textdocument_1.TextDocument.update(this.vsTextDoc, [vsEdit], version);
|
|
89
|
+
}
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
64
92
|
}
|
|
65
93
|
function createTextDocument({ uri, content, languageId, locale, version, }) {
|
|
66
94
|
version = version !== null && version !== void 0 ? version : 1;
|
|
@@ -70,4 +98,9 @@ function createTextDocument({ uri, content, languageId, locale, version, }) {
|
|
|
70
98
|
return new TextDocumentImpl(uri, content, languageId, locale, version);
|
|
71
99
|
}
|
|
72
100
|
exports.createTextDocument = createTextDocument;
|
|
101
|
+
function updateTextDocument(doc, edits, version) {
|
|
102
|
+
(0, assert_1.default)(doc instanceof TextDocumentImpl, 'Unknown TextDocument type');
|
|
103
|
+
return doc.update(edits, version);
|
|
104
|
+
}
|
|
105
|
+
exports.updateTextDocument = updateTextDocument;
|
|
73
106
|
//# sourceMappingURL=TextDocument.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CSpellSettingsWithSourceTrace, Glob, ImportFileRef } from '@cspell/cspell-types';
|
|
2
|
-
import { CSpellSettingsInternal } from '../Models/CSpellSettingsInternalDef';
|
|
2
|
+
import { CSpellSettingsInternal, CSpellSettingsInternalFinalized } from '../Models/CSpellSettingsInternalDef';
|
|
3
3
|
import { OptionalOrUndefined } from '../util/types';
|
|
4
4
|
declare type CSpellSettingsWST = CSpellSettingsWithSourceTrace;
|
|
5
5
|
declare type CSpellSettingsWSTO = OptionalOrUndefined<CSpellSettingsWithSourceTrace>;
|
|
@@ -12,7 +12,7 @@ declare function mergeObjects(left: undefined, right: undefined): undefined;
|
|
|
12
12
|
declare function mergeObjects<T>(left: T, right: undefined): T;
|
|
13
13
|
declare function mergeObjects<T>(left: T, right: T): T;
|
|
14
14
|
declare function mergeObjects<T>(left: undefined, right: T): T;
|
|
15
|
-
export declare function mergeSettings(left: CSpellSettingsWSTO | CSpellSettingsI, ...settings: (CSpellSettingsWSTO | CSpellSettingsI)[]): CSpellSettingsI;
|
|
15
|
+
export declare function mergeSettings(left: CSpellSettingsWSTO | CSpellSettingsI, ...settings: (CSpellSettingsWSTO | CSpellSettingsI | undefined)[]): CSpellSettingsI;
|
|
16
16
|
export declare function mergeInDocSettings(left: CSpellSettingsWSTO, right: CSpellSettingsWSTO): CSpellSettingsWST;
|
|
17
17
|
export declare function calcOverrideSettings(settings: CSpellSettingsWSTO, filename: string): CSpellSettingsI;
|
|
18
18
|
/**
|
|
@@ -20,7 +20,7 @@ export declare function calcOverrideSettings(settings: CSpellSettingsWSTO, filen
|
|
|
20
20
|
* @param settings - settings to finalize
|
|
21
21
|
* @returns settings where all globs and file paths have been resolved.
|
|
22
22
|
*/
|
|
23
|
-
export declare function finalizeSettings(settings: CSpellSettingsWSTO | CSpellSettingsI):
|
|
23
|
+
export declare function finalizeSettings(settings: CSpellSettingsWSTO | CSpellSettingsI): CSpellSettingsInternalFinalized;
|
|
24
24
|
export declare function toInternalSettings(settings: undefined): undefined;
|
|
25
25
|
export declare function toInternalSettings(settings: CSpellSettingsI | CSpellSettingsWSTO): CSpellSettingsI;
|
|
26
26
|
export declare function toInternalSettings(settings?: CSpellSettingsI | CSpellSettingsWSTO): CSpellSettingsI | undefined;
|
|
@@ -34,13 +34,19 @@ exports.configSettingsFileVersion0_1 = '0.1';
|
|
|
34
34
|
exports.configSettingsFileVersion0_2 = '0.2';
|
|
35
35
|
exports.currentSettingsFileVersion = exports.configSettingsFileVersion0_2;
|
|
36
36
|
exports.ENV_CSPELL_GLOB_ROOT = 'CSPELL_GLOB_ROOT';
|
|
37
|
+
function _unique(a) {
|
|
38
|
+
return [...new Set(a)];
|
|
39
|
+
}
|
|
37
40
|
function mergeListUnique(left, right) {
|
|
38
41
|
if (left === undefined)
|
|
39
42
|
return right;
|
|
40
43
|
if (right === undefined)
|
|
41
44
|
return left;
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
if (!right.length)
|
|
46
|
+
return left;
|
|
47
|
+
if (!left.length)
|
|
48
|
+
return right;
|
|
49
|
+
return _unique([...left, ...right]);
|
|
44
50
|
}
|
|
45
51
|
function mergeList(left, right) {
|
|
46
52
|
if (left === undefined)
|
|
@@ -73,12 +79,6 @@ function mergeObjects(left, right) {
|
|
|
73
79
|
return left;
|
|
74
80
|
return { ...left, ...right };
|
|
75
81
|
}
|
|
76
|
-
function tagLanguageSettings(tag, settings = []) {
|
|
77
|
-
return settings.map((s) => ({
|
|
78
|
-
id: tag + '.' + (s.id || s.locale || s.languageId),
|
|
79
|
-
...s,
|
|
80
|
-
}));
|
|
81
|
-
}
|
|
82
82
|
function replaceIfNotEmpty(left = [], right = []) {
|
|
83
83
|
const filtered = right.filter((a) => !!a);
|
|
84
84
|
if (filtered.length) {
|
|
@@ -87,7 +87,7 @@ function replaceIfNotEmpty(left = [], right = []) {
|
|
|
87
87
|
return left;
|
|
88
88
|
}
|
|
89
89
|
function mergeSettings(left, ...settings) {
|
|
90
|
-
const rawSettings = settings.reduce(merge, toInternalSettings(left));
|
|
90
|
+
const rawSettings = settings.filter((a) => !!a).reduce(merge, toInternalSettings(left));
|
|
91
91
|
return util.clean(rawSettings);
|
|
92
92
|
}
|
|
93
93
|
exports.mergeSettings = mergeSettings;
|
|
@@ -136,7 +136,7 @@ function merge(left, right) {
|
|
|
136
136
|
dictionaryDefinitions: mergeListUnique(_left.dictionaryDefinitions, _right.dictionaryDefinitions),
|
|
137
137
|
dictionaries: mergeListUnique(_left.dictionaries, _right.dictionaries),
|
|
138
138
|
noSuggestDictionaries: mergeListUnique(_left.noSuggestDictionaries, _right.noSuggestDictionaries),
|
|
139
|
-
languageSettings: mergeList(
|
|
139
|
+
languageSettings: mergeList(_left.languageSettings, _right.languageSettings),
|
|
140
140
|
enabled: _right.enabled !== undefined ? _right.enabled : _left.enabled,
|
|
141
141
|
files: mergeListUnique(_left.files, _right.files),
|
|
142
142
|
ignorePaths: versionBasedMergeList(_left.ignorePaths, _right.ignorePaths, version),
|
|
@@ -221,6 +221,7 @@ function _finalizeSettings(settings) {
|
|
|
221
221
|
// apply patterns to any RegExpLists.
|
|
222
222
|
const finalized = {
|
|
223
223
|
...settings,
|
|
224
|
+
finalized: true,
|
|
224
225
|
ignoreRegExpList: (0, patterns_1.resolvePatterns)(settings.ignoreRegExpList, settings.patterns),
|
|
225
226
|
includeRegExpList: (0, patterns_1.resolvePatterns)(settings.includeRegExpList, settings.patterns),
|
|
226
227
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { DictionaryDefinition
|
|
1
|
+
import type { DictionaryDefinition } from '@cspell/cspell-types';
|
|
2
2
|
import { CSpellSettingsInternal, DictionaryDefinitionInternal, DictionaryDefinitionInternalWithSource } from '../Models/CSpellSettingsInternalDef';
|
|
3
|
+
import { DictionaryReferenceCollection } from './DictionaryReferenceCollection';
|
|
3
4
|
export declare type DefMapArrayItem = [string, DictionaryDefinitionInternal];
|
|
4
5
|
/**
|
|
5
6
|
* Combines the list of desired dictionaries with the list of dictionary
|
|
@@ -9,15 +10,16 @@ export declare type DefMapArrayItem = [string, DictionaryDefinitionInternal];
|
|
|
9
10
|
* - Adding `!` to a dictId will remove the dictionary.
|
|
10
11
|
* - Adding `!!` will add it back.
|
|
11
12
|
*
|
|
12
|
-
* @param
|
|
13
|
+
* @param dictRefCol - dictionaries desired
|
|
13
14
|
* @param defs - dictionary definitions
|
|
14
15
|
* @returns map from dictIds to definitions
|
|
15
16
|
*/
|
|
16
|
-
export declare function filterDictDefsToLoad(
|
|
17
|
+
export declare function filterDictDefsToLoad(dictRefCol: DictionaryReferenceCollection, defs: DictionaryDefinitionInternal[]): DictionaryDefinitionInternal[];
|
|
17
18
|
export declare function mapDictDefsToInternal(defs: undefined, pathToSettingsFile: string): undefined;
|
|
18
19
|
export declare function mapDictDefsToInternal(defs: DictionaryDefinition[], pathToSettingsFile: string): DictionaryDefinitionInternalWithSource[];
|
|
19
20
|
export declare function mapDictDefsToInternal(defs: DictionaryDefinition[] | undefined, pathToSettingsFile: string): DictionaryDefinitionInternalWithSource[] | undefined;
|
|
20
21
|
export declare function mapDictDefToInternal(def: DictionaryDefinition, pathToSettingsFile: string): DictionaryDefinitionInternalWithSource;
|
|
21
22
|
export declare function isDictionaryDefinitionWithSource(d: DictionaryDefinition | DictionaryDefinitionInternalWithSource): d is DictionaryDefinitionInternalWithSource;
|
|
22
23
|
export declare function calcDictionaryDefsToLoad(settings: CSpellSettingsInternal): DictionaryDefinitionInternal[];
|
|
24
|
+
export declare function isDictionaryDefinitionInternal(def: DictionaryDefinition | DictionaryDefinitionInternal): def is DictionaryDefinitionInternal;
|
|
23
25
|
//# sourceMappingURL=DictionarySettings.d.ts.map
|
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.calcDictionaryDefsToLoad = exports.isDictionaryDefinitionWithSource = exports.mapDictDefToInternal = exports.mapDictDefsToInternal = exports.filterDictDefsToLoad = void 0;
|
|
26
|
+
exports.isDictionaryDefinitionInternal = exports.calcDictionaryDefsToLoad = exports.isDictionaryDefinitionWithSource = exports.mapDictDefToInternal = exports.mapDictDefsToInternal = exports.filterDictDefsToLoad = void 0;
|
|
27
27
|
const path = __importStar(require("path"));
|
|
28
28
|
const resolveFile_1 = require("../util/resolveFile");
|
|
29
29
|
const DictionaryReferenceCollection_1 = require("./DictionaryReferenceCollection");
|
|
@@ -37,30 +37,26 @@ const util_1 = require("../util/util");
|
|
|
37
37
|
* - Adding `!` to a dictId will remove the dictionary.
|
|
38
38
|
* - Adding `!!` will add it back.
|
|
39
39
|
*
|
|
40
|
-
* @param
|
|
40
|
+
* @param dictRefCol - dictionaries desired
|
|
41
41
|
* @param defs - dictionary definitions
|
|
42
42
|
* @returns map from dictIds to definitions
|
|
43
43
|
*/
|
|
44
|
-
function filterDictDefsToLoad(
|
|
45
|
-
|
|
46
|
-
return !!def.path;
|
|
47
|
-
}
|
|
48
|
-
const col = (0, DictionaryReferenceCollection_1.createDictionaryReferenceCollection)(dictRefIds);
|
|
49
|
-
const dictIdSet = new Set(col.enabled());
|
|
50
|
-
const allActiveDefs = defs
|
|
51
|
-
.filter(({ name }) => dictIdSet.has(name))
|
|
52
|
-
.map((def) => ({ ...def, path: getFullPathName(def) }))
|
|
53
|
-
// Remove any empty paths.
|
|
54
|
-
.filter(isDefP);
|
|
44
|
+
function filterDictDefsToLoad(dictRefCol, defs) {
|
|
45
|
+
const allActiveDefs = defs.filter(({ name }) => dictRefCol.isEnabled(name)).map(fixPath);
|
|
55
46
|
return [...new Map(allActiveDefs.map((d) => [d.name, d])).values()];
|
|
56
47
|
}
|
|
57
48
|
exports.filterDictDefsToLoad = filterDictDefsToLoad;
|
|
58
|
-
function
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return '';
|
|
49
|
+
function fixPath(def) {
|
|
50
|
+
if (def instanceof _DictionaryDefinitionInternalWithSource) {
|
|
51
|
+
return def;
|
|
62
52
|
}
|
|
63
|
-
|
|
53
|
+
const { path: filePath = '', file = '' } = def;
|
|
54
|
+
const newPath = !filePath && !file ? '' : path.join(filePath, file);
|
|
55
|
+
return {
|
|
56
|
+
...def,
|
|
57
|
+
file: undefined,
|
|
58
|
+
path: newPath,
|
|
59
|
+
};
|
|
64
60
|
}
|
|
65
61
|
function mapDictDefsToInternal(defs, pathToSettingsFile) {
|
|
66
62
|
return defs === null || defs === void 0 ? void 0 : defs.map((def) => mapDictDefToInternal(def, pathToSettingsFile));
|
|
@@ -93,9 +89,13 @@ function calcDictionaryDefsToLoad(settings) {
|
|
|
93
89
|
return def;
|
|
94
90
|
return { ...def, noSuggest: enabled };
|
|
95
91
|
});
|
|
96
|
-
return filterDictDefsToLoad(colDicts
|
|
92
|
+
return filterDictDefsToLoad(colDicts, modDefs);
|
|
97
93
|
}
|
|
98
94
|
exports.calcDictionaryDefsToLoad = calcDictionaryDefsToLoad;
|
|
95
|
+
function isDictionaryDefinitionInternal(def) {
|
|
96
|
+
return def instanceof _DictionaryDefinitionInternalWithSource;
|
|
97
|
+
}
|
|
98
|
+
exports.isDictionaryDefinitionInternal = isDictionaryDefinitionInternal;
|
|
99
99
|
class _DictionaryDefinitionInternalWithSource {
|
|
100
100
|
constructor(def, __source) {
|
|
101
101
|
this.__source = __source;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BaseSetting, CSpellUserSettings, LanguageId, LanguageSetting, LocaleId } from '@cspell/cspell-types';
|
|
2
2
|
export declare type LanguageSettings = LanguageSetting[];
|
|
3
3
|
export declare function getDefaultLanguageSettings(): LanguageSettings;
|
|
4
4
|
export declare function normalizeLanguageId(langId: LanguageId | LanguageId[]): Set<LanguageId>;
|
|
5
5
|
export declare function normalizeLocale(locale: LocaleId | LocaleId[]): Set<LocaleId>;
|
|
6
6
|
export declare function isLocaleInSet(locale: LocaleId | LocaleId[], setOfLocals: Set<LocaleId>): boolean;
|
|
7
|
-
export declare function calcSettingsForLanguage(languageSettings: LanguageSettings, languageId: LanguageId, locale: LocaleId
|
|
7
|
+
export declare function calcSettingsForLanguage(languageSettings: LanguageSettings, languageId: LanguageId, locale: LocaleId): BaseSetting;
|
|
8
8
|
export declare function calcUserSettingsForLanguage(settings: CSpellUserSettings, languageId: string): CSpellUserSettings;
|
|
9
9
|
export declare function calcSettingsForLanguageId(baseSettings: CSpellUserSettings, languageId: LanguageId[] | LanguageId): CSpellUserSettings;
|
|
10
10
|
//# sourceMappingURL=LanguageSettings.d.ts.map
|
|
@@ -24,6 +24,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.calcSettingsForLanguageId = exports.calcUserSettingsForLanguage = exports.calcSettingsForLanguage = exports.isLocaleInSet = exports.normalizeLocale = exports.normalizeLanguageId = exports.getDefaultLanguageSettings = void 0;
|
|
27
|
+
const Memorizer_1 = require("../util/Memorizer");
|
|
28
|
+
const util_1 = require("../util/util");
|
|
27
29
|
const SpellSettings = __importStar(require("./CSpellSettingsServer"));
|
|
28
30
|
const defaultLocale = 'en';
|
|
29
31
|
const defaultLanguageSettings = [];
|
|
@@ -32,58 +34,69 @@ function getDefaultLanguageSettings() {
|
|
|
32
34
|
}
|
|
33
35
|
exports.getDefaultLanguageSettings = getDefaultLanguageSettings;
|
|
34
36
|
function localesToList(locales) {
|
|
35
|
-
locales = typeof locales !== 'string' ? locales.join(',') : locales;
|
|
36
37
|
return stringToList(locales.replace(/\s+/g, ','));
|
|
37
38
|
}
|
|
38
39
|
function stringToList(sList) {
|
|
39
|
-
|
|
40
|
-
sList = sList.join(',');
|
|
41
|
-
}
|
|
42
|
-
sList = sList
|
|
40
|
+
return sList
|
|
43
41
|
.replace(/[|;]/g, ',')
|
|
44
42
|
.split(',')
|
|
45
43
|
.map((s) => s.trim())
|
|
46
44
|
.filter((s) => !!s);
|
|
47
|
-
return sList;
|
|
48
45
|
}
|
|
49
|
-
|
|
46
|
+
const _normalizeLanguageId = (0, Memorizer_1.memorizerAll)(__normalizeLanguageId);
|
|
47
|
+
function __normalizeLanguageId(langId) {
|
|
50
48
|
const langIds = stringToList(langId);
|
|
51
49
|
return new Set(langIds.map((a) => a.toLowerCase()));
|
|
52
50
|
}
|
|
51
|
+
function normalizeLanguageId(langId) {
|
|
52
|
+
return _normalizeLanguageId(typeof langId === 'string' ? langId : langId.join(','));
|
|
53
|
+
}
|
|
53
54
|
exports.normalizeLanguageId = normalizeLanguageId;
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
const _normalizeLocale = (0, Memorizer_1.memorizerAll)(__normalizeLocale);
|
|
56
|
+
function __normalizeLocale(locale) {
|
|
57
|
+
const locales = localesToList(locale);
|
|
58
|
+
return new Set(locales.map((locale) => locale.toLowerCase().replace(/[^a-z]/g, '')));
|
|
56
59
|
}
|
|
57
60
|
function normalizeLocale(locale) {
|
|
58
|
-
locale =
|
|
59
|
-
return
|
|
61
|
+
locale = typeof locale === 'string' ? locale : locale.join(',');
|
|
62
|
+
return _normalizeLocale(locale);
|
|
60
63
|
}
|
|
61
64
|
exports.normalizeLocale = normalizeLocale;
|
|
62
65
|
function isLocaleInSet(locale, setOfLocals) {
|
|
63
66
|
const locales = normalizeLocale(locale);
|
|
64
|
-
return
|
|
67
|
+
return (0, util_1.doSetsIntersect)(locales, setOfLocals);
|
|
65
68
|
}
|
|
66
69
|
exports.isLocaleInSet = isLocaleInSet;
|
|
67
70
|
function calcSettingsForLanguage(languageSettings, languageId, locale) {
|
|
68
71
|
languageId = languageId.toLowerCase();
|
|
69
72
|
const allowedLocals = normalizeLocale(locale);
|
|
70
|
-
|
|
71
|
-
.concat(languageSettings)
|
|
73
|
+
const ls = languageSettings
|
|
72
74
|
.filter((s) => doesLanguageSettingMatchLanguageId(s, languageId))
|
|
73
75
|
.filter((s) => !s.locale || s.locale === '*' || isLocaleInSet(s.locale, allowedLocals))
|
|
74
76
|
.map((langSetting) => {
|
|
75
|
-
const
|
|
76
|
-
const { languageId: _languageId, locale: _local, ...s } = { id, ...langSetting };
|
|
77
|
+
const { languageId: _languageId, locale: _locale, ...s } = langSetting;
|
|
77
78
|
return s;
|
|
78
79
|
})
|
|
79
|
-
.reduce((langSetting, setting) => ({
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}), {});
|
|
80
|
+
.reduce((langSetting, setting) => SpellSettings.mergeSettings(langSetting, setting), {});
|
|
81
|
+
ls.languageId = languageId;
|
|
82
|
+
ls.locale = locale;
|
|
83
|
+
return ls;
|
|
84
84
|
}
|
|
85
85
|
exports.calcSettingsForLanguage = calcSettingsForLanguage;
|
|
86
|
+
const cacheDoesLanguageSettingMatchLanguageId = new WeakMap();
|
|
86
87
|
function doesLanguageSettingMatchLanguageId(s, languageId) {
|
|
88
|
+
var _a;
|
|
89
|
+
const r = (_a = cacheDoesLanguageSettingMatchLanguageId.get(s)) !== null && _a !== void 0 ? _a : new Map();
|
|
90
|
+
const f = r.get(languageId);
|
|
91
|
+
if (f !== undefined) {
|
|
92
|
+
return f;
|
|
93
|
+
}
|
|
94
|
+
const v = _doesLanguageSettingMatchLanguageId(s, languageId);
|
|
95
|
+
r.set(languageId, v);
|
|
96
|
+
cacheDoesLanguageSettingMatchLanguageId.set(s, r);
|
|
97
|
+
return v;
|
|
98
|
+
}
|
|
99
|
+
function _doesLanguageSettingMatchLanguageId(s, languageId) {
|
|
87
100
|
const languageSettingsLanguageIds = s.languageId;
|
|
88
101
|
if (!languageSettingsLanguageIds || languageSettingsLanguageIds === '*')
|
|
89
102
|
return true;
|
|
@@ -96,13 +109,10 @@ function doesLanguageSettingMatchLanguageId(s, languageId) {
|
|
|
96
109
|
return numExcludes === ids.size;
|
|
97
110
|
}
|
|
98
111
|
function calcUserSettingsForLanguage(settings, languageId) {
|
|
99
|
-
const { languageSettings = [], language: locale = defaultLocale } = settings;
|
|
100
|
-
const defaults = {
|
|
101
|
-
allowCompoundWords: settings.allowCompoundWords,
|
|
102
|
-
enabled: settings.enabled,
|
|
103
|
-
};
|
|
112
|
+
const { languageSettings = [], language: locale = defaultLocale, allowCompoundWords, enabled } = settings;
|
|
104
113
|
const langSettings = {
|
|
105
|
-
|
|
114
|
+
allowCompoundWords,
|
|
115
|
+
enabled,
|
|
106
116
|
...calcSettingsForLanguage(languageSettings, languageId, locale),
|
|
107
117
|
};
|
|
108
118
|
return SpellSettings.mergeSettings(settings, langSettings);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { RegExpPatternDefinition } from '@cspell/cspell-types';
|
|
2
|
-
export declare function resolvePatterns(regExpList?: (string | RegExp)[], patternDefinitions?: RegExpPatternDefinition[]):
|
|
2
|
+
export declare function resolvePatterns(regExpList?: (string | RegExp)[], patternDefinitions?: RegExpPatternDefinition[]): RegExp[];
|
|
3
3
|
//# sourceMappingURL=patterns.d.ts.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resolvePatterns = void 0;
|
|
4
|
+
const text_1 = require("../util/text");
|
|
4
5
|
const util_1 = require("../util/util");
|
|
5
6
|
function resolvePatterns(regExpList = [], patternDefinitions = []) {
|
|
6
7
|
const patternMap = new Map(patternDefinitions.map((def) => [def.name.toLowerCase(), def.pattern]));
|
|
@@ -22,7 +23,10 @@ function resolvePatterns(regExpList = [], patternDefinitions = []) {
|
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
const patternList = regExpList.map(resolvePattern).filter(util_1.isDefined);
|
|
25
|
-
return [...flatten(patternList)];
|
|
26
|
+
return [...flatten(patternList)].map(toRegExp).filter(util_1.isDefined);
|
|
26
27
|
}
|
|
27
28
|
exports.resolvePatterns = resolvePatterns;
|
|
29
|
+
function toRegExp(pattern) {
|
|
30
|
+
return pattern instanceof RegExp ? new RegExp(pattern) : (0, text_1.stringToRegExp)(pattern, 'gim', 'g');
|
|
31
|
+
}
|
|
28
32
|
//# sourceMappingURL=patterns.js.map
|
|
@@ -7,11 +7,11 @@ const createSpellingDictionary_1 = require("./createSpellingDictionary");
|
|
|
7
7
|
const DictionaryLoader_1 = require("./DictionaryLoader");
|
|
8
8
|
const SpellingDictionaryCollection_1 = require("./SpellingDictionaryCollection");
|
|
9
9
|
function loadDictionaryDefs(defsToLoad) {
|
|
10
|
-
return defsToLoad.map(
|
|
10
|
+
return defsToLoad.map(DictionaryLoader_1.loadDictionary);
|
|
11
11
|
}
|
|
12
12
|
exports.loadDictionaryDefs = loadDictionaryDefs;
|
|
13
13
|
function loadDictionaryDefsSync(defsToLoad) {
|
|
14
|
-
return defsToLoad.map(
|
|
14
|
+
return defsToLoad.map(DictionaryLoader_1.loadDictionarySync);
|
|
15
15
|
}
|
|
16
16
|
exports.loadDictionaryDefsSync = loadDictionaryDefsSync;
|
|
17
17
|
function refreshDictionaryCache(maxAge) {
|
|
@@ -32,8 +32,8 @@ export interface SyncLoaders {
|
|
|
32
32
|
W: LoaderSync;
|
|
33
33
|
default: LoaderSync;
|
|
34
34
|
}
|
|
35
|
-
export declare function loadDictionary(
|
|
36
|
-
export declare function loadDictionarySync(
|
|
35
|
+
export declare function loadDictionary(def: DictionaryDefinitionInternal): Promise<SpellingDictionary>;
|
|
36
|
+
export declare function loadDictionarySync(def: DictionaryDefinitionInternal): SpellingDictionary;
|
|
37
37
|
/**
|
|
38
38
|
* Check to see if any of the cached dictionaries have changed. If one has changed, reload it.
|
|
39
39
|
* @param maxAge - Only check the dictionary if it has been at least `maxAge` ms since the last check.
|
|
@@ -59,49 +59,50 @@ function __log(msg) {
|
|
|
59
59
|
debugMode && debugLog.push(msg);
|
|
60
60
|
}
|
|
61
61
|
const dictionaryCache = new Map();
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
const dictionaryCacheByDef = new Map();
|
|
63
|
+
function getCacheEntry(def) {
|
|
64
|
+
const defEntry = dictionaryCacheByDef.get(def);
|
|
65
|
+
if (defEntry) {
|
|
66
|
+
return defEntry;
|
|
67
|
+
}
|
|
68
|
+
const key = calcKey(def);
|
|
64
69
|
const entry = dictionaryCache.get(key);
|
|
70
|
+
if (entry) {
|
|
71
|
+
// replace old entry so it can be released.
|
|
72
|
+
entry.options = def;
|
|
73
|
+
}
|
|
74
|
+
return { key, entry };
|
|
75
|
+
}
|
|
76
|
+
function setCacheEntry(key, entry, def) {
|
|
77
|
+
dictionaryCache.set(key, entry);
|
|
78
|
+
dictionaryCacheByDef.set(def, { key, entry });
|
|
79
|
+
}
|
|
80
|
+
function loadDictionary(def) {
|
|
81
|
+
const { key, entry } = getCacheEntry(def);
|
|
65
82
|
if (entry) {
|
|
66
83
|
return entry.pending.then(([dictionary]) => dictionary);
|
|
67
84
|
}
|
|
68
|
-
const loadedEntry = loadEntry(
|
|
69
|
-
|
|
85
|
+
const loadedEntry = loadEntry(def.path, def);
|
|
86
|
+
setCacheEntry(key, loadedEntry, def);
|
|
70
87
|
return loadedEntry.pending.then(([dictionary]) => dictionary);
|
|
71
88
|
}
|
|
72
89
|
exports.loadDictionary = loadDictionary;
|
|
73
|
-
function loadDictionarySync(
|
|
74
|
-
const key =
|
|
75
|
-
const entry = dictionaryCache.get(key);
|
|
90
|
+
function loadDictionarySync(def) {
|
|
91
|
+
const { key, entry } = getCacheEntry(def);
|
|
76
92
|
if ((entry === null || entry === void 0 ? void 0 : entry.dictionary) && entry.loadingState === LoadingState.Loaded) {
|
|
77
|
-
// if (entry.options.name === 'temp') {
|
|
78
|
-
// __log(
|
|
79
|
-
// `Cache Found ${entry.options.name}; ts: ${entry.sig.toFixed(2)}; file: ${path.relative(
|
|
80
|
-
// process.cwd(),
|
|
81
|
-
// entry.uri
|
|
82
|
-
// )}`
|
|
83
|
-
// );
|
|
84
|
-
// }
|
|
85
93
|
return entry.dictionary;
|
|
86
94
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
// `Cache Miss ${options.name}; ts: ${entry?.sig.toFixed(2) || Date.now()}; file: ${path.relative(
|
|
90
|
-
// process.cwd(),
|
|
91
|
-
// uri
|
|
92
|
-
// )}`
|
|
93
|
-
// );
|
|
94
|
-
// }
|
|
95
|
-
const loadedEntry = loadEntrySync(uri, options);
|
|
96
|
-
dictionaryCache.set(key, loadedEntry);
|
|
95
|
+
const loadedEntry = loadEntrySync(def.path, def);
|
|
96
|
+
setCacheEntry(key, loadedEntry, def);
|
|
97
97
|
return loadedEntry.dictionary;
|
|
98
98
|
}
|
|
99
99
|
exports.loadDictionarySync = loadDictionarySync;
|
|
100
100
|
const importantOptionKeys = ['name', 'noSuggest', 'useCompounds', 'type'];
|
|
101
|
-
function calcKey(
|
|
102
|
-
const
|
|
103
|
-
const
|
|
104
|
-
const
|
|
101
|
+
function calcKey(def) {
|
|
102
|
+
const path = def.path;
|
|
103
|
+
const loaderType = determineType(path, def);
|
|
104
|
+
const optValues = importantOptionKeys.map((k) => { var _a; return ((_a = def[k]) === null || _a === void 0 ? void 0 : _a.toString()) || ''; });
|
|
105
|
+
const parts = [path, loaderType].concat(optValues);
|
|
105
106
|
return parts.join('|');
|
|
106
107
|
}
|
|
107
108
|
/**
|
|
@@ -136,7 +137,10 @@ async function refreshEntry(entry, maxAge, now) {
|
|
|
136
137
|
// }
|
|
137
138
|
if (sigMatches && hasChanged) {
|
|
138
139
|
entry.loadingState = LoadingState.Loading;
|
|
139
|
-
|
|
140
|
+
const key = calcKey(entry.options);
|
|
141
|
+
const newEntry = loadEntry(entry.uri, entry.options);
|
|
142
|
+
dictionaryCache.set(key, newEntry);
|
|
143
|
+
dictionaryCacheByDef.set(entry.options, { key, entry: newEntry });
|
|
140
144
|
}
|
|
141
145
|
}
|
|
142
146
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export * from '@cspell/cspell-types';
|
|
|
7
7
|
export * from 'cspell-io';
|
|
8
8
|
export { ExcludeFilesGlobMap, ExclusionFunction } from './exclusionHelper';
|
|
9
9
|
export { getLanguagesForExt } from './LanguageIds';
|
|
10
|
-
export { createTextDocument } from './Models/TextDocument';
|
|
10
|
+
export { createTextDocument, updateTextDocument } from './Models/TextDocument';
|
|
11
11
|
export type { CreateTextDocumentParams, TextDocument, TextDocumentLine } from './Models/TextDocument';
|
|
12
12
|
export * from './Settings';
|
|
13
13
|
export { defaultFileName as defaultSettingsFilename } from './Settings';
|
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.checkText = exports.resolveFile = exports.setLogger = exports.getLogger = exports.traceWordsAsync = exports.traceWords = exports.DocumentValidator = exports.suggestionsForWords = exports.suggestionsForWord = exports.SuggestionError = exports.SpellingDictionaryLoadError = exports.SpellingDictionaryCollection = exports.refreshDictionaryCache = exports.isSpellingDictionaryLoadError = exports.createSpellingDictionary = exports.CompoundWordsMethod = exports.spellCheckFile = exports.spellCheckDocument = exports.isBinaryFile = exports.fileToDocument = exports.determineFinalDocumentSettings = exports.constructSettingsForText = exports.combineTextAndLanguageSettings = exports.defaultSettingsFilename = exports.createTextDocument = exports.getLanguagesForExt = void 0;
|
|
29
|
+
exports.getDictionary = exports.clearCachedFiles = exports.ExclusionHelper = exports.Link = exports.Text = exports.validateText = exports.IncludeExcludeFlag = exports.checkText = exports.resolveFile = exports.setLogger = exports.getLogger = exports.traceWordsAsync = exports.traceWords = exports.DocumentValidator = exports.suggestionsForWords = exports.suggestionsForWord = exports.SuggestionError = exports.SpellingDictionaryLoadError = exports.SpellingDictionaryCollection = exports.refreshDictionaryCache = exports.isSpellingDictionaryLoadError = exports.createSpellingDictionary = exports.CompoundWordsMethod = exports.spellCheckFile = exports.spellCheckDocument = exports.isBinaryFile = exports.fileToDocument = exports.determineFinalDocumentSettings = exports.constructSettingsForText = exports.combineTextAndLanguageSettings = exports.defaultSettingsFilename = exports.updateTextDocument = exports.createTextDocument = exports.getLanguagesForExt = void 0;
|
|
30
30
|
const ExclusionHelper = __importStar(require("./exclusionHelper"));
|
|
31
31
|
exports.ExclusionHelper = ExclusionHelper;
|
|
32
32
|
const Settings_1 = require("./Settings");
|
|
@@ -42,6 +42,7 @@ var LanguageIds_1 = require("./LanguageIds");
|
|
|
42
42
|
Object.defineProperty(exports, "getLanguagesForExt", { enumerable: true, get: function () { return LanguageIds_1.getLanguagesForExt; } });
|
|
43
43
|
var TextDocument_1 = require("./Models/TextDocument");
|
|
44
44
|
Object.defineProperty(exports, "createTextDocument", { enumerable: true, get: function () { return TextDocument_1.createTextDocument; } });
|
|
45
|
+
Object.defineProperty(exports, "updateTextDocument", { enumerable: true, get: function () { return TextDocument_1.updateTextDocument; } });
|
|
45
46
|
__exportStar(require("./Settings"), exports);
|
|
46
47
|
var Settings_2 = require("./Settings");
|
|
47
48
|
Object.defineProperty(exports, "defaultSettingsFilename", { enumerable: true, get: function () { return Settings_2.defaultFileName; } });
|
|
@@ -25,6 +25,8 @@ export declare class DocumentValidator {
|
|
|
25
25
|
readonly errors: Error[];
|
|
26
26
|
private _prepared;
|
|
27
27
|
private _preparations;
|
|
28
|
+
private _preparationTime;
|
|
29
|
+
private _suggestions;
|
|
28
30
|
/**
|
|
29
31
|
* @param doc - Document to validate
|
|
30
32
|
* @param config - configuration to use (not finalized).
|
|
@@ -34,11 +36,19 @@ export declare class DocumentValidator {
|
|
|
34
36
|
prepareSync(): void;
|
|
35
37
|
prepare(): Promise<void>;
|
|
36
38
|
private _prepareAsync;
|
|
39
|
+
private _updatePrep;
|
|
40
|
+
/**
|
|
41
|
+
* The amount of time in ms to prepare for validation.
|
|
42
|
+
*/
|
|
43
|
+
get prepTime(): number;
|
|
37
44
|
checkText(range: SimpleRange, _text: string, _scope: string[]): ValidationIssue[];
|
|
38
45
|
get document(): TextDocument;
|
|
46
|
+
updateDocumentText(text: string): void;
|
|
39
47
|
private addPossibleError;
|
|
40
48
|
private catchError;
|
|
41
49
|
private errorCatcherWrapper;
|
|
50
|
+
private suggest;
|
|
51
|
+
private genSuggestions;
|
|
42
52
|
}
|
|
43
53
|
export declare type Offset = number;
|
|
44
54
|
export declare type SimpleRange = readonly [Offset, Offset];
|