cspell-lib 5.19.2 → 5.19.5
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/PatternRegExp.d.ts +5 -0
- package/dist/Models/PatternRegExp.js +13 -0
- package/dist/Models/TextDocument.d.ts +9 -0
- package/dist/Models/TextDocument.js +36 -3
- package/dist/Settings/CSpellSettingsServer.d.ts +1 -1
- package/dist/Settings/CSpellSettingsServer.js +10 -10
- package/dist/Settings/DefaultSettings.d.ts +3 -1
- package/dist/Settings/DefaultSettings.js +44 -20
- package/dist/Settings/DictionarySettings.d.ts +5 -3
- package/dist/Settings/DictionarySettings.js +23 -19
- package/dist/Settings/LanguageSettings.d.ts +2 -2
- package/dist/Settings/LanguageSettings.js +37 -27
- package/dist/Settings/index.d.ts +1 -1
- package/dist/Settings/index.js +2 -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/SpellingDictionary/SpellingDictionaryCollection.js +1 -1
- package/dist/SpellingDictionary/SpellingDictionaryFromTrie.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/dist/suggestions.js +4 -1
- package/dist/textValidation/determineTextDocumentSettings.js +3 -3
- package/dist/textValidation/docValidator.d.ts +5 -0
- package/dist/textValidation/docValidator.js +61 -16
- 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/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 +11 -0
- package/dist/util/timer.js +32 -3
- package/dist/util/util.d.ts +7 -0
- package/dist/util/util.js +18 -1
- package/package.json +11 -11
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PatternRegExp = void 0;
|
|
4
|
+
class PatternRegExp extends RegExp {
|
|
5
|
+
constructor(pattern) {
|
|
6
|
+
super(pattern);
|
|
7
|
+
}
|
|
8
|
+
toJSON() {
|
|
9
|
+
return this.toString();
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.PatternRegExp = PatternRegExp;
|
|
13
|
+
//# sourceMappingURL=PatternRegExp.js.map
|
|
@@ -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
|
|
@@ -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
|
/**
|
|
@@ -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),
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { CSpellSettingsInternal } from '../Models/CSpellSettingsInternalDef';
|
|
2
|
+
export declare const _defaultSettingsBasis: Readonly<CSpellSettingsInternal>;
|
|
2
3
|
export declare const _defaultSettings: Readonly<CSpellSettingsInternal>;
|
|
3
|
-
export declare function getDefaultSettings(): CSpellSettingsInternal;
|
|
4
|
+
export declare function getDefaultSettings(useDefaultDictionaries?: boolean): CSpellSettingsInternal;
|
|
5
|
+
export declare function getDefaultBundledSettings(): CSpellSettingsInternal;
|
|
4
6
|
//# sourceMappingURL=DefaultSettings.d.ts.map
|
|
@@ -23,8 +23,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.getDefaultSettings = exports._defaultSettings = void 0;
|
|
26
|
+
exports.getDefaultBundledSettings = exports.getDefaultSettings = exports._defaultSettings = exports._defaultSettingsBasis = void 0;
|
|
27
27
|
const CSpellSettingsInternalDef_1 = require("../Models/CSpellSettingsInternalDef");
|
|
28
|
+
const PatternRegExp_1 = require("../Models/PatternRegExp");
|
|
28
29
|
const resolveFile_1 = require("../util/resolveFile");
|
|
29
30
|
const configLoader_1 = require("./configLoader");
|
|
30
31
|
const index_1 = require("./index");
|
|
@@ -34,9 +35,9 @@ const defaultConfigFileModuleRef = '@cspell/cspell-bundled-dicts/cspell-default.
|
|
|
34
35
|
// Do not use require.resolve because webpack will mess it up.
|
|
35
36
|
const defaultConfigFile = resolveConfigModule(defaultConfigFileModuleRef);
|
|
36
37
|
const regExpSpellCheckerDisable = [
|
|
37
|
-
RegPat.regExSpellingGuardBlock,
|
|
38
|
-
RegPat.regExSpellingGuardLine,
|
|
39
|
-
RegPat.regExSpellingGuardNext,
|
|
38
|
+
new PatternRegExp_1.PatternRegExp(RegPat.regExSpellingGuardBlock),
|
|
39
|
+
new PatternRegExp_1.PatternRegExp(RegPat.regExSpellingGuardLine),
|
|
40
|
+
new PatternRegExp_1.PatternRegExp(RegPat.regExSpellingGuardNext),
|
|
40
41
|
];
|
|
41
42
|
// cspell:ignore filetypes
|
|
42
43
|
const predefinedPatterns = [
|
|
@@ -71,7 +72,7 @@ const predefinedPatterns = [
|
|
|
71
72
|
{ name: 'CStyleComment', pattern: RegPat.regExCStyleComments },
|
|
72
73
|
{ name: 'Everything', pattern: '.*' },
|
|
73
74
|
];
|
|
74
|
-
const defaultRegExpPatterns = [...predefinedPatterns];
|
|
75
|
+
const defaultRegExpPatterns = [...predefinedPatterns].map(normalizePattern);
|
|
75
76
|
const definedDefaultRegExpExcludeList = [
|
|
76
77
|
'SpellCheckerDisable',
|
|
77
78
|
'SpellCheckerIgnoreInDocSetting',
|
|
@@ -92,11 +93,28 @@ const definedDefaultRegExpExcludeList = [
|
|
|
92
93
|
];
|
|
93
94
|
// This bit of copying is done to have the complier ensure that the defaults exist.
|
|
94
95
|
const defaultRegExpExcludeList = definedDefaultRegExpExcludeList;
|
|
95
|
-
exports.
|
|
96
|
+
exports._defaultSettingsBasis = Object.freeze((0, CSpellSettingsInternalDef_1.createCSpellSettingsInternal)({
|
|
96
97
|
id: 'static_defaults',
|
|
97
98
|
language: 'en',
|
|
98
99
|
name: 'Static Defaults',
|
|
99
100
|
enabled: true,
|
|
101
|
+
enabledLanguageIds: [],
|
|
102
|
+
maxNumberOfProblems: 100,
|
|
103
|
+
numSuggestions: 10,
|
|
104
|
+
suggestionsTimeout: 500,
|
|
105
|
+
suggestionNumChanges: 3,
|
|
106
|
+
words: [],
|
|
107
|
+
userWords: [],
|
|
108
|
+
ignorePaths: [],
|
|
109
|
+
allowCompoundWords: false,
|
|
110
|
+
patterns: defaultRegExpPatterns,
|
|
111
|
+
ignoreRegExpList: [],
|
|
112
|
+
languageSettings: [],
|
|
113
|
+
source: { name: 'defaultSettings' },
|
|
114
|
+
reporters: [],
|
|
115
|
+
}));
|
|
116
|
+
exports._defaultSettings = Object.freeze((0, CSpellSettingsInternalDef_1.createCSpellSettingsInternal)({
|
|
117
|
+
...exports._defaultSettingsBasis,
|
|
100
118
|
enabledLanguageIds: [
|
|
101
119
|
'ada',
|
|
102
120
|
'csharp',
|
|
@@ -123,23 +141,15 @@ exports._defaultSettings = Object.freeze((0, CSpellSettingsInternalDef_1.createC
|
|
|
123
141
|
'shellscript',
|
|
124
142
|
'toml',
|
|
125
143
|
],
|
|
126
|
-
maxNumberOfProblems: 100,
|
|
127
|
-
numSuggestions: 10,
|
|
128
|
-
suggestionsTimeout: 500,
|
|
129
|
-
suggestionNumChanges: 3,
|
|
130
|
-
words: [],
|
|
131
|
-
userWords: [],
|
|
132
|
-
ignorePaths: [],
|
|
133
|
-
allowCompoundWords: false,
|
|
134
|
-
patterns: defaultRegExpPatterns,
|
|
135
144
|
ignoreRegExpList: defaultRegExpExcludeList,
|
|
136
145
|
languageSettings: LanguageSettings.getDefaultLanguageSettings(),
|
|
137
|
-
source: { name: 'defaultSettings' },
|
|
138
|
-
reporters: [],
|
|
139
146
|
}));
|
|
140
147
|
const getSettings = (function () {
|
|
141
148
|
let settings = undefined;
|
|
142
|
-
return function () {
|
|
149
|
+
return function (useDefaultDictionaries) {
|
|
150
|
+
if (!useDefaultDictionaries) {
|
|
151
|
+
return exports._defaultSettingsBasis;
|
|
152
|
+
}
|
|
143
153
|
if (!settings) {
|
|
144
154
|
const jsonSettings = (0, configLoader_1.readSettings)(defaultConfigFile);
|
|
145
155
|
settings = (0, index_1.mergeSettings)(exports._defaultSettings, jsonSettings);
|
|
@@ -156,8 +166,22 @@ const getSettings = (function () {
|
|
|
156
166
|
function resolveConfigModule(configModuleName) {
|
|
157
167
|
return (0, resolveFile_1.resolveFile)(configModuleName, __dirname).filename;
|
|
158
168
|
}
|
|
159
|
-
function
|
|
160
|
-
|
|
169
|
+
function normalizePattern(pat) {
|
|
170
|
+
const { name, pattern, description } = pat;
|
|
171
|
+
if (!(pattern instanceof RegExp))
|
|
172
|
+
return pat;
|
|
173
|
+
return {
|
|
174
|
+
name,
|
|
175
|
+
pattern: new PatternRegExp_1.PatternRegExp(pattern),
|
|
176
|
+
description,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function getDefaultSettings(useDefaultDictionaries = true) {
|
|
180
|
+
return getSettings(useDefaultDictionaries);
|
|
161
181
|
}
|
|
162
182
|
exports.getDefaultSettings = getDefaultSettings;
|
|
183
|
+
function getDefaultBundledSettings() {
|
|
184
|
+
return getDefaultSettings();
|
|
185
|
+
}
|
|
186
|
+
exports.getDefaultBundledSettings = getDefaultBundledSettings;
|
|
163
187
|
//# sourceMappingURL=DefaultSettings.js.map
|
|
@@ -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;
|
|
@@ -120,6 +120,7 @@ class _DictionaryDefinitionInternalWithSource {
|
|
|
120
120
|
useCompounds,
|
|
121
121
|
};
|
|
122
122
|
Object.assign(this, (0, util_1.clean)(ddi));
|
|
123
|
+
this.ddi = ddi;
|
|
123
124
|
this.name = ddi.name;
|
|
124
125
|
this.file = ddi.file;
|
|
125
126
|
this.path = ddi.path;
|
|
@@ -130,5 +131,8 @@ class _DictionaryDefinitionInternalWithSource {
|
|
|
130
131
|
get weightMap() {
|
|
131
132
|
return this._weightMap;
|
|
132
133
|
}
|
|
134
|
+
toJSON() {
|
|
135
|
+
return this.ddi;
|
|
136
|
+
}
|
|
133
137
|
}
|
|
134
138
|
//# sourceMappingURL=DictionarySettings.js.map
|
|
@@ -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);
|
package/dist/Settings/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { clearCachedSettingsFiles, defaultConfigFilenames, defaultFileName, extractImportErrors, getCachedFileSize, getGlobalSettings, loadConfig, loadPnP, loadPnPSync, readRawSettings, readSettings, readSettingsFiles, searchForConfig, sectionCSpell, } from './configLoader';
|
|
2
2
|
export { calcOverrideSettings, checkFilenameMatchesGlob, currentSettingsFileVersion, ENV_CSPELL_GLOB_ROOT, extractDependencies, finalizeSettings, getSources, mergeInDocSettings, mergeSettings, } from './CSpellSettingsServer';
|
|
3
3
|
export type { ConfigurationDependencies, ImportFileRefWithError } from './CSpellSettingsServer';
|
|
4
|
-
export { getDefaultSettings } from './DefaultSettings';
|
|
4
|
+
export { getDefaultSettings, getDefaultBundledSettings } from './DefaultSettings';
|
|
5
5
|
export { ImportError } from './ImportError';
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/Settings/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ImportError = exports.getDefaultSettings = exports.mergeSettings = exports.mergeInDocSettings = exports.getSources = exports.finalizeSettings = exports.extractDependencies = exports.ENV_CSPELL_GLOB_ROOT = exports.currentSettingsFileVersion = exports.checkFilenameMatchesGlob = exports.calcOverrideSettings = exports.sectionCSpell = exports.searchForConfig = exports.readSettingsFiles = exports.readSettings = exports.readRawSettings = exports.loadPnPSync = exports.loadPnP = exports.loadConfig = exports.getGlobalSettings = exports.getCachedFileSize = exports.extractImportErrors = exports.defaultFileName = exports.defaultConfigFilenames = exports.clearCachedSettingsFiles = void 0;
|
|
3
|
+
exports.ImportError = exports.getDefaultBundledSettings = exports.getDefaultSettings = exports.mergeSettings = exports.mergeInDocSettings = exports.getSources = exports.finalizeSettings = exports.extractDependencies = exports.ENV_CSPELL_GLOB_ROOT = exports.currentSettingsFileVersion = exports.checkFilenameMatchesGlob = exports.calcOverrideSettings = exports.sectionCSpell = exports.searchForConfig = exports.readSettingsFiles = exports.readSettings = exports.readRawSettings = exports.loadPnPSync = exports.loadPnP = exports.loadConfig = exports.getGlobalSettings = exports.getCachedFileSize = exports.extractImportErrors = exports.defaultFileName = exports.defaultConfigFilenames = exports.clearCachedSettingsFiles = void 0;
|
|
4
4
|
var configLoader_1 = require("./configLoader");
|
|
5
5
|
Object.defineProperty(exports, "clearCachedSettingsFiles", { enumerable: true, get: function () { return configLoader_1.clearCachedSettingsFiles; } });
|
|
6
6
|
Object.defineProperty(exports, "defaultConfigFilenames", { enumerable: true, get: function () { return configLoader_1.defaultConfigFilenames; } });
|
|
@@ -28,6 +28,7 @@ Object.defineProperty(exports, "mergeInDocSettings", { enumerable: true, get: fu
|
|
|
28
28
|
Object.defineProperty(exports, "mergeSettings", { enumerable: true, get: function () { return CSpellSettingsServer_1.mergeSettings; } });
|
|
29
29
|
var DefaultSettings_1 = require("./DefaultSettings");
|
|
30
30
|
Object.defineProperty(exports, "getDefaultSettings", { enumerable: true, get: function () { return DefaultSettings_1.getDefaultSettings; } });
|
|
31
|
+
Object.defineProperty(exports, "getDefaultBundledSettings", { enumerable: true, get: function () { return DefaultSettings_1.getDefaultBundledSettings; } });
|
|
31
32
|
var ImportError_1 = require("./ImportError");
|
|
32
33
|
Object.defineProperty(exports, "ImportError", { enumerable: true, get: function () { return ImportError_1.ImportError; } });
|
|
33
34
|
//# sourceMappingURL=index.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.
|