/
DefaultSettings.ts
155 lines (140 loc) · 5.43 KB
/
DefaultSettings.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import type { PredefinedPatterns, RegExpPatternDefinition } from '@cspell/cspell-types';
import { createCSpellSettingsInternal, CSpellSettingsInternal } from '../Models/CSpellSettingsInternalDef';
import { resolveFile } from '../util/resolveFile';
import { readSettings } from './configLoader';
import { mergeSettings } from './index';
import * as LanguageSettings from './LanguageSettings';
import * as RegPat from './RegExpPatterns';
const defaultConfigFileModuleRef = '@cspell/cspell-bundled-dicts/cspell-default.json';
// Do not use require.resolve because webpack will mess it up.
const defaultConfigFile = resolveConfigModule(defaultConfigFileModuleRef);
const regExpSpellCheckerDisable = [
RegPat.regExSpellingGuardBlock,
RegPat.regExSpellingGuardLine,
RegPat.regExSpellingGuardNext,
];
// cspell:ignore filetypes
const predefinedPatterns = [
// Exclude patterns
{ name: 'CommitHash', pattern: RegPat.regExCommitHash },
{ name: 'CommitHashLink', pattern: RegPat.regExCommitHashLink },
{ name: 'CStyleHexValue', pattern: RegPat.regExCStyleHexValue },
{ name: 'CSSHexValue', pattern: RegPat.regExCSSHexValue },
{ name: 'Urls', pattern: RegPat.regExMatchUrls },
{ name: 'HexValues', pattern: RegPat.regExMatchCommonHexFormats },
{ name: 'SpellCheckerDisable', pattern: regExpSpellCheckerDisable },
{ name: 'PublicKey', pattern: RegPat.regExPublicKey },
{ name: 'RsaCert', pattern: RegPat.regExCert },
{ name: 'SshRsa', pattern: RegPat.regExSshRSA },
{ name: 'EscapeCharacters', pattern: RegPat.regExEscapeCharacters },
{ name: 'Base64', pattern: RegPat.regExBase64 },
{ name: 'Base64SingleLine', pattern: RegPat.regExBase64SingleLine },
{ name: 'Base64MultiLine', pattern: RegPat.regExBase64MultiLine },
{ name: 'Email', pattern: RegPat.regExEmail },
{ name: 'SHA', pattern: RegPat.regExSha },
{ name: 'HashStrings', pattern: RegPat.regExHashStrings },
{ name: 'UnicodeRef', pattern: RegPat.regExUnicodeRef },
{ name: 'UUID', pattern: RegPat.regExUUID },
{ name: 'href', pattern: RegPat.regExHRef },
{ name: 'SpellCheckerDisableBlock', pattern: RegPat.regExSpellingGuardBlock },
{ name: 'SpellCheckerDisableLine', pattern: RegPat.regExSpellingGuardLine },
{ name: 'SpellCheckerDisableNext', pattern: RegPat.regExSpellingGuardNext },
{ name: 'SpellCheckerIgnoreInDocSetting', pattern: RegPat.regExIgnoreSpellingDirectives },
// Include Patterns
{ name: 'PhpHereDoc', pattern: RegPat.regExPhpHereDoc },
{ name: 'string', pattern: RegPat.regExString },
{ name: 'CStyleComment', pattern: RegPat.regExCStyleComments },
{ name: 'Everything', pattern: '.*' },
] as const;
type NameType<T> = T extends readonly { name: infer U }[] ? U : never;
type ExtendsType<T, U> = T extends U ? T : never;
type PredefinedPatternNames = ExtendsType<NameType<typeof predefinedPatterns>, PredefinedPatterns>;
const defaultRegExpPatterns: RegExpPatternDefinition[] = [...predefinedPatterns];
const definedDefaultRegExpExcludeList: PredefinedPatterns[] = [
'SpellCheckerDisable',
'SpellCheckerIgnoreInDocSetting',
'Urls',
'Email',
'RsaCert',
'SshRsa',
'Base64MultiLine',
'Base64SingleLine',
'CommitHash',
'CommitHashLink',
'CStyleHexValue',
'CSSHexValue',
'SHA',
'HashStrings',
'UnicodeRef',
'UUID',
];
// This bit of copying is done to have the complier ensure that the defaults exist.
const defaultRegExpExcludeList: PredefinedPatternNames[] = definedDefaultRegExpExcludeList;
export const _defaultSettings: Readonly<CSpellSettingsInternal> = Object.freeze(
createCSpellSettingsInternal({
id: 'static_defaults',
language: 'en',
name: 'Static Defaults',
enabled: true,
enabledLanguageIds: [
'ada',
'csharp',
'go',
'javascript',
'javascriptreact',
'json',
'markdown',
'mdx',
'php',
'plaintext',
'python',
'text',
'typescript',
'typescriptreact',
'haskell',
'html',
'css',
'less',
'scss',
'latex',
'ruby',
'rust',
'shellscript',
'toml',
],
maxNumberOfProblems: 100,
numSuggestions: 10,
suggestionsTimeout: 500,
suggestionNumChanges: 3,
words: [],
userWords: [],
ignorePaths: [],
allowCompoundWords: false,
patterns: defaultRegExpPatterns,
ignoreRegExpList: defaultRegExpExcludeList,
languageSettings: LanguageSettings.getDefaultLanguageSettings(),
source: { name: 'defaultSettings' },
reporters: [],
})
);
const getSettings = (function () {
let settings: CSpellSettingsInternal | undefined = undefined;
return function () {
if (!settings) {
const jsonSettings = readSettings(defaultConfigFile);
settings = mergeSettings(_defaultSettings, jsonSettings);
if (jsonSettings.name !== undefined) {
settings.name = jsonSettings.name;
} else {
delete settings.name;
}
}
return settings;
};
})();
function resolveConfigModule(configModuleName: string) {
return resolveFile(configModuleName, __dirname).filename;
}
export function getDefaultSettings(): CSpellSettingsInternal {
return getSettings();
}