cspell-lib 5.16.0 → 5.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Models/CSpellSettingsInternalDef.d.ts +23 -0
- package/dist/Models/CSpellSettingsInternalDef.js +16 -0
- package/dist/Settings/CSpellSettingsServer.d.ts +26 -47
- package/dist/Settings/CSpellSettingsServer.js +99 -524
- package/dist/Settings/DefaultSettings.d.ts +3 -3
- package/dist/Settings/DefaultSettings.js +5 -4
- package/dist/Settings/DictionarySettings.d.ts +10 -13
- package/dist/Settings/DictionarySettings.js +51 -18
- package/dist/Settings/InDocSettings.js +5 -2
- package/dist/Settings/configLoader.d.ts +57 -0
- package/dist/Settings/configLoader.js +523 -0
- package/dist/Settings/index.d.ts +5 -4
- package/dist/Settings/index.js +30 -14
- package/dist/Settings/index.link.d.ts +3 -0
- package/dist/Settings/index.link.js +8 -0
- package/dist/Settings/link.js +2 -2
- package/dist/SpellingDictionary/Dictionaries.d.ts +4 -4
- package/dist/SpellingDictionary/Dictionaries.js +26 -7
- package/dist/SpellingDictionary/DictionaryLoader.d.ts +3 -3
- package/dist/SpellingDictionary/DictionaryLoader.js +2 -2
- package/dist/SpellingDictionary/SpellingDictionary.d.ts +4 -3
- package/dist/SpellingDictionary/SpellingDictionaryCollection.js +1 -1
- package/dist/SpellingDictionary/SpellingDictionaryFromTrie.js +1 -1
- package/dist/SpellingDictionary/SpellingDictionaryMethods.d.ts +4 -3
- package/dist/SpellingDictionary/SpellingDictionaryMethods.js +8 -3
- package/dist/SpellingDictionary/createSpellingDictionary.d.ts +2 -2
- package/dist/SpellingDictionary/createSpellingDictionary.js +35 -4
- package/dist/index.d.ts +10 -4
- package/dist/index.js +16 -6
- package/dist/suggestions.d.ts +63 -0
- package/dist/suggestions.js +117 -0
- package/dist/trace.d.ts +1 -0
- package/dist/trace.js +19 -16
- package/dist/util/simpleCache.d.ts +44 -0
- package/dist/util/simpleCache.js +140 -0
- package/dist/util/types.d.ts +49 -1
- package/dist/util/types.js +6 -0
- package/dist/util/util.d.ts +3 -0
- package/dist/util/util.js +19 -1
- package/dist/validator.js +1 -2
- package/package.json +14 -10
|
@@ -0,0 +1,523 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.__testing__ = exports.extractImportErrors = exports.clearCachedSettingsFiles = exports.getCachedFileSize = exports.getGlobalSettings = exports.readSettingsFiles = exports.readRawSettings = exports.loadPnPSync = exports.loadPnP = exports.loadConfig = exports.searchForConfig = exports.readSettings = exports.defaultConfigFilenames = exports.defaultFileName = exports.sectionCSpell = void 0;
|
|
23
|
+
const json = __importStar(require("comment-json"));
|
|
24
|
+
const cosmiconfig_1 = require("cosmiconfig");
|
|
25
|
+
const path = __importStar(require("path"));
|
|
26
|
+
const vscode_uri_1 = require("vscode-uri");
|
|
27
|
+
const CSpellSettingsInternalDef_1 = require("../Models/CSpellSettingsInternalDef");
|
|
28
|
+
const logger_1 = require("../util/logger");
|
|
29
|
+
const resolveFile_1 = require("../util/resolveFile");
|
|
30
|
+
const util = __importStar(require("../util/util"));
|
|
31
|
+
const CSpellSettingsServer_1 = require("./CSpellSettingsServer");
|
|
32
|
+
const DictionarySettings_1 = require("./DictionarySettings");
|
|
33
|
+
const GlobalSettings_1 = require("./GlobalSettings");
|
|
34
|
+
const ImportError_1 = require("./ImportError");
|
|
35
|
+
const pnpLoader_1 = require("./pnpLoader");
|
|
36
|
+
const supportedCSpellConfigVersions = [CSpellSettingsServer_1.configSettingsFileVersion0_2];
|
|
37
|
+
const setOfSupportedConfigVersions = new Set(supportedCSpellConfigVersions);
|
|
38
|
+
exports.sectionCSpell = 'cSpell';
|
|
39
|
+
exports.defaultFileName = 'cspell.json';
|
|
40
|
+
/**
|
|
41
|
+
* Logic of the locations:
|
|
42
|
+
* - Support backward compatibility with the VS Code Spell Checker
|
|
43
|
+
* the spell checker extension can only write to `.json` files because
|
|
44
|
+
* it would be too difficult to automatically modify a `.js` or `.cjs` file.
|
|
45
|
+
* - To support `cspell.config.js` in a VS Code environment, have a `cspell.json` import
|
|
46
|
+
* the `cspell.config.js`.
|
|
47
|
+
*/
|
|
48
|
+
const searchPlaces = [
|
|
49
|
+
'package.json',
|
|
50
|
+
// Original locations
|
|
51
|
+
'.cspell.json',
|
|
52
|
+
'cspell.json',
|
|
53
|
+
'.cSpell.json',
|
|
54
|
+
'cSpell.json',
|
|
55
|
+
// Original locations jsonc
|
|
56
|
+
'.cspell.jsonc',
|
|
57
|
+
'cspell.jsonc',
|
|
58
|
+
// Alternate locations
|
|
59
|
+
'.vscode/cspell.json',
|
|
60
|
+
'.vscode/cSpell.json',
|
|
61
|
+
'.vscode/.cspell.json',
|
|
62
|
+
// Standard Locations
|
|
63
|
+
'cspell.config.json',
|
|
64
|
+
'cspell.config.jsonc',
|
|
65
|
+
'cspell.config.yaml',
|
|
66
|
+
'cspell.config.yml',
|
|
67
|
+
'cspell.yaml',
|
|
68
|
+
'cspell.yml',
|
|
69
|
+
// Dynamic config is looked for last
|
|
70
|
+
'cspell.config.js',
|
|
71
|
+
'cspell.config.cjs',
|
|
72
|
+
];
|
|
73
|
+
const cspellCosmiconfig = {
|
|
74
|
+
searchPlaces,
|
|
75
|
+
loaders: {
|
|
76
|
+
'.json': parseJson,
|
|
77
|
+
'.jsonc': parseJson,
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
function parseJson(_filename, content) {
|
|
81
|
+
return json.parse(content);
|
|
82
|
+
}
|
|
83
|
+
exports.defaultConfigFilenames = Object.freeze(searchPlaces.concat());
|
|
84
|
+
const cspellConfigExplorer = (0, cosmiconfig_1.cosmiconfig)('cspell', cspellCosmiconfig);
|
|
85
|
+
const cspellConfigExplorerSync = (0, cosmiconfig_1.cosmiconfigSync)('cspell', cspellCosmiconfig);
|
|
86
|
+
let globalSettings;
|
|
87
|
+
const defaultSettings = (0, CSpellSettingsInternalDef_1.createCSpellSettingsInternal)({
|
|
88
|
+
id: 'default',
|
|
89
|
+
name: 'default',
|
|
90
|
+
version: CSpellSettingsServer_1.currentSettingsFileVersion,
|
|
91
|
+
});
|
|
92
|
+
const defaultPnPSettings = {};
|
|
93
|
+
const cachedFiles = new Map();
|
|
94
|
+
/**
|
|
95
|
+
* Read a config file and inject the fileRef.
|
|
96
|
+
* @param fileRef - filename plus context, injected into the resulting config.
|
|
97
|
+
*/
|
|
98
|
+
function readConfig(fileRef) {
|
|
99
|
+
// cspellConfigExplorerSync
|
|
100
|
+
const { filename } = fileRef;
|
|
101
|
+
const s = {};
|
|
102
|
+
try {
|
|
103
|
+
const r = cspellConfigExplorerSync.load(filename);
|
|
104
|
+
if (!(r === null || r === void 0 ? void 0 : r.config))
|
|
105
|
+
throw new Error(`not found: "${filename}"`);
|
|
106
|
+
Object.assign(s, r.config);
|
|
107
|
+
normalizeRawConfig(s);
|
|
108
|
+
validateRawConfig(s, fileRef);
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
fileRef.error =
|
|
112
|
+
err instanceof ImportError_1.ImportError ? err : new ImportError_1.ImportError(`Failed to read config file: "${filename}"`, err);
|
|
113
|
+
}
|
|
114
|
+
s.__importRef = fileRef;
|
|
115
|
+
return s;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* normalizeSettings handles correcting all relative paths, anchoring globs, and importing other config files.
|
|
119
|
+
* @param rawSettings - raw configuration settings
|
|
120
|
+
* @param pathToSettingsFile - path to the source file of the configuration settings.
|
|
121
|
+
*/
|
|
122
|
+
function normalizeSettings(rawSettings, pathToSettingsFile, pnpSettings) {
|
|
123
|
+
const id = rawSettings.id ||
|
|
124
|
+
[path.basename(path.dirname(pathToSettingsFile)), path.basename(pathToSettingsFile)].join('/');
|
|
125
|
+
const name = rawSettings.name || id;
|
|
126
|
+
// Try to load any .pnp files before reading dictionaries or other config files.
|
|
127
|
+
const { usePnP = pnpSettings.usePnP, pnpFiles = pnpSettings.pnpFiles } = rawSettings;
|
|
128
|
+
const pnpSettingsToUse = {
|
|
129
|
+
usePnP,
|
|
130
|
+
pnpFiles,
|
|
131
|
+
};
|
|
132
|
+
const pathToSettingsDir = path.dirname(pathToSettingsFile);
|
|
133
|
+
loadPnPSync(pnpSettingsToUse, vscode_uri_1.URI.file(pathToSettingsDir));
|
|
134
|
+
// Fix up dictionaryDefinitions
|
|
135
|
+
const settings = {
|
|
136
|
+
version: defaultSettings.version,
|
|
137
|
+
...rawSettings,
|
|
138
|
+
id,
|
|
139
|
+
name,
|
|
140
|
+
globRoot: resolveGlobRoot(rawSettings, pathToSettingsFile),
|
|
141
|
+
languageSettings: normalizeLanguageSettings(rawSettings.languageSettings),
|
|
142
|
+
};
|
|
143
|
+
const pathToSettings = path.dirname(pathToSettingsFile);
|
|
144
|
+
const normalizedDictionaryDefs = normalizeDictionaryDefs(settings, pathToSettingsFile);
|
|
145
|
+
const normalizedSettingsGlobs = normalizeSettingsGlobs(settings, pathToSettingsFile);
|
|
146
|
+
const normalizedOverrides = normalizeOverrides(settings, pathToSettingsFile);
|
|
147
|
+
const normalizedReporters = normalizeReporters(settings, pathToSettingsFile);
|
|
148
|
+
const normalizedGitignoreRoot = normalizeGitignoreRoot(settings, pathToSettingsFile);
|
|
149
|
+
const normalizedCacheSettings = normalizeCacheSettings(settings, pathToSettingsDir);
|
|
150
|
+
const imports = typeof settings.import === 'string' ? [settings.import] : settings.import || [];
|
|
151
|
+
const source = settings.source || {
|
|
152
|
+
name: settings.name,
|
|
153
|
+
filename: pathToSettingsFile,
|
|
154
|
+
};
|
|
155
|
+
const fileSettings = (0, CSpellSettingsInternalDef_1.createCSpellSettingsInternal)({
|
|
156
|
+
...settings,
|
|
157
|
+
source,
|
|
158
|
+
...normalizedDictionaryDefs,
|
|
159
|
+
...normalizedSettingsGlobs,
|
|
160
|
+
...normalizedOverrides,
|
|
161
|
+
...normalizedReporters,
|
|
162
|
+
...normalizedGitignoreRoot,
|
|
163
|
+
...normalizedCacheSettings,
|
|
164
|
+
});
|
|
165
|
+
if (!imports.length) {
|
|
166
|
+
return fileSettings;
|
|
167
|
+
}
|
|
168
|
+
const importedSettings = imports
|
|
169
|
+
.map((name) => resolveFilename(name, pathToSettings))
|
|
170
|
+
.map((ref) => ((ref.referencedBy = [source]), ref))
|
|
171
|
+
.map((ref) => importSettings(ref, undefined, pnpSettingsToUse))
|
|
172
|
+
.reduce((a, b) => (0, CSpellSettingsServer_1.mergeSettings)(a, b));
|
|
173
|
+
const finalizeSettings = (0, CSpellSettingsServer_1.mergeSettings)(importedSettings, fileSettings);
|
|
174
|
+
finalizeSettings.name = settings.name || finalizeSettings.name || '';
|
|
175
|
+
finalizeSettings.id = settings.id || finalizeSettings.id || '';
|
|
176
|
+
return finalizeSettings;
|
|
177
|
+
}
|
|
178
|
+
function mergeSourceList(orig, append) {
|
|
179
|
+
const collection = new Map(orig.map((s) => [s.name + (s.filename || ''), s]));
|
|
180
|
+
for (const s of append || []) {
|
|
181
|
+
const key = s.name + (s.filename || '');
|
|
182
|
+
if (!collection.has(key)) {
|
|
183
|
+
collection.set(key, s);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return [...collection.values()];
|
|
187
|
+
}
|
|
188
|
+
function importSettings(fileRef, defaultValues, pnpSettings) {
|
|
189
|
+
defaultValues = defaultValues !== null && defaultValues !== void 0 ? defaultValues : defaultSettings;
|
|
190
|
+
let { filename } = fileRef;
|
|
191
|
+
filename = path.resolve(filename);
|
|
192
|
+
const importRef = { ...fileRef, filename };
|
|
193
|
+
const cached = cachedFiles.get(filename);
|
|
194
|
+
if (cached) {
|
|
195
|
+
const cachedImportRef = cached.__importRef || importRef;
|
|
196
|
+
cachedImportRef.referencedBy = mergeSourceList(cachedImportRef.referencedBy || [], importRef.referencedBy);
|
|
197
|
+
cached.__importRef = cachedImportRef;
|
|
198
|
+
return cached;
|
|
199
|
+
}
|
|
200
|
+
const id = [path.basename(path.dirname(filename)), path.basename(filename)].join('/');
|
|
201
|
+
const name = id;
|
|
202
|
+
const finalizeSettings = (0, CSpellSettingsInternalDef_1.createCSpellSettingsInternal)({ id, name, __importRef: importRef });
|
|
203
|
+
cachedFiles.set(filename, finalizeSettings); // add an empty entry to prevent circular references.
|
|
204
|
+
const settings = { ...defaultValues, id, name, ...readConfig(importRef) };
|
|
205
|
+
Object.assign(finalizeSettings, normalizeSettings(settings, filename, pnpSettings));
|
|
206
|
+
const finalizeSrc = { name: path.basename(filename), ...finalizeSettings.source };
|
|
207
|
+
finalizeSettings.source = { ...finalizeSrc, filename };
|
|
208
|
+
cachedFiles.set(filename, finalizeSettings);
|
|
209
|
+
return finalizeSettings;
|
|
210
|
+
}
|
|
211
|
+
function readSettings(filename, relativeToOrDefault, defaultValue) {
|
|
212
|
+
const relativeTo = typeof relativeToOrDefault === 'string' ? relativeToOrDefault : process.cwd();
|
|
213
|
+
defaultValue = defaultValue || (typeof relativeToOrDefault !== 'string' ? relativeToOrDefault : undefined);
|
|
214
|
+
const ref = resolveFilename(filename, relativeTo);
|
|
215
|
+
return importSettings(ref, defaultValue, defaultValue || defaultPnPSettings);
|
|
216
|
+
}
|
|
217
|
+
exports.readSettings = readSettings;
|
|
218
|
+
async function normalizeSearchForConfigResult(searchPath, searchResult, pnpSettings) {
|
|
219
|
+
var _a;
|
|
220
|
+
let result;
|
|
221
|
+
let error;
|
|
222
|
+
try {
|
|
223
|
+
result = (await searchResult) || undefined;
|
|
224
|
+
}
|
|
225
|
+
catch (cause) {
|
|
226
|
+
error = new ImportError_1.ImportError(`Failed to find config file at: "${searchPath}"`, cause);
|
|
227
|
+
}
|
|
228
|
+
const filepath = result === null || result === void 0 ? void 0 : result.filepath;
|
|
229
|
+
if (filepath) {
|
|
230
|
+
const cached = cachedFiles.get(filepath);
|
|
231
|
+
if (cached) {
|
|
232
|
+
return {
|
|
233
|
+
config: cached,
|
|
234
|
+
filepath,
|
|
235
|
+
error,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
const { config = (0, CSpellSettingsInternalDef_1.createCSpellSettingsInternal)({}) } = result || {};
|
|
240
|
+
const filename = (_a = result === null || result === void 0 ? void 0 : result.filepath) !== null && _a !== void 0 ? _a : searchPath;
|
|
241
|
+
const importRef = { filename: filename, error };
|
|
242
|
+
const id = [path.basename(path.dirname(filename)), path.basename(filename)].join('/');
|
|
243
|
+
const name = (result === null || result === void 0 ? void 0 : result.filepath) ? id : `Config not found: ${id}`;
|
|
244
|
+
const finalizeSettings = (0, CSpellSettingsInternalDef_1.createCSpellSettingsInternal)({ id, name, __importRef: importRef });
|
|
245
|
+
const settings = { id, ...config };
|
|
246
|
+
cachedFiles.set(filename, finalizeSettings); // add an empty entry to prevent circular references.
|
|
247
|
+
Object.assign(finalizeSettings, normalizeSettings(settings, filename, pnpSettings));
|
|
248
|
+
return {
|
|
249
|
+
config: finalizeSettings,
|
|
250
|
+
filepath,
|
|
251
|
+
error,
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
function searchForConfig(searchFrom, pnpSettings = defaultPnPSettings) {
|
|
255
|
+
return normalizeSearchForConfigResult(searchFrom || process.cwd(), cspellConfigExplorer.search(searchFrom), pnpSettings).then((r) => (r.filepath ? r.config : undefined));
|
|
256
|
+
}
|
|
257
|
+
exports.searchForConfig = searchForConfig;
|
|
258
|
+
/**
|
|
259
|
+
* Load a CSpell configuration files.
|
|
260
|
+
* @param file - path or package reference to load.
|
|
261
|
+
* @param pnpSettings - PnP settings
|
|
262
|
+
* @returns normalized CSpellSettings
|
|
263
|
+
*/
|
|
264
|
+
function loadConfig(file, pnpSettings = defaultPnPSettings) {
|
|
265
|
+
const cached = cachedFiles.get(path.resolve(file));
|
|
266
|
+
if (cached) {
|
|
267
|
+
return Promise.resolve(cached);
|
|
268
|
+
}
|
|
269
|
+
return normalizeSearchForConfigResult(file, cspellConfigExplorer.load(file), pnpSettings).then((r) => r.config);
|
|
270
|
+
}
|
|
271
|
+
exports.loadConfig = loadConfig;
|
|
272
|
+
function loadPnP(pnpSettings, searchFrom) {
|
|
273
|
+
if (!pnpSettings.usePnP) {
|
|
274
|
+
return Promise.resolve(undefined);
|
|
275
|
+
}
|
|
276
|
+
const loader = (0, pnpLoader_1.pnpLoader)(pnpSettings.pnpFiles);
|
|
277
|
+
return loader.load(searchFrom);
|
|
278
|
+
}
|
|
279
|
+
exports.loadPnP = loadPnP;
|
|
280
|
+
function loadPnPSync(pnpSettings, searchFrom) {
|
|
281
|
+
if (!pnpSettings.usePnP) {
|
|
282
|
+
return undefined;
|
|
283
|
+
}
|
|
284
|
+
const loader = (0, pnpLoader_1.pnpLoader)(pnpSettings.pnpFiles);
|
|
285
|
+
return loader.loadSync(searchFrom);
|
|
286
|
+
}
|
|
287
|
+
exports.loadPnPSync = loadPnPSync;
|
|
288
|
+
function readRawSettings(filename, relativeTo) {
|
|
289
|
+
relativeTo = relativeTo || process.cwd();
|
|
290
|
+
const ref = resolveFilename(filename, relativeTo);
|
|
291
|
+
return readConfig(ref);
|
|
292
|
+
}
|
|
293
|
+
exports.readRawSettings = readRawSettings;
|
|
294
|
+
/**
|
|
295
|
+
*
|
|
296
|
+
* @param filenames - settings files to read
|
|
297
|
+
* @returns combined configuration
|
|
298
|
+
* @deprecated true
|
|
299
|
+
*/
|
|
300
|
+
function readSettingsFiles(filenames) {
|
|
301
|
+
return filenames.map((filename) => readSettings(filename)).reduce((a, b) => (0, CSpellSettingsServer_1.mergeSettings)(a, b), defaultSettings);
|
|
302
|
+
}
|
|
303
|
+
exports.readSettingsFiles = readSettingsFiles;
|
|
304
|
+
function resolveFilename(filename, relativeTo) {
|
|
305
|
+
const r = (0, resolveFile_1.resolveFile)(filename, relativeTo);
|
|
306
|
+
return {
|
|
307
|
+
filename: r.filename,
|
|
308
|
+
error: r.found ? undefined : new Error(`Failed to resolve file: "${filename}"`),
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
function getGlobalSettings() {
|
|
312
|
+
if (!globalSettings) {
|
|
313
|
+
const globalConf = (0, GlobalSettings_1.getRawGlobalSettings)();
|
|
314
|
+
globalSettings = {
|
|
315
|
+
id: 'global_config',
|
|
316
|
+
...normalizeSettings(globalConf || {}, './global_config', {}),
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
return globalSettings;
|
|
320
|
+
}
|
|
321
|
+
exports.getGlobalSettings = getGlobalSettings;
|
|
322
|
+
function getCachedFileSize() {
|
|
323
|
+
return cachedFiles.size;
|
|
324
|
+
}
|
|
325
|
+
exports.getCachedFileSize = getCachedFileSize;
|
|
326
|
+
function clearCachedSettingsFiles() {
|
|
327
|
+
globalSettings = undefined;
|
|
328
|
+
cachedFiles.clear();
|
|
329
|
+
cspellConfigExplorer.clearCaches();
|
|
330
|
+
cspellConfigExplorerSync.clearCaches();
|
|
331
|
+
}
|
|
332
|
+
exports.clearCachedSettingsFiles = clearCachedSettingsFiles;
|
|
333
|
+
function mergeImportRefs(left, right = {}) {
|
|
334
|
+
var _a;
|
|
335
|
+
const imports = new Map(left.__imports || []);
|
|
336
|
+
if (left.__importRef) {
|
|
337
|
+
imports.set(left.__importRef.filename, left.__importRef);
|
|
338
|
+
}
|
|
339
|
+
if (right.__importRef) {
|
|
340
|
+
imports.set(right.__importRef.filename, right.__importRef);
|
|
341
|
+
}
|
|
342
|
+
const rightImports = ((_a = right.__imports) === null || _a === void 0 ? void 0 : _a.values()) || [];
|
|
343
|
+
for (const ref of rightImports) {
|
|
344
|
+
imports.set(ref.filename, ref);
|
|
345
|
+
}
|
|
346
|
+
return imports.size ? imports : undefined;
|
|
347
|
+
}
|
|
348
|
+
function isImportFileRefWithError(ref) {
|
|
349
|
+
return !!ref.error;
|
|
350
|
+
}
|
|
351
|
+
function extractImportErrors(settings) {
|
|
352
|
+
const imports = mergeImportRefs(settings);
|
|
353
|
+
return !imports ? [] : [...imports.values()].filter(isImportFileRefWithError);
|
|
354
|
+
}
|
|
355
|
+
exports.extractImportErrors = extractImportErrors;
|
|
356
|
+
function resolveGlobRoot(settings, pathToSettingsFile) {
|
|
357
|
+
var _a;
|
|
358
|
+
const settingsFileDirRaw = path.dirname(pathToSettingsFile);
|
|
359
|
+
const isVSCode = path.basename(settingsFileDirRaw) === '.vscode';
|
|
360
|
+
const settingsFileDir = isVSCode ? path.dirname(settingsFileDirRaw) : settingsFileDirRaw;
|
|
361
|
+
const envGlobRoot = process.env[CSpellSettingsServer_1.ENV_CSPELL_GLOB_ROOT];
|
|
362
|
+
const defaultGlobRoot = envGlobRoot !== null && envGlobRoot !== void 0 ? envGlobRoot : '${cwd}';
|
|
363
|
+
const rawRoot = (_a = settings.globRoot) !== null && _a !== void 0 ? _a : (settings.version === CSpellSettingsServer_1.configSettingsFileVersion0_1 ||
|
|
364
|
+
(envGlobRoot && !settings.version) ||
|
|
365
|
+
(isVSCode && !settings.version)
|
|
366
|
+
? defaultGlobRoot
|
|
367
|
+
: settingsFileDir);
|
|
368
|
+
const globRoot = rawRoot.startsWith('${cwd}') ? rawRoot : path.resolve(settingsFileDir, rawRoot);
|
|
369
|
+
return globRoot;
|
|
370
|
+
}
|
|
371
|
+
function resolveFilePath(filename, pathToSettingsFile) {
|
|
372
|
+
const cwd = process.cwd();
|
|
373
|
+
return path.resolve(pathToSettingsFile, filename.replace('${cwd}', cwd));
|
|
374
|
+
}
|
|
375
|
+
function toGlobDef(g, root, source) {
|
|
376
|
+
if (g === undefined)
|
|
377
|
+
return undefined;
|
|
378
|
+
if (Array.isArray(g)) {
|
|
379
|
+
return g.map((g) => toGlobDef(g, root, source));
|
|
380
|
+
}
|
|
381
|
+
if (typeof g === 'string') {
|
|
382
|
+
return toGlobDef({
|
|
383
|
+
glob: g,
|
|
384
|
+
root,
|
|
385
|
+
}, root, source);
|
|
386
|
+
}
|
|
387
|
+
if (source) {
|
|
388
|
+
return { ...g, source };
|
|
389
|
+
}
|
|
390
|
+
return g;
|
|
391
|
+
}
|
|
392
|
+
function normalizeDictionaryDefs(settings, pathToSettingsFile) {
|
|
393
|
+
var _a;
|
|
394
|
+
const dictionaryDefinitions = (0, DictionarySettings_1.mapDictDefsToInternal)(settings.dictionaryDefinitions, pathToSettingsFile);
|
|
395
|
+
const languageSettings = (_a = settings.languageSettings) === null || _a === void 0 ? void 0 : _a.map((langSetting) => util.clean({
|
|
396
|
+
...langSetting,
|
|
397
|
+
dictionaryDefinitions: (0, DictionarySettings_1.mapDictDefsToInternal)(langSetting.dictionaryDefinitions, pathToSettingsFile),
|
|
398
|
+
}));
|
|
399
|
+
return util.clean({
|
|
400
|
+
dictionaryDefinitions,
|
|
401
|
+
languageSettings,
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
function normalizeOverrides(settings, pathToSettingsFile) {
|
|
405
|
+
var _a;
|
|
406
|
+
const { globRoot = path.dirname(pathToSettingsFile) } = settings;
|
|
407
|
+
const overrides = (_a = settings.overrides) === null || _a === void 0 ? void 0 : _a.map((override) => {
|
|
408
|
+
const filename = toGlobDef(override.filename, globRoot, pathToSettingsFile);
|
|
409
|
+
const { dictionaryDefinitions, languageSettings } = normalizeDictionaryDefs(override, pathToSettingsFile);
|
|
410
|
+
return util.clean({
|
|
411
|
+
...override,
|
|
412
|
+
filename,
|
|
413
|
+
dictionaryDefinitions,
|
|
414
|
+
languageSettings: normalizeLanguageSettings(languageSettings),
|
|
415
|
+
});
|
|
416
|
+
});
|
|
417
|
+
return overrides ? { overrides } : {};
|
|
418
|
+
}
|
|
419
|
+
function normalizeReporters(settings, pathToSettingsFile) {
|
|
420
|
+
if (settings.reporters === undefined)
|
|
421
|
+
return {};
|
|
422
|
+
const folder = path.dirname(pathToSettingsFile);
|
|
423
|
+
function resolve(s) {
|
|
424
|
+
const r = (0, resolveFile_1.resolveFile)(s, folder);
|
|
425
|
+
if (!r.found) {
|
|
426
|
+
throw new Error(`Not found: "${s}"`);
|
|
427
|
+
}
|
|
428
|
+
return r.filename;
|
|
429
|
+
}
|
|
430
|
+
function resolveReporter(s) {
|
|
431
|
+
if (typeof s === 'string') {
|
|
432
|
+
return resolve(s);
|
|
433
|
+
}
|
|
434
|
+
if (!Array.isArray(s) || typeof s[0] !== 'string')
|
|
435
|
+
throw new Error('Invalid Reporter');
|
|
436
|
+
// Preserve the shape of Reporter Setting while resolving the reporter file.
|
|
437
|
+
const [r, ...rest] = s;
|
|
438
|
+
return [resolve(r), ...rest];
|
|
439
|
+
}
|
|
440
|
+
return {
|
|
441
|
+
reporters: settings.reporters.map(resolveReporter),
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
function normalizeLanguageSettings(languageSettings) {
|
|
445
|
+
if (!languageSettings)
|
|
446
|
+
return undefined;
|
|
447
|
+
function fixLocale(s) {
|
|
448
|
+
const { local: locale, ...rest } = s;
|
|
449
|
+
return { locale, ...rest };
|
|
450
|
+
}
|
|
451
|
+
return languageSettings.map(fixLocale);
|
|
452
|
+
}
|
|
453
|
+
function normalizeGitignoreRoot(settings, pathToSettingsFile) {
|
|
454
|
+
const { gitignoreRoot } = settings;
|
|
455
|
+
if (!gitignoreRoot)
|
|
456
|
+
return {};
|
|
457
|
+
const dir = path.dirname(pathToSettingsFile);
|
|
458
|
+
const roots = Array.isArray(gitignoreRoot) ? gitignoreRoot : [gitignoreRoot];
|
|
459
|
+
return {
|
|
460
|
+
gitignoreRoot: roots.map((p) => path.resolve(dir, p)),
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
function normalizeSettingsGlobs(settings, pathToSettingsFile) {
|
|
464
|
+
const { globRoot } = settings;
|
|
465
|
+
if (settings.ignorePaths === undefined)
|
|
466
|
+
return {};
|
|
467
|
+
const ignorePaths = toGlobDef(settings.ignorePaths, globRoot, pathToSettingsFile);
|
|
468
|
+
return {
|
|
469
|
+
ignorePaths,
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
function normalizeCacheSettings(settings, pathToSettingsDir) {
|
|
473
|
+
const { cache } = settings;
|
|
474
|
+
if (cache === undefined)
|
|
475
|
+
return {};
|
|
476
|
+
const { cacheLocation } = cache;
|
|
477
|
+
if (cacheLocation === undefined)
|
|
478
|
+
return { cache };
|
|
479
|
+
return { cache: { ...cache, cacheLocation: resolveFilePath(cacheLocation, pathToSettingsDir) } };
|
|
480
|
+
}
|
|
481
|
+
function validationMessage(msg, fileRef) {
|
|
482
|
+
return msg + `\n File: "${fileRef.filename}"`;
|
|
483
|
+
}
|
|
484
|
+
function validateRawConfigVersion(config, fileRef) {
|
|
485
|
+
const { version } = config;
|
|
486
|
+
if (version === undefined)
|
|
487
|
+
return;
|
|
488
|
+
if (typeof version !== 'string') {
|
|
489
|
+
(0, logger_1.logError)(validationMessage(`Unsupported config file version: "${version}", string expected`, fileRef));
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
if (setOfSupportedConfigVersions.has(version))
|
|
493
|
+
return;
|
|
494
|
+
if (!/^\d+(\.\d+)*$/.test(version)) {
|
|
495
|
+
(0, logger_1.logError)(validationMessage(`Unsupported config file version: "${version}"`, fileRef));
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
const msg = version > CSpellSettingsServer_1.currentSettingsFileVersion
|
|
499
|
+
? `Newer config file version found: "${version}". Supported version is "${CSpellSettingsServer_1.currentSettingsFileVersion}"`
|
|
500
|
+
: `Legacy config file version found: "${version}", upgrade to "${CSpellSettingsServer_1.currentSettingsFileVersion}"`;
|
|
501
|
+
(0, logger_1.logWarning)(validationMessage(msg, fileRef));
|
|
502
|
+
}
|
|
503
|
+
function validateRawConfigExports(config, fileRef) {
|
|
504
|
+
if (config.default) {
|
|
505
|
+
throw new ImportError_1.ImportError(validationMessage('Module `export default` is not supported.\n Use `module.exports =` instead.', fileRef));
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
function normalizeRawConfig(config) {
|
|
509
|
+
if (typeof config.version === 'number') {
|
|
510
|
+
config.version = config.version.toString();
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
function validateRawConfig(config, fileRef) {
|
|
514
|
+
const validations = [validateRawConfigExports, validateRawConfigVersion];
|
|
515
|
+
validations.forEach((fn) => fn(config, fileRef));
|
|
516
|
+
}
|
|
517
|
+
exports.__testing__ = {
|
|
518
|
+
normalizeCacheSettings,
|
|
519
|
+
normalizeSettings,
|
|
520
|
+
validateRawConfigExports,
|
|
521
|
+
validateRawConfigVersion,
|
|
522
|
+
};
|
|
523
|
+
//# sourceMappingURL=configLoader.js.map
|
package/dist/Settings/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
1
|
+
export { clearCachedSettingsFiles, defaultConfigFilenames, defaultFileName, extractImportErrors, getCachedFileSize, getGlobalSettings, loadConfig, loadPnP, loadPnPSync, readRawSettings, readSettings, readSettingsFiles, searchForConfig, sectionCSpell, } from './configLoader';
|
|
2
|
+
export { calcOverrideSettings, checkFilenameMatchesGlob, currentSettingsFileVersion, ENV_CSPELL_GLOB_ROOT, extractDependencies, finalizeSettings, getSources, mergeInDocSettings, mergeSettings, } from './CSpellSettingsServer';
|
|
3
|
+
export type { ConfigurationDependencies, ImportFileRefWithError } from './CSpellSettingsServer';
|
|
4
|
+
export { getDefaultSettings } from './DefaultSettings';
|
|
5
|
+
export { ImportError } from './ImportError';
|
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/Settings/index.js
CHANGED
|
@@ -1,17 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
-
};
|
|
12
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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;
|
|
4
|
+
var configLoader_1 = require("./configLoader");
|
|
5
|
+
Object.defineProperty(exports, "clearCachedSettingsFiles", { enumerable: true, get: function () { return configLoader_1.clearCachedSettingsFiles; } });
|
|
6
|
+
Object.defineProperty(exports, "defaultConfigFilenames", { enumerable: true, get: function () { return configLoader_1.defaultConfigFilenames; } });
|
|
7
|
+
Object.defineProperty(exports, "defaultFileName", { enumerable: true, get: function () { return configLoader_1.defaultFileName; } });
|
|
8
|
+
Object.defineProperty(exports, "extractImportErrors", { enumerable: true, get: function () { return configLoader_1.extractImportErrors; } });
|
|
9
|
+
Object.defineProperty(exports, "getCachedFileSize", { enumerable: true, get: function () { return configLoader_1.getCachedFileSize; } });
|
|
10
|
+
Object.defineProperty(exports, "getGlobalSettings", { enumerable: true, get: function () { return configLoader_1.getGlobalSettings; } });
|
|
11
|
+
Object.defineProperty(exports, "loadConfig", { enumerable: true, get: function () { return configLoader_1.loadConfig; } });
|
|
12
|
+
Object.defineProperty(exports, "loadPnP", { enumerable: true, get: function () { return configLoader_1.loadPnP; } });
|
|
13
|
+
Object.defineProperty(exports, "loadPnPSync", { enumerable: true, get: function () { return configLoader_1.loadPnPSync; } });
|
|
14
|
+
Object.defineProperty(exports, "readRawSettings", { enumerable: true, get: function () { return configLoader_1.readRawSettings; } });
|
|
15
|
+
Object.defineProperty(exports, "readSettings", { enumerable: true, get: function () { return configLoader_1.readSettings; } });
|
|
16
|
+
Object.defineProperty(exports, "readSettingsFiles", { enumerable: true, get: function () { return configLoader_1.readSettingsFiles; } });
|
|
17
|
+
Object.defineProperty(exports, "searchForConfig", { enumerable: true, get: function () { return configLoader_1.searchForConfig; } });
|
|
18
|
+
Object.defineProperty(exports, "sectionCSpell", { enumerable: true, get: function () { return configLoader_1.sectionCSpell; } });
|
|
19
|
+
var CSpellSettingsServer_1 = require("./CSpellSettingsServer");
|
|
20
|
+
Object.defineProperty(exports, "calcOverrideSettings", { enumerable: true, get: function () { return CSpellSettingsServer_1.calcOverrideSettings; } });
|
|
21
|
+
Object.defineProperty(exports, "checkFilenameMatchesGlob", { enumerable: true, get: function () { return CSpellSettingsServer_1.checkFilenameMatchesGlob; } });
|
|
22
|
+
Object.defineProperty(exports, "currentSettingsFileVersion", { enumerable: true, get: function () { return CSpellSettingsServer_1.currentSettingsFileVersion; } });
|
|
23
|
+
Object.defineProperty(exports, "ENV_CSPELL_GLOB_ROOT", { enumerable: true, get: function () { return CSpellSettingsServer_1.ENV_CSPELL_GLOB_ROOT; } });
|
|
24
|
+
Object.defineProperty(exports, "extractDependencies", { enumerable: true, get: function () { return CSpellSettingsServer_1.extractDependencies; } });
|
|
25
|
+
Object.defineProperty(exports, "finalizeSettings", { enumerable: true, get: function () { return CSpellSettingsServer_1.finalizeSettings; } });
|
|
26
|
+
Object.defineProperty(exports, "getSources", { enumerable: true, get: function () { return CSpellSettingsServer_1.getSources; } });
|
|
27
|
+
Object.defineProperty(exports, "mergeInDocSettings", { enumerable: true, get: function () { return CSpellSettingsServer_1.mergeInDocSettings; } });
|
|
28
|
+
Object.defineProperty(exports, "mergeSettings", { enumerable: true, get: function () { return CSpellSettingsServer_1.mergeSettings; } });
|
|
29
|
+
var DefaultSettings_1 = require("./DefaultSettings");
|
|
30
|
+
Object.defineProperty(exports, "getDefaultSettings", { enumerable: true, get: function () { return DefaultSettings_1.getDefaultSettings; } });
|
|
31
|
+
var ImportError_1 = require("./ImportError");
|
|
32
|
+
Object.defineProperty(exports, "ImportError", { enumerable: true, get: function () { return ImportError_1.ImportError; } });
|
|
17
33
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { addPathsToGlobalImports, listGlobalImports, removePathsFromGlobalImports } from './link';
|
|
2
|
+
export type { AddPathsToGlobalImportsResults, ListGlobalImportsResult, ListGlobalImportsResults, RemovePathsFromGlobalImportsResult, ResolveSettingsResult, } from './link';
|
|
3
|
+
//# sourceMappingURL=index.link.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removePathsFromGlobalImports = exports.listGlobalImports = exports.addPathsToGlobalImports = void 0;
|
|
4
|
+
var link_1 = require("./link");
|
|
5
|
+
Object.defineProperty(exports, "addPathsToGlobalImports", { enumerable: true, get: function () { return link_1.addPathsToGlobalImports; } });
|
|
6
|
+
Object.defineProperty(exports, "listGlobalImports", { enumerable: true, get: function () { return link_1.listGlobalImports; } });
|
|
7
|
+
Object.defineProperty(exports, "removePathsFromGlobalImports", { enumerable: true, get: function () { return link_1.removePathsFromGlobalImports; } });
|
|
8
|
+
//# sourceMappingURL=index.link.js.map
|
package/dist/Settings/link.js
CHANGED
|
@@ -22,7 +22,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
22
22
|
exports.__testing__ = exports.removePathsFromGlobalImports = exports.addPathsToGlobalImports = exports.listGlobalImports = void 0;
|
|
23
23
|
const fs = __importStar(require("fs"));
|
|
24
24
|
const Path = __importStar(require("path"));
|
|
25
|
-
const
|
|
25
|
+
const configLoader_1 = require("./configLoader");
|
|
26
26
|
const GlobalSettings_1 = require("./GlobalSettings");
|
|
27
27
|
function listGlobalImports() {
|
|
28
28
|
const globalSettings = (0, GlobalSettings_1.getRawGlobalSettings)();
|
|
@@ -125,7 +125,7 @@ function removePathsFromGlobalImports(paths) {
|
|
|
125
125
|
exports.removePathsFromGlobalImports = removePathsFromGlobalImports;
|
|
126
126
|
function resolveSettings(filename) {
|
|
127
127
|
var _a;
|
|
128
|
-
const settings = (0,
|
|
128
|
+
const settings = (0, configLoader_1.readRawSettings)(filename);
|
|
129
129
|
const ref = settings.__importRef;
|
|
130
130
|
const resolvedToFilename = ref === null || ref === void 0 ? void 0 : ref.filename;
|
|
131
131
|
const error = ((_a = ref === null || ref === void 0 ? void 0 : ref.error) === null || _a === void 0 ? void 0 : _a.message) || (!resolvedToFilename && 'File not Found') || undefined;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { SpellingDictionaryCollection } from './index';
|
|
1
|
+
import { CSpellSettingsInternal, DictionaryDefinitionInternal } from '../Models/CSpellSettingsInternalDef';
|
|
3
2
|
import { SpellingDictionary } from './SpellingDictionary';
|
|
4
|
-
|
|
3
|
+
import { SpellingDictionaryCollection } from './SpellingDictionaryCollection';
|
|
4
|
+
export declare function loadDictionaryDefs(defsToLoad: DictionaryDefinitionInternal[]): Promise<SpellingDictionary>[];
|
|
5
5
|
export declare function refreshDictionaryCache(maxAge?: number): Promise<void>;
|
|
6
|
-
export declare function
|
|
6
|
+
export declare function getDictionaryInternal(settings: CSpellSettingsInternal): Promise<SpellingDictionaryCollection>;
|
|
7
7
|
//# sourceMappingURL=Dictionaries.d.ts.map
|