cspell-lib 9.4.0 → 9.6.1

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.
Files changed (115) hide show
  1. package/README.md +6 -6
  2. package/dist/cspell-rpc/api.d.ts +28 -0
  3. package/dist/cspell-rpc/api.js +6 -0
  4. package/dist/cspell-rpc/client.d.ts +17 -0
  5. package/dist/cspell-rpc/client.js +20 -0
  6. package/dist/cspell-rpc/index.d.ts +7 -0
  7. package/dist/cspell-rpc/index.js +4 -0
  8. package/dist/cspell-rpc/server.d.ts +16 -0
  9. package/dist/cspell-rpc/server.js +37 -0
  10. package/dist/cspell-rpc/spellCheckFile.d.ts +2 -0
  11. package/dist/cspell-rpc/spellCheckFile.js +2 -0
  12. package/dist/index.d.ts +2 -0
  13. package/dist/index.js +2 -0
  14. package/dist/lib/Settings/CSpellSettingsServer.d.ts +4 -2
  15. package/dist/lib/Settings/CSpellSettingsServer.js +10 -2
  16. package/dist/lib/Settings/Controller/ImportError.js +3 -0
  17. package/dist/lib/Settings/Controller/configLoader/configLoader.d.ts +6 -4
  18. package/dist/lib/Settings/Controller/configLoader/configLoader.js +12 -6
  19. package/dist/lib/Settings/Controller/configLoader/configLocations.js +1 -0
  20. package/dist/lib/Settings/Controller/configLoader/defaultSettings.js +1 -1
  21. package/dist/lib/Settings/Controller/configLoader/normalizeRawSettings.js +1 -1
  22. package/dist/lib/Settings/Controller/configLoader/types.d.ts +1 -1
  23. package/dist/lib/Settings/DefaultSettings.d.ts +1 -1
  24. package/dist/lib/Settings/DefaultSettings.js +1 -1
  25. package/dist/lib/Settings/InDocSettings.d.ts +0 -3
  26. package/dist/lib/Settings/InDocSettings.js +2 -3
  27. package/dist/lib/Settings/LanguageSettings.js +3 -3
  28. package/dist/lib/Settings/RegExpPatterns.js +2 -2
  29. package/dist/lib/Settings/TextDocumentSettings.d.ts +1 -1
  30. package/dist/lib/Settings/cfgStore.d.ts +1 -1
  31. package/dist/lib/Settings/index.d.ts +3 -1
  32. package/dist/lib/Settings/index.js +2 -1
  33. package/dist/lib/Settings/internal/CSpellSettingsInternalDef.d.ts +18 -0
  34. package/dist/lib/{Models → Settings/internal}/CSpellSettingsInternalDef.js +1 -10
  35. package/dist/lib/Settings/{DictionarySettings.d.ts → internal/DictionarySettings.d.ts} +3 -2
  36. package/dist/lib/Settings/{DictionarySettings.js → internal/DictionarySettings.js} +20 -10
  37. package/dist/lib/{Models/CSpellSettingsInternalDef.d.ts → Settings/internal/InternalDictionaryDef.d.ts} +2 -17
  38. package/dist/lib/Settings/internal/InternalDictionaryDef.js +10 -0
  39. package/dist/lib/Settings/internal/index.d.ts +6 -0
  40. package/dist/lib/Settings/internal/index.js +4 -0
  41. package/dist/lib/Settings/link.js +1 -1
  42. package/dist/lib/Settings/mergeCache.d.ts +1 -1
  43. package/dist/lib/Settings/mergeList.d.ts +1 -1
  44. package/dist/lib/Settings/sanitizeSettings.d.ts +11 -0
  45. package/dist/lib/Settings/sanitizeSettings.js +254 -0
  46. package/dist/lib/Settings/util/settingsToJson.d.ts +28 -0
  47. package/dist/lib/Settings/util/settingsToJson.js +125 -0
  48. package/dist/lib/SpellingDictionary/Dictionaries.d.ts +1 -1
  49. package/dist/lib/SpellingDictionary/Dictionaries.js +1 -1
  50. package/dist/lib/SpellingDictionary/DictionaryController/DictionaryLoader.d.ts +1 -1
  51. package/dist/lib/SpellingDictionary/DictionaryController/DictionaryLoader.js +115 -28
  52. package/dist/lib/SpellingDictionary/DictionaryLoader.d.ts +1 -1
  53. package/dist/lib/index.d.ts +2 -2
  54. package/dist/lib/index.js +2 -2
  55. package/dist/lib/perf/index.d.ts +1 -0
  56. package/dist/lib/perf/index.js +1 -0
  57. package/dist/lib/spellCheckFile.d.ts +11 -1
  58. package/dist/lib/spellCheckFile.js +24 -4
  59. package/dist/lib/suggestions.d.ts +1 -1
  60. package/dist/lib/suggestions.js +3 -3
  61. package/dist/lib/textValidation/cleanValidationIssue.d.ts +3 -0
  62. package/dist/lib/textValidation/cleanValidationIssue.js +21 -0
  63. package/dist/lib/textValidation/determineTextDocumentSettings.d.ts +1 -1
  64. package/dist/lib/textValidation/docValidator.d.ts +6 -3
  65. package/dist/lib/textValidation/docValidator.js +29 -6
  66. package/dist/lib/textValidation/isRandomString.d.ts +1 -1
  67. package/dist/lib/textValidation/lineValidatorFactory.js +13 -5
  68. package/dist/lib/textValidation/settingsToValidateOptions.d.ts +1 -1
  69. package/dist/lib/textValidation/traceWord.d.ts +1 -0
  70. package/dist/lib/textValidation/traceWord.js +1 -0
  71. package/dist/lib/trace.d.ts +2 -1
  72. package/dist/lib/trace.js +2 -2
  73. package/dist/lib/util/clone.d.ts +35 -0
  74. package/dist/lib/util/clone.js +76 -0
  75. package/dist/lib/util/errors.js +1 -1
  76. package/dist/lib/util/memoizeLastCall.d.ts +13 -0
  77. package/dist/lib/util/{memorizeLastCall.js → memoizeLastCall.js} +2 -2
  78. package/dist/lib/util/memoizeWeak.d.ts +6 -0
  79. package/dist/lib/util/{memorizerWeak.js → memoizeWeak.js} +2 -2
  80. package/dist/lib/util/text.js +6 -4
  81. package/dist/lib/util/textRegex.d.ts +2 -2
  82. package/dist/lib/util/textRegex.js +2 -2
  83. package/dist/rpc/Future.d.ts +18 -0
  84. package/dist/rpc/Future.js +49 -0
  85. package/dist/rpc/MessagePortEvents.d.ts +56 -0
  86. package/dist/rpc/MessagePortEvents.js +94 -0
  87. package/dist/rpc/assert.d.ts +14 -0
  88. package/dist/rpc/assert.js +21 -0
  89. package/dist/rpc/client.d.ts +186 -0
  90. package/dist/rpc/client.js +364 -0
  91. package/dist/rpc/errors.d.ts +24 -0
  92. package/dist/rpc/errors.js +47 -0
  93. package/dist/rpc/index.d.ts +11 -0
  94. package/dist/rpc/index.js +6 -0
  95. package/dist/rpc/messagePort.d.ts +34 -0
  96. package/dist/rpc/messagePort.js +2 -0
  97. package/dist/rpc/models.d.ts +134 -0
  98. package/dist/rpc/models.js +2 -0
  99. package/dist/rpc/modelsHelpers.d.ts +56 -0
  100. package/dist/rpc/modelsHelpers.js +117 -0
  101. package/dist/rpc/notify.d.ts +79 -0
  102. package/dist/rpc/notify.js +135 -0
  103. package/dist/rpc/protocol.d.ts +21 -0
  104. package/dist/rpc/protocol.js +17 -0
  105. package/dist/rpc/server.d.ts +39 -0
  106. package/dist/rpc/server.js +146 -0
  107. package/dist/rpc/types.d.ts +9 -0
  108. package/dist/rpc/types.js +2 -0
  109. package/dist/rpc.d.ts +2 -0
  110. package/dist/rpc.js +2 -0
  111. package/package.json +41 -26
  112. package/dist/lib/perf/perf.d.ts +0 -20
  113. package/dist/lib/perf/perf.js +0 -32
  114. package/dist/lib/util/memorizeLastCall.d.ts +0 -13
  115. package/dist/lib/util/memorizerWeak.d.ts +0 -6
package/README.md CHANGED
@@ -6,13 +6,13 @@
6
6
 
7
7
  <!--- @@inject: ../../static/sponsor.md --->
8
8
 
9
- - [![GitHub Sponsors](https://img.shields.io/badge/-black?style=social&logo=githubsponsors&label=GitHub%20Sponsor%3A%20Street%20Side%20Software)](https://github.com/sponsors/streetsidesoftware)
10
- - [![PayPal](https://img.shields.io/badge/-black?style=social&logo=paypal&label=PayPal%20Donate%3A%20Street%20Side%20Software)](https://www.paypal.com/donate/?hosted_button_id=26LNBP2Q6MKCY)
11
- - [![Open Collective](https://img.shields.io/badge/-black?style=social&logo=opencollective&label=Open%20Collective%3A%20CSpell)](https://opencollective.com/cspell)
9
+ [![GitHub Sponsors](https://img.shields.io/badge/-Street_Side_Software-black?style=for-the-badge&logo=githubsponsors&label=GitHub%20Sponsor%3A)](https://github.com/sponsors/streetsidesoftware)
12
10
 
13
- <!---
14
- - [![Patreon](https://img.shields.io/badge/-black?style=social&logo=patreon&label=Patreon%3A%20Street%20Side%20Software)](https://patreon.com/streetsidesoftware)
15
- --->
11
+ [![Open Collective](https://img.shields.io/badge/-CSpell-black?style=for-the-badge&logo=opencollective&label=Open%20Collective%3A)](https://opencollective.com/cspell)
12
+
13
+ [![Street Side Software](https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2Fstreetsidesoftware%2Fcspell%2Frefs%2Fheads%2Fmain%2Fstatic%2Fcspell-badge.json)](https://streetsidesoftware.com/sponsor/)
14
+
15
+ [![PayPal](https://img.shields.io/badge/-Street_Side_Software-black?style=for-the-badge&logo=paypal&label=PayPal%20Donate%3A)](https://www.paypal.com/donate/?hosted_button_id=26LNBP2Q6MKCY)
16
16
 
17
17
  <!--- @@inject-end: ../../static/sponsor.md --->
18
18
 
@@ -0,0 +1,28 @@
1
+ import type { spellCheckDocumentRPC } from './spellCheckFile.js';
2
+ export interface CSpellRPCApi {
3
+ spellCheckDocument: typeof spellCheckDocumentRPC;
4
+ /**
5
+ * Sleeps for the given number of milliseconds.
6
+ *
7
+ * **Note:** This is primarily for testing purposes.
8
+ *
9
+ * @param ms - The number of milliseconds to sleep.
10
+ * @returns A promise that resolves with the number of milliseconds slept.
11
+ */
12
+ sleep: (ms: number) => Promise<number>;
13
+ /**
14
+ * Returns the given message.
15
+ *
16
+ * **Note:** This is primarily for testing purposes.
17
+ *
18
+ * @param msg - The message to echo.
19
+ * @returns A promise that resolves with the given message.
20
+ */
21
+ echo: (msg: string) => Promise<string>;
22
+ }
23
+ export type CSpellRPCApiMethodNames = keyof CSpellRPCApi;
24
+ export type CSpellRPCApiEndpointNames = {
25
+ [K in CSpellRPCApiMethodNames]: K;
26
+ };
27
+ export declare const CSPELL_RPC_API_ENDPOINTS: CSpellRPCApiEndpointNames;
28
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1,6 @@
1
+ export const CSPELL_RPC_API_ENDPOINTS = {
2
+ spellCheckDocument: 'spellCheckDocument',
3
+ sleep: 'sleep',
4
+ echo: 'echo',
5
+ };
6
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1,17 @@
1
+ import type { RPCClientConfiguration, RPCClientOptions, RPCProtocol } from '../rpc/index.js';
2
+ import { RPCClient } from '../rpc/index.js';
3
+ import type { CSpellRPCApi } from './api.js';
4
+ export type { MessagePortLike } from '../rpc/index.js';
5
+ export type CSpellRPCClientOptions = RPCClientOptions;
6
+ export type CSpellRPCClientConfig = RPCClientConfiguration;
7
+ export declare class CSpellRPCClient extends RPCClient<CSpellRPCApi> {
8
+ constructor(config: CSpellRPCClientConfig);
9
+ getApi(): RPCProtocol<CSpellRPCApi>;
10
+ }
11
+ /**
12
+ * Create a CSpell RPC Client.
13
+ * @param config - Client configuration
14
+ * @returns CSpellRPCClient
15
+ */
16
+ export declare function createCSpellRPCClient(config: CSpellRPCClientConfig): CSpellRPCClient;
17
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1,20 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { RPCClient } from '../rpc/index.js';
3
+ import { CSPELL_RPC_API_ENDPOINTS } from './api.js';
4
+ export class CSpellRPCClient extends RPCClient {
5
+ constructor(config) {
6
+ super({ randomUUID, ...config });
7
+ }
8
+ getApi() {
9
+ return super.getApi(Object.keys(CSPELL_RPC_API_ENDPOINTS));
10
+ }
11
+ }
12
+ /**
13
+ * Create a CSpell RPC Client.
14
+ * @param config - Client configuration
15
+ * @returns CSpellRPCClient
16
+ */
17
+ export function createCSpellRPCClient(config) {
18
+ return new CSpellRPCClient(config);
19
+ }
20
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1,7 @@
1
+ export type { CSpellRPCApi } from './api.js';
2
+ export { CSPELL_RPC_API_ENDPOINTS } from './api.js';
3
+ export type { CSpellRPCClientOptions } from './client.js';
4
+ export { createCSpellRPCClient, CSpellRPCClient } from './client.js';
5
+ export type { CSpellRPCServerOptions, MessagePortLike } from './server.js';
6
+ export { createCSpellRPCServer, CSpellRPCServer } from './server.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,4 @@
1
+ export { CSPELL_RPC_API_ENDPOINTS } from './api.js';
2
+ export { createCSpellRPCClient, CSpellRPCClient } from './client.js';
3
+ export { createCSpellRPCServer, CSpellRPCServer } from './server.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,16 @@
1
+ import type { RPCServerConfiguration, RPCServerOptions } from '../rpc/index.js';
2
+ import { RPCServer } from '../rpc/index.js';
3
+ import type { CSpellRPCApi } from './api.js';
4
+ export type { MessagePortLike } from '../rpc/index.js';
5
+ export type CSpellRPCServerOptions = RPCServerOptions;
6
+ export type CSpellRPCServerConfig = RPCServerConfiguration;
7
+ export declare class CSpellRPCServer extends RPCServer<CSpellRPCApi> {
8
+ constructor(config: CSpellRPCServerConfig);
9
+ }
10
+ /**
11
+ * Create a CSpell RPC Server that listens on the given port.
12
+ * @param config - Server configuration.
13
+ * @returns The CSpell RPC Server.
14
+ */
15
+ export declare function createCSpellRPCServer(config: CSpellRPCServerConfig): CSpellRPCServer;
16
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1,37 @@
1
+ import { RPCServer } from '../rpc/index.js';
2
+ import { spellCheckDocumentRPC } from './spellCheckFile.js';
3
+ export class CSpellRPCServer extends RPCServer {
4
+ constructor(config) {
5
+ super(config, getCSpellRPCApi());
6
+ }
7
+ }
8
+ /**
9
+ * Create a CSpell RPC Server that listens on the given port.
10
+ * @param config - Server configuration.
11
+ * @returns The CSpell RPC Server.
12
+ */
13
+ export function createCSpellRPCServer(config) {
14
+ return new CSpellRPCServer(config);
15
+ }
16
+ /**
17
+ * Get the CSpell RPC API.
18
+ *
19
+ * @returns the api implementation.
20
+ */
21
+ function getCSpellRPCApi() {
22
+ return {
23
+ spellCheckDocument: spellCheckDocumentRPC,
24
+ sleep,
25
+ echo,
26
+ };
27
+ }
28
+ function echo(msg) {
29
+ return Promise.resolve(msg);
30
+ }
31
+ function sleep(ms) {
32
+ return new Promise((resolve) => {
33
+ const start = performance.now();
34
+ setTimeout(() => resolve(performance.now() - start), ms);
35
+ });
36
+ }
37
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1,2 @@
1
+ export { spellCheckDocumentRPC } from '../lib/spellCheckFile.js';
2
+ //# sourceMappingURL=spellCheckFile.d.ts.map
@@ -0,0 +1,2 @@
1
+ export { spellCheckDocumentRPC } from '../lib/spellCheckFile.js';
2
+ //# sourceMappingURL=spellCheckFile.js.map
@@ -0,0 +1,2 @@
1
+ export * from './lib/index.js';
2
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from './lib/index.js';
2
+ //# sourceMappingURL=index.js.map
@@ -1,6 +1,6 @@
1
- import type { AdvancedCSpellSettingsWithSourceTrace, ImportFileRef } from '@cspell/cspell-types';
2
- import type { CSpellSettingsInternal, CSpellSettingsInternalFinalized } from '../Models/CSpellSettingsInternalDef.js';
1
+ import type { AdvancedCSpellSettingsWithSourceTrace, CSpellSettings, ImportFileRef } from '@cspell/cspell-types';
3
2
  import type { OptionalOrUndefined } from '../util/types.js';
3
+ import type { CSpellSettingsInternal, CSpellSettingsInternalFinalized } from './internal/index.js';
4
4
  type CSpellSettingsWST = AdvancedCSpellSettingsWithSourceTrace;
5
5
  export type CSpellSettingsWSTO = OptionalOrUndefined<AdvancedCSpellSettingsWithSourceTrace>;
6
6
  export type CSpellSettingsI = CSpellSettingsInternal;
@@ -9,6 +9,8 @@ declare function mergeObjects(left: undefined, right: undefined): undefined;
9
9
  declare function mergeObjects<T>(left: T, right: undefined): T;
10
10
  declare function mergeObjects<T>(left: T, right: T): T;
11
11
  declare function mergeObjects<T>(left: undefined, right: T): T;
12
+ export declare function toCSpellSettingsWithSourceTrace(settings: CSpellSettingsWSTO | CSpellSettingsI): CSpellSettingsWSTO;
13
+ export declare function toCSpellSettingsWithOutSourceTrace(settings: CSpellSettingsWSTO | CSpellSettingsI): CSpellSettings;
12
14
  export declare function mergeSettings(left: CSpellSettingsWSTO | CSpellSettingsI, ...settings: (CSpellSettingsWSTO | CSpellSettingsI | undefined)[]): CSpellSettingsI;
13
15
  export declare function mergeInDocSettings(left: CSpellSettingsWSTO, ...rest: CSpellSettingsWSTO[]): CSpellSettingsWST;
14
16
  /**
@@ -1,14 +1,15 @@
1
1
  import assert from 'node:assert';
2
2
  import { onClearCache } from '../events/index.js';
3
- import { cleanCSpellSettingsInternal as csi, isCSpellSettingsInternal } from '../Models/CSpellSettingsInternalDef.js';
4
3
  import { autoResolveWeak, AutoResolveWeakCache } from '../util/AutoResolve.js';
5
4
  import { toFileUrl } from '../util/url.js';
6
5
  import * as util from '../util/util.js';
7
6
  import { configSettingsFileVersion0_1, ENV_CSPELL_GLOB_ROOT } from './constants.js';
8
- import { calcDictionaryDefsToLoad, mapDictDefsToInternal } from './DictionarySettings.js';
7
+ import { calcDictionaryDefsToLoad, mapDictDefsToInternal } from './internal/index.js';
8
+ import { cleanCSpellSettingsInternal as csi, isCSpellSettingsInternal } from './internal/index.js';
9
9
  import { mergeList, mergeListUnique } from './mergeList.js';
10
10
  import { resolvePatterns } from './patterns.js';
11
11
  import { CwdUrlResolver } from './resolveCwd.js';
12
+ import { walkToJSONObj } from './util/settingsToJson.js';
12
13
  export { stats as getMergeStats } from './mergeList.js';
13
14
  const emptyWords = [];
14
15
  Object.freeze(emptyWords);
@@ -54,6 +55,13 @@ function replaceIfNotEmpty(left = [], right = []) {
54
55
  }
55
56
  return left;
56
57
  }
58
+ export function toCSpellSettingsWithSourceTrace(settings) {
59
+ return walkToJSONObj(settings);
60
+ }
61
+ export function toCSpellSettingsWithOutSourceTrace(settings) {
62
+ const { __importRef, __imports, source: _source, ...rest } = toCSpellSettingsWithSourceTrace(settings);
63
+ return util.clean(rest);
64
+ }
57
65
  export function mergeSettings(left, ...settings) {
58
66
  const rawSettings = settings.filter(util.isDefined).reduce(merge, toInternalSettings(left));
59
67
  return util.clean(rawSettings);
@@ -2,6 +2,9 @@ import { isError } from '../../util/errors.js';
2
2
  export class ImportError extends Error {
3
3
  cause;
4
4
  constructor(msg, cause) {
5
+ if (isError(cause)) {
6
+ msg += `\n ${cause.message}`;
7
+ }
5
8
  super(msg);
6
9
  this.cause = isError(cause) ? cause : undefined;
7
10
  }
@@ -1,11 +1,13 @@
1
1
  import type { CSpellSettings, CSpellUserSettings, ImportFileRef } from '@cspell/cspell-types';
2
- import { CSpellConfigFile, CSpellConfigFileReaderWriter, ICSpellConfigFile } from 'cspell-config-lib';
2
+ import type { CSpellConfigFileReaderWriter, ICSpellConfigFile } from 'cspell-config-lib';
3
+ import { CSpellConfigFile, CSpellConfigFileWithErrors } from 'cspell-config-lib';
3
4
  import type { VFileSystem } from '../../../fileSystem.js';
4
- import { AutoResolveCache, CacheStats } from '../../../util/AutoResolve.js';
5
+ import type { CacheStats } from '../../../util/AutoResolve.js';
6
+ import { AutoResolveCache } from '../../../util/AutoResolve.js';
5
7
  import { FileResolver } from '../../../util/resolveFile.js';
6
8
  import type { LoaderResult } from '../pnpLoader.js';
7
9
  import { ConfigSearch } from './configSearch.js';
8
- import { StopSearchAt } from './defaultConfigLoader.js';
10
+ import type { StopSearchAt } from './defaultConfigLoader.js';
9
11
  import { normalizeCacheSettings } from './normalizeRawSettings.js';
10
12
  import type { PnPSettingsOptional } from './PnPSettings.js';
11
13
  import type { CSpellSettingsI, CSpellSettingsWST } from './types.js';
@@ -123,7 +125,7 @@ export declare class ConfigLoader implements IConfigLoader {
123
125
  readSettingsAsync(filename: string | URL, relativeTo?: string | URL, pnpSettings?: PnPSettingsOptional): Promise<CSpellSettingsI>;
124
126
  readConfigFile(filenameOrURL: string | URL, relativeTo?: string | URL): Promise<CSpellConfigFile | Error>;
125
127
  searchForConfigFileLocation(searchFrom: URL | string | undefined, stopSearchAt?: URL[] | undefined): Promise<URL | undefined>;
126
- searchForConfigFile(searchFrom: URL | string | undefined, stopSearchAt?: URL[]): Promise<CSpellConfigFile | undefined>;
128
+ searchForConfigFile(searchFrom: URL | string | undefined, stopSearchAt?: URL[]): Promise<CSpellConfigFile | CSpellConfigFileWithErrors | undefined>;
127
129
  /**
128
130
  *
129
131
  * @param searchFrom the directory / file URL to start searching from.
@@ -1,13 +1,12 @@
1
1
  import assert from 'node:assert';
2
2
  import path from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
- import { CSpellConfigFile } from 'cspell-config-lib';
4
+ import { CSpellConfigFile, CSpellConfigFileWithErrors } from 'cspell-config-lib';
5
5
  import { createReaderWriter } from 'cspell-config-lib';
6
6
  import { isUrlLike, toFileURL } from 'cspell-io';
7
7
  import { URI, Utils as UriUtils } from 'vscode-uri';
8
8
  import { onClearCache } from '../../../events/index.js';
9
9
  import { getVirtualFS } from '../../../fileSystem.js';
10
- import { createCSpellSettingsInternal as csi } from '../../../Models/CSpellSettingsInternalDef.js';
11
10
  import { srcDirectory } from '../../../pkg-info.mjs';
12
11
  import { autoResolve, AutoResolveCache, autoResolveWeak } from '../../../util/AutoResolve.js';
13
12
  import { logError, logWarning } from '../../../util/logger.js';
@@ -15,13 +14,14 @@ import { FileResolver } from '../../../util/resolveFile.js';
15
14
  import { envToTemplateVars } from '../../../util/templates.js';
16
15
  import { addTrailingSlash, cwdURL, resolveFileWithURL, toFileDirURL, toFilePathOrHref, toFileUrl, windowsDriveLetterToUpper, } from '../../../util/url.js';
17
16
  import { configSettingsFileVersion0_1, configSettingsFileVersion0_2, currentSettingsFileVersion, defaultConfigFileModuleRef, ENV_CSPELL_GLOB_ROOT, } from '../../constants.js';
18
- import { getMergeStats, mergeSettings } from '../../CSpellSettingsServer.js';
17
+ import { getMergeStats, mergeSettings, toInternalSettings } from '../../CSpellSettingsServer.js';
19
18
  import { getGlobalConfig } from '../../GlobalSettings.js';
19
+ import { createCSpellSettingsInternal as csi } from '../../internal/index.js';
20
20
  import { ImportError } from '../ImportError.js';
21
21
  import { pnpLoader } from '../pnpLoader.js';
22
22
  import { searchPlaces } from './configLocations.js';
23
23
  import { ConfigSearch } from './configSearch.js';
24
- import { configToRawSettings } from './configToRawSettings.js';
24
+ import { configErrorToRawSettings, configToRawSettings } from './configToRawSettings.js';
25
25
  import { defaultSettings } from './defaultSettings.js';
26
26
  import { normalizeCacheSettings, normalizeDictionaryDefs, normalizeGitignoreRoot, normalizeImport, normalizeLanguageSettings, normalizeOverrides, normalizeReporters, normalizeSettingsGlobs, } from './normalizeRawSettings.js';
27
27
  import { defaultPnPSettings, normalizePnPSettings } from './PnPSettings.js';
@@ -31,7 +31,7 @@ export const sectionCSpell = 'cSpell';
31
31
  export const defaultFileName = 'cspell.json';
32
32
  let defaultConfigLoader = undefined;
33
33
  const defaultExtensions = ['.json', '.yaml', '.yml', '.jsonc', '.toml'];
34
- const defaultJsExtensions = ['.js', '.cjs', '.mjs', '.ts', '.mts'];
34
+ const defaultJsExtensions = ['.js', '.cjs', '.mjs', '.ts', '.mts', '.cts'];
35
35
  export const defaultExtensionsAll = [...defaultExtensions, ...defaultJsExtensions];
36
36
  const trustedSearch = new Map([
37
37
  ['*', defaultExtensions],
@@ -110,7 +110,10 @@ export class ConfigLoader {
110
110
  if (!location)
111
111
  return undefined;
112
112
  const file = await this.readConfigFile(location);
113
- return file instanceof Error ? undefined : file;
113
+ if (file instanceof Error) {
114
+ return new CSpellConfigFileWithErrors(location, configErrorToRawSettings(file, location), file);
115
+ }
116
+ return file;
114
117
  }
115
118
  /**
116
119
  *
@@ -123,6 +126,9 @@ export class ConfigLoader {
123
126
  const configFile = await this.searchForConfigFile(searchFrom, stopAt);
124
127
  if (!configFile)
125
128
  return undefined;
129
+ if (configFile instanceof CSpellConfigFileWithErrors) {
130
+ return toInternalSettings(configFile.settings);
131
+ }
126
132
  return this.mergeConfigFileWithImports(configFile, options);
127
133
  }
128
134
  getGlobalSettings() {
@@ -9,6 +9,7 @@ export const supportedExtensions = [
9
9
  '.toml',
10
10
  '.mts',
11
11
  '.ts',
12
+ '.cts',
12
13
  ];
13
14
  /**
14
15
  * Logic of the locations:
@@ -1,5 +1,5 @@
1
- import { createCSpellSettingsInternal as csi } from '../../../Models/CSpellSettingsInternalDef.js';
2
1
  import { currentSettingsFileVersion } from '../../constants.js';
2
+ import { createCSpellSettingsInternal as csi } from '../../internal/index.js';
3
3
  export const defaultSettings = csi({
4
4
  id: 'default',
5
5
  name: 'default',
@@ -3,7 +3,7 @@ import { fileURLToPath } from 'node:url';
3
3
  import { resolveFile } from '../../../util/resolveFile.js';
4
4
  import { resolveFileWithURL, toFilePathOrHref } from '../../../util/url.js';
5
5
  import * as util from '../../../util/util.js';
6
- import { mapDictDefsToInternal } from '../../DictionarySettings.js';
6
+ import { mapDictDefsToInternal } from '../../internal/index.js';
7
7
  import { toGlobDef } from './toGlobDef.js';
8
8
  export function normalizeRawConfig(config) {
9
9
  if (typeof config.version === 'number') {
@@ -1,5 +1,5 @@
1
1
  import type { CSpellSettingsWithSourceTrace } from '@cspell/cspell-types';
2
- import type { CSpellSettingsInternal } from '../../../Models/CSpellSettingsInternalDef.js';
2
+ import type { CSpellSettingsInternal } from '../../internal/index.js';
3
3
  export type CSpellSettingsWST = CSpellSettingsWithSourceTrace;
4
4
  export type CSpellSettingsI = CSpellSettingsInternal;
5
5
  //# sourceMappingURL=types.d.ts.map
@@ -1,4 +1,4 @@
1
- import type { CSpellSettingsInternal } from '../Models/CSpellSettingsInternalDef.js';
1
+ import type { CSpellSettingsInternal } from './internal/index.js';
2
2
  export declare const _defaultSettingsBasis: Readonly<CSpellSettingsInternal>;
3
3
  export declare const _defaultSettings: Readonly<CSpellSettingsInternal>;
4
4
  declare class DefaultSettingsLoader {
@@ -1,11 +1,11 @@
1
1
  import { parsers } from 'cspell-grammar';
2
- import { createCSpellSettingsInternal } from '../Models/CSpellSettingsInternalDef.js';
3
2
  import { PatternRegExp } from '../Models/PatternRegExp.js';
4
3
  import { srcDirectory } from '../pkg-info.mjs';
5
4
  import { resolveFile } from '../util/resolveFile.js';
6
5
  import { defaultConfigFileModuleRef } from './constants.js';
7
6
  import { readSettings } from './Controller/configLoader/index.js';
8
7
  import { mergeSettings } from './CSpellSettingsServer.js';
8
+ import { createCSpellSettingsInternal } from './internal/index.js';
9
9
  import * as LanguageSettings from './LanguageSettings.js';
10
10
  import * as RegPat from './RegExpPatterns.js';
11
11
  // Do not use require.resolve because webpack will mess it up.
@@ -31,9 +31,6 @@ interface DirectiveMatchWithParser extends PossibleMatch {
31
31
  directive: Directive;
32
32
  fn: ReducerFn;
33
33
  }
34
- export declare const regExSpellingGuardBlock: RegExp;
35
- export declare const regExSpellingGuardNext: RegExp;
36
- export declare const regExSpellingGuardLine: RegExp;
37
34
  declare function parseCompoundWords(acc: CSpellUserSettings, match: string): CSpellUserSettings;
38
35
  declare function parseWords(acc: CSpellUserSettings, match: string): CSpellUserSettings;
39
36
  declare function parseIgnoreWords(acc: CSpellUserSettings, match: string): CSpellUserSettings;
@@ -118,14 +118,12 @@ const settingParsers = [
118
118
  [/^dictionar(?:y|ies)\b(?!-)/i, parseDictionaries, 'Dictionaries'], // cspell:disable-line
119
119
  [/^LocalWords:/, (acc, m) => reduceWordList(acc, m.replaceAll(/^LocalWords:?/gi, ' '), 'words'), 'Words'],
120
120
  ];
121
- export const regExSpellingGuardBlock = /(\bc?spell(?:-?checker)?::?)\s*disable(?!-line|-next)\b[\s\S]*?((?:\1\s*enable\b)|$)/gi;
122
- export const regExSpellingGuardNext = /\bc?spell(?:-?checker)?::?\s*disable-next\b.*\s\s?.*/gi;
123
- export const regExSpellingGuardLine = /^.*\bc?spell(?:-?checker)?::?\s*disable-line\b.*/gim;
124
121
  const issueMessages = {
125
122
  unknownDirective: 'Unknown CSpell directive',
126
123
  };
127
124
  function parseSettingMatchValidation(possibleMatch) {
128
125
  const { fullDirective, offset } = possibleMatch;
126
+ regExCSpellDirectiveKey.lastIndex = 0;
129
127
  const directiveMatch = fullDirective.match(regExCSpellDirectiveKey);
130
128
  if (!directiveMatch)
131
129
  return undefined;
@@ -231,6 +229,7 @@ function parseFlagWords(acc, match) {
231
229
  }
232
230
  function parseRegEx(match) {
233
231
  const patterns = [match.replace(/^[^\s]+\s+/, '')].map((a) => {
232
+ regExMatchRegEx.lastIndex = 0;
234
233
  const m = a.match(regExMatchRegEx);
235
234
  if (m && m[0]) {
236
235
  return m[0];
@@ -16,11 +16,11 @@ function stringToList(sList) {
16
16
  .map((s) => s.trim())
17
17
  .filter((s) => !!s);
18
18
  }
19
- function memorizer(resolver) {
19
+ function memoize(resolver) {
20
20
  const cache = createAutoResolveCache();
21
21
  return (k) => cache.get(k, resolver);
22
22
  }
23
- const _normalizeLanguageId = memorizer(__normalizeLanguageId);
23
+ const _normalizeLanguageId = memoize(__normalizeLanguageId);
24
24
  function __normalizeLanguageId(langId) {
25
25
  const langIds = stringToList(langId);
26
26
  return new Set(langIds.map((a) => a.toLowerCase()));
@@ -28,7 +28,7 @@ function __normalizeLanguageId(langId) {
28
28
  export function normalizeLanguageId(langId) {
29
29
  return _normalizeLanguageId(typeof langId === 'string' ? langId : langId.join(','));
30
30
  }
31
- const _normalizeLocale = memorizer(__normalizeLocale);
31
+ const _normalizeLocale = memoize(__normalizeLocale);
32
32
  function __normalizeLocale(locale) {
33
33
  const locales = localesToList(locale);
34
34
  return new Set(locales.map((locale) => locale.toLowerCase().replaceAll(/[^a-z]/g, '')));
@@ -5,14 +5,14 @@ export const regExHRef = /\bhref\s*=\s*".*?"/gi;
5
5
  export const regExMatchCommonHexFormats = /(?:#[0-9a-f]{3,8})|(?:0x[0-9a-f]+)|(?:\\u[0-9a-f]{4})|(?:\\x\{[0-9a-f]{4}\})/gi;
6
6
  export const regExCommitHash = /\b(?![a-f]+\b)(?:0x)?[0-9a-f]{7,}\b/gi; // Match Commit Hashes that contain at least one digit.
7
7
  export const regExCommitHashLink = /\[[0-9a-f]{7,}\]/gi; // Match Commit Hash Markdown link: [abcdef0].
8
- export const regExCStyleHexValue = /\b0x[0-9a-f_]+\b/gi;
8
+ export const regExCStyleHexValue = /\b0x[0-9a-f_]+n?\b/gi;
9
9
  export const regExCSSHexValue = /#[0-9a-f]{3,8}\b/gi;
10
10
  export const regExUUID = /\b[0-9a-fx]{8}-[0-9a-fx]{4}-[0-9a-fx]{4}-[0-9a-fx]{4}-[0-9a-fx]{12}\b/gi; // x - represents placeholder values
11
11
  export const regExUnicodeRef = /\bU\+[0-9a-f]{4,5}(?:-[0-9a-f]{4,5})?/gi;
12
12
  export const regExSpellingGuardBlock = /(\bc?spell(?:-?checker)?::?)\s*disable(?!-line|-next)\b(?!-)[\s\S]*?((?:\1\s*enable\b)|$)/gi;
13
13
  export const regExSpellingGuardNext = /\bc?spell(?:-?checker)?::?\s*disable-next\b.*\s\s?.*/gi;
14
14
  export const regExSpellingGuardLine = /^.*\bc?spell(?:-?checker)?::?\s*disable-line\b.*/gim;
15
- export const regExIgnoreSpellingDirectives = /\bc?spell(?:-?checker)?::?\s*ignoreRegExp.*/gim;
15
+ export const regExIgnoreSpellingDirectives = /\bc?spell(?:-?checker)?::?\s*(ignoreRegExp|word|ignore).*/gim;
16
16
  export const regExPublicKey = /-{5}BEGIN\s+((?:RSA\s+)?PUBLIC\s+KEY)[\w=+\-/=\\\s]+?END\s+\1-{5}/g;
17
17
  export const regExCert = /-{5}BEGIN\s+(CERTIFICATE|(?:RSA\s+)?(?:PRIVATE|PUBLIC)\s+KEY)[\w=+\-/=\\\s]+?END\s+\1-{5}/g;
18
18
  export const regExSshRSA = /ssh-rsa\s+[a-z0-9/+]{28,}={0,3}(?![a-z0-9/+=])/gi;
@@ -1,5 +1,5 @@
1
1
  import type { CSpellSettings, CSpellUserSettings } from '@cspell/cspell-types';
2
- import type { CSpellSettingsInternal } from '../Models/CSpellSettingsInternalDef.js';
2
+ import type { CSpellSettingsInternal } from './internal/index.js';
3
3
  export declare function combineTextAndLanguageSettings(settings: CSpellUserSettings, text: string | undefined, languageId: string | string[]): CSpellSettingsInternal;
4
4
  export declare function extractSettingsFromText(text: string): CSpellSettings;
5
5
  //# sourceMappingURL=TextDocumentSettings.d.ts.map
@@ -1,4 +1,4 @@
1
- import { CSpellSettings } from '@cspell/cspell-types';
1
+ import type { CSpellSettings } from '@cspell/cspell-types';
2
2
  export declare const legacyLocationDir: string | undefined;
3
3
  export declare const cspellGlobalLocationDir: string;
4
4
  export declare const defaultConfigFileName = "cspell.json";
@@ -5,6 +5,8 @@ export type { CSpellConfigFile, ICSpellConfigFile } from './Controller/configLoa
5
5
  export { clearCachedSettingsFiles, createConfigLoader, defaultConfigFilenames, defaultFileName, extractImportErrors, getCachedFileSize, getDefaultConfigLoader, getGlobalSettings, getGlobalSettingsAsync, loadConfig, loadPnP, readConfigFile, readRawSettings, readSettings, readSettingsFiles, resolveConfigFileImports, resolveSettingsImports, searchForConfig, sectionCSpell, } from './Controller/configLoader/index.js';
6
6
  export { ImportError } from './Controller/ImportError.js';
7
7
  export type { ConfigurationDependencies, ImportFileRefWithError } from './CSpellSettingsServer.js';
8
- export { extractDependencies, finalizeSettings, getSources, mergeInDocSettings, mergeSettings, } from './CSpellSettingsServer.js';
8
+ export { extractDependencies, finalizeSettings, getSources, mergeInDocSettings, mergeSettings, toCSpellSettingsWithOutSourceTrace, } from './CSpellSettingsServer.js';
9
9
  export { defaultSettingsLoader, getDefaultBundledSettingsAsync, getDefaultSettings } from './DefaultSettings.js';
10
+ export type { CSpellSettingsInternal, CSpellSettingsInternalFinalized, DictionaryDefinitionInlineInternal, DictionaryDefinitionInternal, DictionaryDefinitionSimpleInternal, DictionaryFileDefinitionInternal, } from './internal/index.js';
11
+ export { calcDictionaryDefsToLoad, createCSpellSettingsInternal, filterDictDefsToLoad, isDictionaryDefinitionInlineInternal, isDictionaryFileDefinitionInternal, mapDictDefToInternal, } from './internal/index.js';
10
12
  //# sourceMappingURL=index.d.ts.map
@@ -3,6 +3,7 @@ export { checkFilenameMatchesGlob } from './checkFilenameMatchesGlob.js';
3
3
  export { currentSettingsFileVersion, ENV_CSPELL_GLOB_ROOT } from './constants.js';
4
4
  export { clearCachedSettingsFiles, createConfigLoader, defaultConfigFilenames, defaultFileName, extractImportErrors, getCachedFileSize, getDefaultConfigLoader, getGlobalSettings, getGlobalSettingsAsync, loadConfig, loadPnP, readConfigFile, readRawSettings, readSettings, readSettingsFiles, resolveConfigFileImports, resolveSettingsImports, searchForConfig, sectionCSpell, } from './Controller/configLoader/index.js';
5
5
  export { ImportError } from './Controller/ImportError.js';
6
- export { extractDependencies, finalizeSettings, getSources, mergeInDocSettings, mergeSettings, } from './CSpellSettingsServer.js';
6
+ export { extractDependencies, finalizeSettings, getSources, mergeInDocSettings, mergeSettings, toCSpellSettingsWithOutSourceTrace, } from './CSpellSettingsServer.js';
7
7
  export { defaultSettingsLoader, getDefaultBundledSettingsAsync, getDefaultSettings } from './DefaultSettings.js';
8
+ export { calcDictionaryDefsToLoad, createCSpellSettingsInternal, filterDictDefsToLoad, isDictionaryDefinitionInlineInternal, isDictionaryFileDefinitionInternal, mapDictDefToInternal, } from './internal/index.js';
8
9
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,18 @@
1
+ import type { AdvancedCSpellSettingsWithSourceTrace, CSpellSettingsWithSourceTrace, Parser } from '@cspell/cspell-types';
2
+ import type { OptionalOrUndefined } from '../../util/types.js';
3
+ import type { DictionaryDefinitionInternal } from './InternalDictionaryDef.js';
4
+ export declare const SymbolCSpellSettingsInternal: unique symbol;
5
+ export interface CSpellSettingsInternal extends Omit<AdvancedCSpellSettingsWithSourceTrace, 'dictionaryDefinitions'> {
6
+ [SymbolCSpellSettingsInternal]: true;
7
+ dictionaryDefinitions?: DictionaryDefinitionInternal[];
8
+ }
9
+ export interface CSpellSettingsInternalFinalized extends CSpellSettingsInternal {
10
+ parserFn: Parser | undefined;
11
+ finalized: true;
12
+ ignoreRegExpList: RegExp[];
13
+ includeRegExpList: RegExp[];
14
+ }
15
+ export declare function cleanCSpellSettingsInternal(parts?: OptionalOrUndefined<Partial<CSpellSettingsInternal>>): CSpellSettingsInternal;
16
+ export declare function createCSpellSettingsInternal(parts?: OptionalOrUndefined<Partial<CSpellSettingsInternal>>): CSpellSettingsInternal;
17
+ export declare function isCSpellSettingsInternal(cs: CSpellSettingsInternal | CSpellSettingsWithSourceTrace | OptionalOrUndefined<CSpellSettingsInternal | CSpellSettingsWithSourceTrace>): cs is CSpellSettingsInternal;
18
+ //# sourceMappingURL=CSpellSettingsInternalDef.d.ts.map
@@ -1,4 +1,4 @@
1
- import { clean } from '../util/util.js';
1
+ import { clean } from '../../util/util.js';
2
2
  export const SymbolCSpellSettingsInternal = Symbol('CSpellSettingsInternal');
3
3
  export function cleanCSpellSettingsInternal(parts) {
4
4
  return parts
@@ -11,13 +11,4 @@ export function createCSpellSettingsInternal(parts) {
11
11
  export function isCSpellSettingsInternal(cs) {
12
12
  return !!cs[SymbolCSpellSettingsInternal];
13
13
  }
14
- export function isDictionaryDefinitionInlineInternal(def) {
15
- if (def.path)
16
- return false;
17
- const defInline = def;
18
- return !!(defInline.words || defInline.flagWords || defInline.ignoreWords || defInline.suggestWords);
19
- }
20
- export function isDictionaryFileDefinitionInternal(def) {
21
- return !!(def.path || def.file);
22
- }
23
14
  //# sourceMappingURL=CSpellSettingsInternalDef.js.map
@@ -1,6 +1,7 @@
1
1
  import type { DictionaryDefinition } from '@cspell/cspell-types';
2
- import type { CSpellSettingsInternal, DictionaryDefinitionInternal, DictionaryDefinitionInternalWithSource, DictionaryFileDefinitionInternalWithSource } from '../Models/CSpellSettingsInternalDef.js';
3
- import type { DictionaryReferenceCollection } from './DictionaryReferenceCollection.js';
2
+ import type { DictionaryReferenceCollection } from '../DictionaryReferenceCollection.js';
3
+ import type { CSpellSettingsInternal } from './CSpellSettingsInternalDef.js';
4
+ import type { DictionaryDefinitionInternal, DictionaryDefinitionInternalWithSource, DictionaryFileDefinitionInternalWithSource } from './InternalDictionaryDef.js';
4
5
  export type DefMapArrayItem = [string, DictionaryDefinitionInternal];
5
6
  /**
6
7
  * Combines the list of desired dictionaries with the list of dictionary