cspell-lib 5.17.0 → 5.18.2
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 +4 -4
- package/dist/Settings/CSpellSettingsServer.d.ts +3 -47
- package/dist/Settings/CSpellSettingsServer.js +27 -488
- package/dist/Settings/DefaultSettings.js +3 -3
- package/dist/Settings/DictionarySettings.js +45 -13
- 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 +2 -1
- package/dist/Settings/index.js +16 -15
- package/dist/Settings/link.js +2 -2
- package/dist/SpellingDictionary/Dictionaries.js +23 -4
- 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 +7 -5
- package/dist/SpellingDictionary/SpellingDictionaryMethods.js +9 -9
- package/dist/SpellingDictionary/createSpellingDictionary.d.ts +2 -2
- package/dist/SpellingDictionary/createSpellingDictionary.js +35 -4
- package/dist/suggestions.js +2 -2
- 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/package.json +10 -9
|
@@ -6,16 +6,16 @@ export interface CSpellSettingsInternal extends Omit<CSpellSettingsWithSourceTra
|
|
|
6
6
|
dictionaryDefinitions?: DictionaryDefinitionInternal[];
|
|
7
7
|
}
|
|
8
8
|
declare type DictionaryDefinitionCustomUniqueFields = Omit<DictionaryDefinitionCustom, keyof DictionaryDefinitionPreferred>;
|
|
9
|
-
export interface DictionaryDefinitionInternal extends DictionaryDefinitionPreferred
|
|
9
|
+
export interface DictionaryDefinitionInternal extends Readonly<DictionaryDefinitionPreferred>, Readonly<Partial<DictionaryDefinitionCustomUniqueFields>>, Readonly<DictionaryDefinitionAugmented> {
|
|
10
10
|
/**
|
|
11
11
|
* Optional weight map used to improve suggestions.
|
|
12
12
|
*/
|
|
13
|
-
weightMap?: WeightMap;
|
|
13
|
+
readonly weightMap?: WeightMap | undefined;
|
|
14
14
|
/** The path to the config file that contains this dictionary definition */
|
|
15
|
-
__source?: string;
|
|
15
|
+
readonly __source?: string | undefined;
|
|
16
16
|
}
|
|
17
17
|
export interface DictionaryDefinitionInternalWithSource extends DictionaryDefinitionInternal {
|
|
18
|
-
__source: string;
|
|
18
|
+
readonly __source: string;
|
|
19
19
|
}
|
|
20
20
|
export declare function createCSpellSettingsInternal(parts?: Partial<CSpellSettingsInternal>): CSpellSettingsInternal;
|
|
21
21
|
export declare function isCSpellSettingsInternal(cs: CSpellSettingsInternal | CSpellSettingsWithSourceTrace): cs is CSpellSettingsInternal;
|
|
@@ -1,42 +1,11 @@
|
|
|
1
|
-
import type { CSpellSettingsWithSourceTrace,
|
|
2
|
-
import { URI } from 'vscode-uri';
|
|
1
|
+
import type { CSpellSettingsWithSourceTrace, Glob, ImportFileRef } from '@cspell/cspell-types';
|
|
3
2
|
import { CSpellSettingsInternal } from '../Models/CSpellSettingsInternalDef';
|
|
4
|
-
import { LoaderResult } from './pnpLoader';
|
|
5
3
|
declare type CSpellSettingsWST = CSpellSettingsWithSourceTrace;
|
|
6
4
|
declare type CSpellSettingsI = CSpellSettingsInternal;
|
|
5
|
+
export declare const configSettingsFileVersion0_1 = "0.1";
|
|
6
|
+
export declare const configSettingsFileVersion0_2 = "0.2";
|
|
7
7
|
export declare const currentSettingsFileVersion = "0.2";
|
|
8
|
-
export declare const sectionCSpell = "cSpell";
|
|
9
|
-
export declare const defaultFileName = "cspell.json";
|
|
10
8
|
export declare const ENV_CSPELL_GLOB_ROOT = "CSPELL_GLOB_ROOT";
|
|
11
|
-
export declare const defaultConfigFilenames: readonly string[];
|
|
12
|
-
/**
|
|
13
|
-
* normalizeSettings handles correcting all relative paths, anchoring globs, and importing other config files.
|
|
14
|
-
* @param rawSettings - raw configuration settings
|
|
15
|
-
* @param pathToSettingsFile - path to the source file of the configuration settings.
|
|
16
|
-
*/
|
|
17
|
-
declare function normalizeSettings(rawSettings: CSpellSettingsWST, pathToSettingsFile: string, pnpSettings: PnPSettings): CSpellSettingsI;
|
|
18
|
-
export declare function readSettings(filename: string): CSpellSettingsI;
|
|
19
|
-
export declare function readSettings(filename: string, defaultValues: CSpellSettingsWST): CSpellSettingsI;
|
|
20
|
-
export declare function readSettings(filename: string, relativeTo: string): CSpellSettingsI;
|
|
21
|
-
export declare function readSettings(filename: string, relativeTo: string, defaultValues: CSpellSettingsWST): CSpellSettingsI;
|
|
22
|
-
export declare function searchForConfig(searchFrom: string | undefined, pnpSettings?: PnPSettings): Promise<CSpellSettingsI | undefined>;
|
|
23
|
-
/**
|
|
24
|
-
* Load a CSpell configuration files.
|
|
25
|
-
* @param file - path or package reference to load.
|
|
26
|
-
* @param pnpSettings - PnP settings
|
|
27
|
-
* @returns normalized CSpellSettings
|
|
28
|
-
*/
|
|
29
|
-
export declare function loadConfig(file: string, pnpSettings?: PnPSettings): Promise<CSpellSettingsI>;
|
|
30
|
-
export declare function loadPnP(pnpSettings: PnPSettings, searchFrom: URI): Promise<LoaderResult>;
|
|
31
|
-
export declare function loadPnPSync(pnpSettings: PnPSettings, searchFrom: URI): LoaderResult;
|
|
32
|
-
export declare function readRawSettings(filename: string, relativeTo?: string): CSpellSettingsWST;
|
|
33
|
-
/**
|
|
34
|
-
*
|
|
35
|
-
* @param filenames - settings files to read
|
|
36
|
-
* @returns combined configuration
|
|
37
|
-
* @deprecated true
|
|
38
|
-
*/
|
|
39
|
-
export declare function readSettingsFiles(filenames: string[]): CSpellSettingsI;
|
|
40
9
|
declare function mergeObjects(left: undefined, right: undefined): undefined;
|
|
41
10
|
declare function mergeObjects<T>(left: T, right: undefined): T;
|
|
42
11
|
declare function mergeObjects<T>(left: T, right: T): T;
|
|
@@ -53,9 +22,6 @@ export declare function finalizeSettings(settings: CSpellSettingsWST | CSpellSet
|
|
|
53
22
|
export declare function toInternalSettings(settings: undefined): undefined;
|
|
54
23
|
export declare function toInternalSettings(settings: CSpellSettingsI | CSpellSettingsWST): CSpellSettingsI;
|
|
55
24
|
export declare function toInternalSettings(settings?: CSpellSettingsI | CSpellSettingsWST): CSpellSettingsI | undefined;
|
|
56
|
-
export declare function getGlobalSettings(): CSpellSettingsI;
|
|
57
|
-
export declare function getCachedFileSize(): number;
|
|
58
|
-
export declare function clearCachedSettingsFiles(): void;
|
|
59
25
|
/**
|
|
60
26
|
* @param filename - filename
|
|
61
27
|
* @param globs - globs
|
|
@@ -72,23 +38,13 @@ export declare function getSources(settings: CSpellSettingsWST): CSpellSettingsW
|
|
|
72
38
|
export interface ImportFileRefWithError extends ImportFileRef {
|
|
73
39
|
error: Error;
|
|
74
40
|
}
|
|
75
|
-
export declare function extractImportErrors(settings: CSpellSettingsWST): ImportFileRefWithError[];
|
|
76
41
|
export interface ConfigurationDependencies {
|
|
77
42
|
configFiles: string[];
|
|
78
43
|
dictionaryFiles: string[];
|
|
79
44
|
}
|
|
80
45
|
export declare function extractDependencies(settings: CSpellSettingsWST | CSpellSettingsI): ConfigurationDependencies;
|
|
81
|
-
declare function normalizeCacheSettings(settings: Pick<CSpellUserSettings, 'cache'>, pathToSettingsDir: string): Pick<CSpellUserSettings, 'cache'>;
|
|
82
|
-
declare function validateRawConfigVersion(config: CSpellUserSettings | {
|
|
83
|
-
version: unknown;
|
|
84
|
-
}, fileRef: ImportFileRef): void;
|
|
85
|
-
declare function validateRawConfigExports(config: CSpellUserSettings, fileRef: ImportFileRef): void;
|
|
86
46
|
export declare const __testing__: {
|
|
87
47
|
mergeObjects: typeof mergeObjects;
|
|
88
|
-
normalizeCacheSettings: typeof normalizeCacheSettings;
|
|
89
|
-
normalizeSettings: typeof normalizeSettings;
|
|
90
|
-
validateRawConfigExports: typeof validateRawConfigExports;
|
|
91
|
-
validateRawConfigVersion: typeof validateRawConfigVersion;
|
|
92
48
|
};
|
|
93
49
|
export {};
|
|
94
50
|
//# sourceMappingURL=CSpellSettingsServer.d.ts.map
|
|
@@ -19,293 +19,17 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.__testing__ = exports.extractDependencies = exports.
|
|
23
|
-
const json = __importStar(require("comment-json"));
|
|
24
|
-
const cosmiconfig_1 = require("cosmiconfig");
|
|
22
|
+
exports.__testing__ = exports.extractDependencies = exports.getSources = exports.checkFilenameMatchesGlob = exports.toInternalSettings = exports.finalizeSettings = exports.calcOverrideSettings = exports.mergeInDocSettings = exports.mergeSettings = exports.ENV_CSPELL_GLOB_ROOT = exports.currentSettingsFileVersion = exports.configSettingsFileVersion0_2 = exports.configSettingsFileVersion0_1 = void 0;
|
|
25
23
|
const cspell_glob_1 = require("cspell-glob");
|
|
26
24
|
const path = __importStar(require("path"));
|
|
27
|
-
const vscode_uri_1 = require("vscode-uri");
|
|
28
|
-
const logger_1 = require("../util/logger");
|
|
29
|
-
const resolveFile_1 = require("../util/resolveFile");
|
|
30
|
-
const util = __importStar(require("../util/util"));
|
|
31
25
|
const CSpellSettingsInternalDef_1 = require("../Models/CSpellSettingsInternalDef");
|
|
26
|
+
const util = __importStar(require("../util/util"));
|
|
32
27
|
const DictionarySettings_1 = require("./DictionarySettings");
|
|
33
|
-
const GlobalSettings_1 = require("./GlobalSettings");
|
|
34
|
-
const ImportError_1 = require("./ImportError");
|
|
35
28
|
const patterns_1 = require("./patterns");
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const configSettingsFileVersion0_2 = '0.2';
|
|
40
|
-
exports.currentSettingsFileVersion = configSettingsFileVersion0_2;
|
|
41
|
-
const setOfSupportedConfigVersions = new Set(supportedCSpellConfigVersions);
|
|
42
|
-
exports.sectionCSpell = 'cSpell';
|
|
43
|
-
exports.defaultFileName = 'cspell.json';
|
|
29
|
+
exports.configSettingsFileVersion0_1 = '0.1';
|
|
30
|
+
exports.configSettingsFileVersion0_2 = '0.2';
|
|
31
|
+
exports.currentSettingsFileVersion = exports.configSettingsFileVersion0_2;
|
|
44
32
|
exports.ENV_CSPELL_GLOB_ROOT = 'CSPELL_GLOB_ROOT';
|
|
45
|
-
/**
|
|
46
|
-
* Logic of the locations:
|
|
47
|
-
* - Support backward compatibility with the VS Code Spell Checker
|
|
48
|
-
* the spell checker extension can only write to `.json` files because
|
|
49
|
-
* it would be too difficult to automatically modify a `.js` or `.cjs` file.
|
|
50
|
-
* - To support `cspell.config.js` in a VS Code environment, have a `cspell.json` import
|
|
51
|
-
* the `cspell.config.js`.
|
|
52
|
-
*/
|
|
53
|
-
const searchPlaces = [
|
|
54
|
-
'package.json',
|
|
55
|
-
// Original locations
|
|
56
|
-
'.cspell.json',
|
|
57
|
-
'cspell.json',
|
|
58
|
-
'.cSpell.json',
|
|
59
|
-
'cSpell.json',
|
|
60
|
-
// Original locations jsonc
|
|
61
|
-
'.cspell.jsonc',
|
|
62
|
-
'cspell.jsonc',
|
|
63
|
-
// Alternate locations
|
|
64
|
-
'.vscode/cspell.json',
|
|
65
|
-
'.vscode/cSpell.json',
|
|
66
|
-
'.vscode/.cspell.json',
|
|
67
|
-
// Standard Locations
|
|
68
|
-
'cspell.config.json',
|
|
69
|
-
'cspell.config.jsonc',
|
|
70
|
-
'cspell.config.yaml',
|
|
71
|
-
'cspell.config.yml',
|
|
72
|
-
'cspell.yaml',
|
|
73
|
-
'cspell.yml',
|
|
74
|
-
// Dynamic config is looked for last
|
|
75
|
-
'cspell.config.js',
|
|
76
|
-
'cspell.config.cjs',
|
|
77
|
-
];
|
|
78
|
-
const cspellCosmiconfig = {
|
|
79
|
-
searchPlaces,
|
|
80
|
-
loaders: {
|
|
81
|
-
'.json': parseJson,
|
|
82
|
-
'.jsonc': parseJson,
|
|
83
|
-
},
|
|
84
|
-
};
|
|
85
|
-
function parseJson(_filename, content) {
|
|
86
|
-
return json.parse(content);
|
|
87
|
-
}
|
|
88
|
-
exports.defaultConfigFilenames = Object.freeze(searchPlaces.concat());
|
|
89
|
-
const cspellConfigExplorer = (0, cosmiconfig_1.cosmiconfig)('cspell', cspellCosmiconfig);
|
|
90
|
-
const cspellConfigExplorerSync = (0, cosmiconfig_1.cosmiconfigSync)('cspell', cspellCosmiconfig);
|
|
91
|
-
const defaultSettings = (0, CSpellSettingsInternalDef_1.createCSpellSettingsInternal)({
|
|
92
|
-
id: 'default',
|
|
93
|
-
name: 'default',
|
|
94
|
-
version: exports.currentSettingsFileVersion,
|
|
95
|
-
});
|
|
96
|
-
const defaultPnPSettings = {};
|
|
97
|
-
let globalSettings;
|
|
98
|
-
const cachedFiles = new Map();
|
|
99
|
-
/**
|
|
100
|
-
* Read a config file and inject the fileRef.
|
|
101
|
-
* @param fileRef - filename plus context, injected into the resulting config.
|
|
102
|
-
*/
|
|
103
|
-
function readConfig(fileRef) {
|
|
104
|
-
// cspellConfigExplorerSync
|
|
105
|
-
const { filename } = fileRef;
|
|
106
|
-
const s = {};
|
|
107
|
-
try {
|
|
108
|
-
const r = cspellConfigExplorerSync.load(filename);
|
|
109
|
-
if (!(r === null || r === void 0 ? void 0 : r.config))
|
|
110
|
-
throw new Error(`not found: "${filename}"`);
|
|
111
|
-
Object.assign(s, r.config);
|
|
112
|
-
normalizeRawConfig(s);
|
|
113
|
-
validateRawConfig(s, fileRef);
|
|
114
|
-
}
|
|
115
|
-
catch (err) {
|
|
116
|
-
fileRef.error =
|
|
117
|
-
err instanceof ImportError_1.ImportError ? err : new ImportError_1.ImportError(`Failed to read config file: "${filename}"`, err);
|
|
118
|
-
}
|
|
119
|
-
s.__importRef = fileRef;
|
|
120
|
-
return s;
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* normalizeSettings handles correcting all relative paths, anchoring globs, and importing other config files.
|
|
124
|
-
* @param rawSettings - raw configuration settings
|
|
125
|
-
* @param pathToSettingsFile - path to the source file of the configuration settings.
|
|
126
|
-
*/
|
|
127
|
-
function normalizeSettings(rawSettings, pathToSettingsFile, pnpSettings) {
|
|
128
|
-
const id = rawSettings.id ||
|
|
129
|
-
[path.basename(path.dirname(pathToSettingsFile)), path.basename(pathToSettingsFile)].join('/');
|
|
130
|
-
const name = rawSettings.name || id;
|
|
131
|
-
// Try to load any .pnp files before reading dictionaries or other config files.
|
|
132
|
-
const { usePnP = pnpSettings.usePnP, pnpFiles = pnpSettings.pnpFiles } = rawSettings;
|
|
133
|
-
const pnpSettingsToUse = {
|
|
134
|
-
usePnP,
|
|
135
|
-
pnpFiles,
|
|
136
|
-
};
|
|
137
|
-
const pathToSettingsDir = path.dirname(pathToSettingsFile);
|
|
138
|
-
loadPnPSync(pnpSettingsToUse, vscode_uri_1.URI.file(pathToSettingsDir));
|
|
139
|
-
// Fix up dictionaryDefinitions
|
|
140
|
-
const settings = {
|
|
141
|
-
version: defaultSettings.version,
|
|
142
|
-
...rawSettings,
|
|
143
|
-
id,
|
|
144
|
-
name,
|
|
145
|
-
globRoot: resolveGlobRoot(rawSettings, pathToSettingsFile),
|
|
146
|
-
languageSettings: normalizeLanguageSettings(rawSettings.languageSettings),
|
|
147
|
-
};
|
|
148
|
-
const pathToSettings = path.dirname(pathToSettingsFile);
|
|
149
|
-
const normalizedDictionaryDefs = normalizeDictionaryDefs(settings, pathToSettingsFile);
|
|
150
|
-
const normalizedSettingsGlobs = normalizeSettingsGlobs(settings, pathToSettingsFile);
|
|
151
|
-
const normalizedOverrides = normalizeOverrides(settings, pathToSettingsFile);
|
|
152
|
-
const normalizedReporters = normalizeReporters(settings, pathToSettingsFile);
|
|
153
|
-
const normalizedGitignoreRoot = normalizeGitignoreRoot(settings, pathToSettingsFile);
|
|
154
|
-
const normalizedCacheSettings = normalizeCacheSettings(settings, pathToSettingsDir);
|
|
155
|
-
const imports = typeof settings.import === 'string' ? [settings.import] : settings.import || [];
|
|
156
|
-
const source = settings.source || {
|
|
157
|
-
name: settings.name,
|
|
158
|
-
filename: pathToSettingsFile,
|
|
159
|
-
};
|
|
160
|
-
const fileSettings = (0, CSpellSettingsInternalDef_1.createCSpellSettingsInternal)({
|
|
161
|
-
...settings,
|
|
162
|
-
source,
|
|
163
|
-
...normalizedDictionaryDefs,
|
|
164
|
-
...normalizedSettingsGlobs,
|
|
165
|
-
...normalizedOverrides,
|
|
166
|
-
...normalizedReporters,
|
|
167
|
-
...normalizedGitignoreRoot,
|
|
168
|
-
...normalizedCacheSettings,
|
|
169
|
-
});
|
|
170
|
-
if (!imports.length) {
|
|
171
|
-
return fileSettings;
|
|
172
|
-
}
|
|
173
|
-
const importedSettings = imports
|
|
174
|
-
.map((name) => resolveFilename(name, pathToSettings))
|
|
175
|
-
.map((ref) => ((ref.referencedBy = [source]), ref))
|
|
176
|
-
.map((ref) => importSettings(ref, undefined, pnpSettingsToUse))
|
|
177
|
-
.reduce((a, b) => mergeSettings(a, b));
|
|
178
|
-
const finalizeSettings = mergeSettings(importedSettings, fileSettings);
|
|
179
|
-
finalizeSettings.name = settings.name || finalizeSettings.name || '';
|
|
180
|
-
finalizeSettings.id = settings.id || finalizeSettings.id || '';
|
|
181
|
-
return finalizeSettings;
|
|
182
|
-
}
|
|
183
|
-
function mergeSourceList(orig, append) {
|
|
184
|
-
const collection = new Map(orig.map((s) => [s.name + (s.filename || ''), s]));
|
|
185
|
-
for (const s of append || []) {
|
|
186
|
-
const key = s.name + (s.filename || '');
|
|
187
|
-
if (!collection.has(key)) {
|
|
188
|
-
collection.set(key, s);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
return [...collection.values()];
|
|
192
|
-
}
|
|
193
|
-
function importSettings(fileRef, defaultValues, pnpSettings) {
|
|
194
|
-
defaultValues = defaultValues !== null && defaultValues !== void 0 ? defaultValues : defaultSettings;
|
|
195
|
-
let { filename } = fileRef;
|
|
196
|
-
filename = path.resolve(filename);
|
|
197
|
-
const importRef = { ...fileRef, filename };
|
|
198
|
-
const cached = cachedFiles.get(filename);
|
|
199
|
-
if (cached) {
|
|
200
|
-
const cachedImportRef = cached.__importRef || importRef;
|
|
201
|
-
cachedImportRef.referencedBy = mergeSourceList(cachedImportRef.referencedBy || [], importRef.referencedBy);
|
|
202
|
-
cached.__importRef = cachedImportRef;
|
|
203
|
-
return cached;
|
|
204
|
-
}
|
|
205
|
-
const id = [path.basename(path.dirname(filename)), path.basename(filename)].join('/');
|
|
206
|
-
const name = id;
|
|
207
|
-
const finalizeSettings = (0, CSpellSettingsInternalDef_1.createCSpellSettingsInternal)({ id, name, __importRef: importRef });
|
|
208
|
-
cachedFiles.set(filename, finalizeSettings); // add an empty entry to prevent circular references.
|
|
209
|
-
const settings = { ...defaultValues, id, name, ...readConfig(importRef) };
|
|
210
|
-
Object.assign(finalizeSettings, normalizeSettings(settings, filename, pnpSettings));
|
|
211
|
-
const finalizeSrc = { name: path.basename(filename), ...finalizeSettings.source };
|
|
212
|
-
finalizeSettings.source = { ...finalizeSrc, filename };
|
|
213
|
-
cachedFiles.set(filename, finalizeSettings);
|
|
214
|
-
return finalizeSettings;
|
|
215
|
-
}
|
|
216
|
-
function readSettings(filename, relativeToOrDefault, defaultValue) {
|
|
217
|
-
const relativeTo = typeof relativeToOrDefault === 'string' ? relativeToOrDefault : process.cwd();
|
|
218
|
-
defaultValue = defaultValue || (typeof relativeToOrDefault !== 'string' ? relativeToOrDefault : undefined);
|
|
219
|
-
const ref = resolveFilename(filename, relativeTo);
|
|
220
|
-
return importSettings(ref, defaultValue, defaultValue || defaultPnPSettings);
|
|
221
|
-
}
|
|
222
|
-
exports.readSettings = readSettings;
|
|
223
|
-
async function normalizeSearchForConfigResult(searchPath, searchResult, pnpSettings) {
|
|
224
|
-
var _a;
|
|
225
|
-
let result;
|
|
226
|
-
let error;
|
|
227
|
-
try {
|
|
228
|
-
result = (await searchResult) || undefined;
|
|
229
|
-
}
|
|
230
|
-
catch (cause) {
|
|
231
|
-
error = new ImportError_1.ImportError(`Failed to find config file at: "${searchPath}"`, cause);
|
|
232
|
-
}
|
|
233
|
-
const filepath = result === null || result === void 0 ? void 0 : result.filepath;
|
|
234
|
-
if (filepath) {
|
|
235
|
-
const cached = cachedFiles.get(filepath);
|
|
236
|
-
if (cached) {
|
|
237
|
-
return {
|
|
238
|
-
config: cached,
|
|
239
|
-
filepath,
|
|
240
|
-
error,
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
const { config = (0, CSpellSettingsInternalDef_1.createCSpellSettingsInternal)({}) } = result || {};
|
|
245
|
-
const filename = (_a = result === null || result === void 0 ? void 0 : result.filepath) !== null && _a !== void 0 ? _a : searchPath;
|
|
246
|
-
const importRef = { filename: filename, error };
|
|
247
|
-
const id = [path.basename(path.dirname(filename)), path.basename(filename)].join('/');
|
|
248
|
-
const name = (result === null || result === void 0 ? void 0 : result.filepath) ? id : `Config not found: ${id}`;
|
|
249
|
-
const finalizeSettings = (0, CSpellSettingsInternalDef_1.createCSpellSettingsInternal)({ id, name, __importRef: importRef });
|
|
250
|
-
const settings = { id, ...config };
|
|
251
|
-
cachedFiles.set(filename, finalizeSettings); // add an empty entry to prevent circular references.
|
|
252
|
-
Object.assign(finalizeSettings, normalizeSettings(settings, filename, pnpSettings));
|
|
253
|
-
return {
|
|
254
|
-
config: finalizeSettings,
|
|
255
|
-
filepath,
|
|
256
|
-
error,
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
function searchForConfig(searchFrom, pnpSettings = defaultPnPSettings) {
|
|
260
|
-
return normalizeSearchForConfigResult(searchFrom || process.cwd(), cspellConfigExplorer.search(searchFrom), pnpSettings).then((r) => (r.filepath ? r.config : undefined));
|
|
261
|
-
}
|
|
262
|
-
exports.searchForConfig = searchForConfig;
|
|
263
|
-
/**
|
|
264
|
-
* Load a CSpell configuration files.
|
|
265
|
-
* @param file - path or package reference to load.
|
|
266
|
-
* @param pnpSettings - PnP settings
|
|
267
|
-
* @returns normalized CSpellSettings
|
|
268
|
-
*/
|
|
269
|
-
function loadConfig(file, pnpSettings = defaultPnPSettings) {
|
|
270
|
-
const cached = cachedFiles.get(path.resolve(file));
|
|
271
|
-
if (cached) {
|
|
272
|
-
return Promise.resolve(cached);
|
|
273
|
-
}
|
|
274
|
-
return normalizeSearchForConfigResult(file, cspellConfigExplorer.load(file), pnpSettings).then((r) => r.config);
|
|
275
|
-
}
|
|
276
|
-
exports.loadConfig = loadConfig;
|
|
277
|
-
function loadPnP(pnpSettings, searchFrom) {
|
|
278
|
-
if (!pnpSettings.usePnP) {
|
|
279
|
-
return Promise.resolve(undefined);
|
|
280
|
-
}
|
|
281
|
-
const loader = (0, pnpLoader_1.pnpLoader)(pnpSettings.pnpFiles);
|
|
282
|
-
return loader.load(searchFrom);
|
|
283
|
-
}
|
|
284
|
-
exports.loadPnP = loadPnP;
|
|
285
|
-
function loadPnPSync(pnpSettings, searchFrom) {
|
|
286
|
-
if (!pnpSettings.usePnP) {
|
|
287
|
-
return undefined;
|
|
288
|
-
}
|
|
289
|
-
const loader = (0, pnpLoader_1.pnpLoader)(pnpSettings.pnpFiles);
|
|
290
|
-
return loader.loadSync(searchFrom);
|
|
291
|
-
}
|
|
292
|
-
exports.loadPnPSync = loadPnPSync;
|
|
293
|
-
function readRawSettings(filename, relativeTo) {
|
|
294
|
-
relativeTo = relativeTo || process.cwd();
|
|
295
|
-
const ref = resolveFilename(filename, relativeTo);
|
|
296
|
-
return readConfig(ref);
|
|
297
|
-
}
|
|
298
|
-
exports.readRawSettings = readRawSettings;
|
|
299
|
-
/**
|
|
300
|
-
*
|
|
301
|
-
* @param filenames - settings files to read
|
|
302
|
-
* @returns combined configuration
|
|
303
|
-
* @deprecated true
|
|
304
|
-
*/
|
|
305
|
-
function readSettingsFiles(filenames) {
|
|
306
|
-
return filenames.map((filename) => readSettings(filename)).reduce((a, b) => mergeSettings(a, b), defaultSettings);
|
|
307
|
-
}
|
|
308
|
-
exports.readSettingsFiles = readSettingsFiles;
|
|
309
33
|
function mergeListUnique(left, right) {
|
|
310
34
|
if (left === undefined)
|
|
311
35
|
return right;
|
|
@@ -319,6 +43,23 @@ function mergeList(left, right) {
|
|
|
319
43
|
return right;
|
|
320
44
|
if (right === undefined)
|
|
321
45
|
return left;
|
|
46
|
+
if (!left.length)
|
|
47
|
+
return right;
|
|
48
|
+
if (!right.length)
|
|
49
|
+
return left;
|
|
50
|
+
return left.concat(right);
|
|
51
|
+
}
|
|
52
|
+
const emptyWords = [];
|
|
53
|
+
Object.freeze(emptyWords);
|
|
54
|
+
function mergeWordsCached(left, right) {
|
|
55
|
+
if (left === undefined)
|
|
56
|
+
return !right || right.length ? right : emptyWords;
|
|
57
|
+
if (right === undefined)
|
|
58
|
+
return !left || left.length ? left : emptyWords;
|
|
59
|
+
if (!left.length)
|
|
60
|
+
return !right || right.length ? right : emptyWords;
|
|
61
|
+
if (!right.length)
|
|
62
|
+
return !left || left.length ? left : emptyWords;
|
|
322
63
|
return left.concat(right);
|
|
323
64
|
}
|
|
324
65
|
function mergeObjects(left, right) {
|
|
@@ -380,10 +121,10 @@ function merge(left, right) {
|
|
|
380
121
|
version,
|
|
381
122
|
id: [leftId, rightId].join('|'),
|
|
382
123
|
name: [_left.name || '', _right.name || ''].join('|'),
|
|
383
|
-
words:
|
|
384
|
-
userWords:
|
|
385
|
-
flagWords:
|
|
386
|
-
ignoreWords:
|
|
124
|
+
words: mergeWordsCached(_left.words, _right.words),
|
|
125
|
+
userWords: mergeWordsCached(_left.userWords, _right.userWords),
|
|
126
|
+
flagWords: mergeWordsCached(_left.flagWords, _right.flagWords),
|
|
127
|
+
ignoreWords: mergeWordsCached(_left.ignoreWords, _right.ignoreWords),
|
|
387
128
|
enabledLanguageIds: replaceIfNotEmpty(_left.enabledLanguageIds, _right.enabledLanguageIds),
|
|
388
129
|
enableFiletypes: mergeList(_left.enableFiletypes, _right.enableFiletypes),
|
|
389
130
|
ignoreRegExpList: mergeListUnique(_left.ignoreRegExpList, _right.ignoreRegExpList),
|
|
@@ -407,7 +148,7 @@ function merge(left, right) {
|
|
|
407
148
|
return settings;
|
|
408
149
|
}
|
|
409
150
|
function versionBasedMergeList(left, right, version) {
|
|
410
|
-
if (version === configSettingsFileVersion0_1) {
|
|
151
|
+
if (version === exports.configSettingsFileVersion0_1) {
|
|
411
152
|
return takeRightOtherwiseLeft(left, right);
|
|
412
153
|
}
|
|
413
154
|
return mergeListUnique(left, right);
|
|
@@ -498,35 +239,6 @@ exports.toInternalSettings = toInternalSettings;
|
|
|
498
239
|
function filenameToDirectory(filename) {
|
|
499
240
|
return filename ? path.dirname(filename) : undefined;
|
|
500
241
|
}
|
|
501
|
-
function resolveFilename(filename, relativeTo) {
|
|
502
|
-
const r = (0, resolveFile_1.resolveFile)(filename, relativeTo);
|
|
503
|
-
return {
|
|
504
|
-
filename: r.filename,
|
|
505
|
-
error: r.found ? undefined : new Error(`Failed to resolve file: "${filename}"`),
|
|
506
|
-
};
|
|
507
|
-
}
|
|
508
|
-
function getGlobalSettings() {
|
|
509
|
-
if (!globalSettings) {
|
|
510
|
-
const globalConf = (0, GlobalSettings_1.getRawGlobalSettings)();
|
|
511
|
-
globalSettings = {
|
|
512
|
-
id: 'global_config',
|
|
513
|
-
...normalizeSettings(globalConf || {}, './global_config', {}),
|
|
514
|
-
};
|
|
515
|
-
}
|
|
516
|
-
return globalSettings;
|
|
517
|
-
}
|
|
518
|
-
exports.getGlobalSettings = getGlobalSettings;
|
|
519
|
-
function getCachedFileSize() {
|
|
520
|
-
return cachedFiles.size;
|
|
521
|
-
}
|
|
522
|
-
exports.getCachedFileSize = getCachedFileSize;
|
|
523
|
-
function clearCachedSettingsFiles() {
|
|
524
|
-
globalSettings = undefined;
|
|
525
|
-
cachedFiles.clear();
|
|
526
|
-
cspellConfigExplorer.clearCaches();
|
|
527
|
-
cspellConfigExplorerSync.clearCaches();
|
|
528
|
-
}
|
|
529
|
-
exports.clearCachedSettingsFiles = clearCachedSettingsFiles;
|
|
530
242
|
/**
|
|
531
243
|
* @param filename - filename
|
|
532
244
|
* @param globs - globs
|
|
@@ -591,14 +303,6 @@ function mergeImportRefs(left, right = {}) {
|
|
|
591
303
|
}
|
|
592
304
|
return imports.size ? imports : undefined;
|
|
593
305
|
}
|
|
594
|
-
function isImportFileRefWithError(ref) {
|
|
595
|
-
return !!ref.error;
|
|
596
|
-
}
|
|
597
|
-
function extractImportErrors(settings) {
|
|
598
|
-
const imports = mergeImportRefs(settings);
|
|
599
|
-
return !imports ? [] : [...imports.values()].filter(isImportFileRefWithError);
|
|
600
|
-
}
|
|
601
|
-
exports.extractImportErrors = extractImportErrors;
|
|
602
306
|
function extractDependencies(settings) {
|
|
603
307
|
const settingsI = toInternalSettings(settings);
|
|
604
308
|
const configFiles = [...(mergeImportRefs(settingsI) || [])].map(([filename]) => filename);
|
|
@@ -614,172 +318,7 @@ function resolveCwd() {
|
|
|
614
318
|
const cwd = envGlobRoot || process.cwd();
|
|
615
319
|
return cwd;
|
|
616
320
|
}
|
|
617
|
-
function resolveGlobRoot(settings, pathToSettingsFile) {
|
|
618
|
-
var _a;
|
|
619
|
-
const settingsFileDirRaw = path.dirname(pathToSettingsFile);
|
|
620
|
-
const isVSCode = path.basename(settingsFileDirRaw) === '.vscode';
|
|
621
|
-
const settingsFileDir = isVSCode ? path.dirname(settingsFileDirRaw) : settingsFileDirRaw;
|
|
622
|
-
const envGlobRoot = process.env[exports.ENV_CSPELL_GLOB_ROOT];
|
|
623
|
-
const defaultGlobRoot = envGlobRoot !== null && envGlobRoot !== void 0 ? envGlobRoot : '${cwd}';
|
|
624
|
-
const rawRoot = (_a = settings.globRoot) !== null && _a !== void 0 ? _a : (settings.version === configSettingsFileVersion0_1 ||
|
|
625
|
-
(envGlobRoot && !settings.version) ||
|
|
626
|
-
(isVSCode && !settings.version)
|
|
627
|
-
? defaultGlobRoot
|
|
628
|
-
: settingsFileDir);
|
|
629
|
-
const globRoot = rawRoot.startsWith('${cwd}') ? rawRoot : path.resolve(settingsFileDir, rawRoot);
|
|
630
|
-
return globRoot;
|
|
631
|
-
}
|
|
632
|
-
function resolveFilePath(filename, pathToSettingsFile) {
|
|
633
|
-
const cwd = process.cwd();
|
|
634
|
-
return path.resolve(pathToSettingsFile, filename.replace('${cwd}', cwd));
|
|
635
|
-
}
|
|
636
|
-
function toGlobDef(g, root, source) {
|
|
637
|
-
if (g === undefined)
|
|
638
|
-
return undefined;
|
|
639
|
-
if (Array.isArray(g)) {
|
|
640
|
-
return g.map((g) => toGlobDef(g, root, source));
|
|
641
|
-
}
|
|
642
|
-
if (typeof g === 'string') {
|
|
643
|
-
return toGlobDef({
|
|
644
|
-
glob: g,
|
|
645
|
-
root,
|
|
646
|
-
}, root, source);
|
|
647
|
-
}
|
|
648
|
-
if (source) {
|
|
649
|
-
return { ...g, source };
|
|
650
|
-
}
|
|
651
|
-
return g;
|
|
652
|
-
}
|
|
653
|
-
function normalizeDictionaryDefs(settings, pathToSettingsFile) {
|
|
654
|
-
var _a;
|
|
655
|
-
const dictionaryDefinitions = (0, DictionarySettings_1.mapDictDefsToInternal)(settings.dictionaryDefinitions, pathToSettingsFile);
|
|
656
|
-
const languageSettings = (_a = settings.languageSettings) === null || _a === void 0 ? void 0 : _a.map((langSetting) => util.clean({
|
|
657
|
-
...langSetting,
|
|
658
|
-
dictionaryDefinitions: (0, DictionarySettings_1.mapDictDefsToInternal)(langSetting.dictionaryDefinitions, pathToSettingsFile),
|
|
659
|
-
}));
|
|
660
|
-
return util.clean({
|
|
661
|
-
dictionaryDefinitions,
|
|
662
|
-
languageSettings,
|
|
663
|
-
});
|
|
664
|
-
}
|
|
665
|
-
function normalizeOverrides(settings, pathToSettingsFile) {
|
|
666
|
-
var _a;
|
|
667
|
-
const { globRoot = path.dirname(pathToSettingsFile) } = settings;
|
|
668
|
-
const overrides = (_a = settings.overrides) === null || _a === void 0 ? void 0 : _a.map((override) => {
|
|
669
|
-
const filename = toGlobDef(override.filename, globRoot, pathToSettingsFile);
|
|
670
|
-
const { dictionaryDefinitions, languageSettings } = normalizeDictionaryDefs(override, pathToSettingsFile);
|
|
671
|
-
return util.clean({
|
|
672
|
-
...override,
|
|
673
|
-
filename,
|
|
674
|
-
dictionaryDefinitions,
|
|
675
|
-
languageSettings: normalizeLanguageSettings(languageSettings),
|
|
676
|
-
});
|
|
677
|
-
});
|
|
678
|
-
return overrides ? { overrides } : {};
|
|
679
|
-
}
|
|
680
|
-
function normalizeReporters(settings, pathToSettingsFile) {
|
|
681
|
-
if (settings.reporters === undefined)
|
|
682
|
-
return {};
|
|
683
|
-
const folder = path.dirname(pathToSettingsFile);
|
|
684
|
-
function resolve(s) {
|
|
685
|
-
const r = (0, resolveFile_1.resolveFile)(s, folder);
|
|
686
|
-
if (!r.found) {
|
|
687
|
-
throw new Error(`Not found: "${s}"`);
|
|
688
|
-
}
|
|
689
|
-
return r.filename;
|
|
690
|
-
}
|
|
691
|
-
function resolveReporter(s) {
|
|
692
|
-
if (typeof s === 'string') {
|
|
693
|
-
return resolve(s);
|
|
694
|
-
}
|
|
695
|
-
if (!Array.isArray(s) || typeof s[0] !== 'string')
|
|
696
|
-
throw new Error('Invalid Reporter');
|
|
697
|
-
// Preserve the shape of Reporter Setting while resolving the reporter file.
|
|
698
|
-
const [r, ...rest] = s;
|
|
699
|
-
return [resolve(r), ...rest];
|
|
700
|
-
}
|
|
701
|
-
return {
|
|
702
|
-
reporters: settings.reporters.map(resolveReporter),
|
|
703
|
-
};
|
|
704
|
-
}
|
|
705
|
-
function normalizeLanguageSettings(languageSettings) {
|
|
706
|
-
if (!languageSettings)
|
|
707
|
-
return undefined;
|
|
708
|
-
function fixLocale(s) {
|
|
709
|
-
const { local: locale, ...rest } = s;
|
|
710
|
-
return { locale, ...rest };
|
|
711
|
-
}
|
|
712
|
-
return languageSettings.map(fixLocale);
|
|
713
|
-
}
|
|
714
|
-
function normalizeGitignoreRoot(settings, pathToSettingsFile) {
|
|
715
|
-
const { gitignoreRoot } = settings;
|
|
716
|
-
if (!gitignoreRoot)
|
|
717
|
-
return {};
|
|
718
|
-
const dir = path.dirname(pathToSettingsFile);
|
|
719
|
-
const roots = Array.isArray(gitignoreRoot) ? gitignoreRoot : [gitignoreRoot];
|
|
720
|
-
return {
|
|
721
|
-
gitignoreRoot: roots.map((p) => path.resolve(dir, p)),
|
|
722
|
-
};
|
|
723
|
-
}
|
|
724
|
-
function normalizeSettingsGlobs(settings, pathToSettingsFile) {
|
|
725
|
-
const { globRoot } = settings;
|
|
726
|
-
if (settings.ignorePaths === undefined)
|
|
727
|
-
return {};
|
|
728
|
-
const ignorePaths = toGlobDef(settings.ignorePaths, globRoot, pathToSettingsFile);
|
|
729
|
-
return {
|
|
730
|
-
ignorePaths,
|
|
731
|
-
};
|
|
732
|
-
}
|
|
733
|
-
function normalizeCacheSettings(settings, pathToSettingsDir) {
|
|
734
|
-
const { cache } = settings;
|
|
735
|
-
if (cache === undefined)
|
|
736
|
-
return {};
|
|
737
|
-
const { cacheLocation } = cache;
|
|
738
|
-
if (cacheLocation === undefined)
|
|
739
|
-
return { cache };
|
|
740
|
-
return { cache: { ...cache, cacheLocation: resolveFilePath(cacheLocation, pathToSettingsDir) } };
|
|
741
|
-
}
|
|
742
|
-
function validationMessage(msg, fileRef) {
|
|
743
|
-
return msg + `\n File: "${fileRef.filename}"`;
|
|
744
|
-
}
|
|
745
|
-
function validateRawConfigVersion(config, fileRef) {
|
|
746
|
-
const { version } = config;
|
|
747
|
-
if (version === undefined)
|
|
748
|
-
return;
|
|
749
|
-
if (typeof version !== 'string') {
|
|
750
|
-
(0, logger_1.logError)(validationMessage(`Unsupported config file version: "${version}", string expected`, fileRef));
|
|
751
|
-
return;
|
|
752
|
-
}
|
|
753
|
-
if (setOfSupportedConfigVersions.has(version))
|
|
754
|
-
return;
|
|
755
|
-
if (!/^\d+(\.\d+)*$/.test(version)) {
|
|
756
|
-
(0, logger_1.logError)(validationMessage(`Unsupported config file version: "${version}"`, fileRef));
|
|
757
|
-
return;
|
|
758
|
-
}
|
|
759
|
-
const msg = version > exports.currentSettingsFileVersion
|
|
760
|
-
? `Newer config file version found: "${version}". Supported version is "${exports.currentSettingsFileVersion}"`
|
|
761
|
-
: `Legacy config file version found: "${version}", upgrade to "${exports.currentSettingsFileVersion}"`;
|
|
762
|
-
(0, logger_1.logWarning)(validationMessage(msg, fileRef));
|
|
763
|
-
}
|
|
764
|
-
function validateRawConfigExports(config, fileRef) {
|
|
765
|
-
if (config.default) {
|
|
766
|
-
throw new ImportError_1.ImportError(validationMessage('Module `export default` is not supported.\n Use `module.exports =` instead.', fileRef));
|
|
767
|
-
}
|
|
768
|
-
}
|
|
769
|
-
function normalizeRawConfig(config) {
|
|
770
|
-
if (typeof config.version === 'number') {
|
|
771
|
-
config.version = config.version.toString();
|
|
772
|
-
}
|
|
773
|
-
}
|
|
774
|
-
function validateRawConfig(config, fileRef) {
|
|
775
|
-
const validations = [validateRawConfigExports, validateRawConfigVersion];
|
|
776
|
-
validations.forEach((fn) => fn(config, fileRef));
|
|
777
|
-
}
|
|
778
321
|
exports.__testing__ = {
|
|
779
322
|
mergeObjects,
|
|
780
|
-
normalizeCacheSettings,
|
|
781
|
-
normalizeSettings,
|
|
782
|
-
validateRawConfigExports,
|
|
783
|
-
validateRawConfigVersion,
|
|
784
323
|
};
|
|
785
324
|
//# sourceMappingURL=CSpellSettingsServer.js.map
|