cspell-lib 10.3.5 → 10.4.0-alpha.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.
package/dist/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
- export * from './lib/index.js';
1
+ export type { CheckTextInfo, ConfigurationDependencies, CreateTextDocumentParams, CSpellConfigFile, DetermineFinalDocumentSettingsResult, DictionaryReferenceCollection, Document, DocumentValidatorOptions, ExcludeFilesGlobMap, ExclusionFunction, FeatureFlag, ICSpellConfigFile, ImportFileRefWithError, IncludeExcludeOptions, Logger, PerfTimer, SpellCheckFileOptions, SpellCheckFilePerf, SpellCheckFileResult, SpellingDictionary, SpellingDictionaryCollection, SuggestedWord, SuggestionCollector, SuggestionOptions, SuggestionResult, SuggestionsForWordResult, SuggestOptions, TextDocument, TextDocumentLine, TextDocumentRef, TextInfoItem, TraceOptions, TraceResult, TraceWordResult, ValidationIssue, VFileSystemProvider, VirtualFS, } from './lib/index.js';
2
+ export { asyncIterableToArray, calcOverrideSettings, checkFilenameMatchesGlob, checkText, checkTextDocument, clearCachedFiles, clearCaches, combineTextAndLanguageSettings, CompoundWordsMethod, constructSettingsForText, createConfigLoader, createDictionaryReferenceCollection, createPerfTimer, createSpellingDictionary, createSpellingDictionaryCollection, createTextDocument, currentSettingsFileVersion, defaultConfigFilenames, defaultFileName, defaultSettingsFilename, determineFinalDocumentSettings, DocumentValidator, ENV_CSPELL_GLOB_ROOT, ExclusionHelper, extractDependencies, extractImportErrors, FeatureFlags, fileToDocument, fileToTextDocument, finalizeSettings, FSCapabilityFlags, getCachedFileSize, getDefaultBundledSettingsAsync, getDefaultConfigLoader, getDefaultSettings, getDictionary, getGlobalSettings, getGlobalSettingsAsync, getLanguageIdsForBaseFilename, getLanguagesForExt, getLogger, getSources, getSystemFeatureFlags, getVirtualFS, ImportError, IncludeExcludeFlag, isBinaryFile, isSpellingDictionaryLoadError, Link, loadConfig, loadPnP, mergeInDocSettings, mergeSettings, readConfigFile, readFile, readFileSync, readRawSettings, readSettings, readSettingsFiles, refreshDictionaryCache, resolveConfigFileImports, resolveFile, searchForConfig, sectionCSpell, setLogger, shouldCheckDocument, spellCheckDocument, spellCheckDocumentRPC, spellCheckFile, SpellingDictionaryLoadError, SuggestionError, suggestionsForWord, suggestionsForWords, Text, toCSpellSettingsWithOutSourceTrace, traceWords, traceWordsAsync, UnknownFeatureFlagError, updateTextDocument, validateText, writeToFile, writeToFileIterable, writeToFileIterableP, } from './lib/index.js';
3
+ export * from '@cspell/cspell-types';
2
4
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,2 +1,3 @@
1
- export * from './lib/index.js';
1
+ export { asyncIterableToArray, calcOverrideSettings, checkFilenameMatchesGlob, checkText, checkTextDocument, clearCachedFiles, clearCaches, combineTextAndLanguageSettings, CompoundWordsMethod, constructSettingsForText, createConfigLoader, createDictionaryReferenceCollection, createPerfTimer, createSpellingDictionary, createSpellingDictionaryCollection, createTextDocument, currentSettingsFileVersion, defaultConfigFilenames, defaultFileName, defaultSettingsFilename, determineFinalDocumentSettings, DocumentValidator, ENV_CSPELL_GLOB_ROOT, ExclusionHelper, extractDependencies, extractImportErrors, FeatureFlags, fileToDocument, fileToTextDocument, finalizeSettings, FSCapabilityFlags, getCachedFileSize, getDefaultBundledSettingsAsync, getDefaultConfigLoader, getDefaultSettings, getDictionary, getGlobalSettings, getGlobalSettingsAsync, getLanguageIdsForBaseFilename, getLanguagesForExt, getLogger, getSources, getSystemFeatureFlags, getVirtualFS, ImportError, IncludeExcludeFlag, isBinaryFile, isSpellingDictionaryLoadError, Link, loadConfig, loadPnP, mergeInDocSettings, mergeSettings, readConfigFile, readFile, readFileSync, readRawSettings, readSettings, readSettingsFiles, refreshDictionaryCache, resolveConfigFileImports, resolveFile, searchForConfig, sectionCSpell, setLogger, shouldCheckDocument, spellCheckDocument, spellCheckDocumentRPC, spellCheckFile, SpellingDictionaryLoadError, SuggestionError, suggestionsForWord, suggestionsForWords, Text, toCSpellSettingsWithOutSourceTrace, traceWords, traceWordsAsync, UnknownFeatureFlagError, updateTextDocument, validateText, writeToFile, writeToFileIterable, writeToFileIterableP, } from './lib/index.js';
2
+ export * from '@cspell/cspell-types';
2
3
  //# sourceMappingURL=index.js.map
@@ -1,10 +1,14 @@
1
+ import type { TextEncoding } from 'cspell-io';
2
+ import type { BufferEncoding } from '../Models/BufferEncoding.js';
1
3
  import type { TextDocument } from '../Models/TextDocument.js';
2
4
  import type { Document, DocumentWithText } from './Document.js';
5
+ type DocumentEncoding = Extract<BufferEncoding, TextEncoding>;
3
6
  export declare function fileToDocument(file: string): Document;
4
7
  export declare function fileToDocument(file: string, text: string, languageId?: string, locale?: string): DocumentWithText;
5
8
  export declare function fileToDocument(file: string, text?: string, languageId?: string, locale?: string): Document | DocumentWithText;
6
9
  export declare function fileToTextDocument(file: string): Promise<TextDocument>;
7
10
  export declare function documentToTextDocument(document: DocumentWithText): TextDocument;
8
11
  export declare function resolveDocumentToTextDocument(doc: Document): Promise<TextDocument>;
9
- export declare function resolveDocument(document: DocumentWithText | Document, encoding?: BufferEncoding): Promise<DocumentWithText>;
12
+ export declare function resolveDocument(document: DocumentWithText | Document, encoding?: DocumentEncoding): Promise<DocumentWithText>;
13
+ export {};
10
14
  //# sourceMappingURL=resolveDocument.d.ts.map
@@ -1,4 +1,5 @@
1
1
  import { readFile } from 'node:fs/promises';
2
+ import { readTextFile } from '../fileSystem.js';
2
3
  import { createTextDocument } from '../Models/TextDocument.js';
3
4
  import * as Uri from '../util/Uri.js';
4
5
  import { clean } from '../util/util.js';
@@ -33,11 +34,18 @@ export function resolveDocument(document, encoding) {
33
34
  if (isDocumentWithText(document))
34
35
  return Promise.resolve(document);
35
36
  const uri = Uri.toUri(document.uri);
36
- if (uri.scheme !== 'file') {
37
+ if (uri.scheme === 'stdin') {
37
38
  throw new Error(`Unsupported schema: "${uri.scheme}", open "${uri.toString()}"`);
38
39
  }
40
+ if (uri.scheme !== 'file') {
41
+ return readDocumentFromUrl(document.uri, encoding);
42
+ }
39
43
  return readDocument(Uri.uriToFilePath(uri), encoding);
40
44
  }
45
+ async function readDocumentFromUrl(uri, encoding = defaultEncoding) {
46
+ const text = await readTextFile(Uri.documentUriToURL(uri), encoding);
47
+ return { uri, text };
48
+ }
41
49
  function isDocumentWithText(doc) {
42
50
  return doc.text !== undefined;
43
51
  }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The text encodings Node.js supports, the same as its global `BufferEncoding`.
3
+ * Declared here so the published types do not need `@types/node`.
4
+ */
5
+ export type BufferEncoding = 'ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'utf-16le' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'latin1' | 'binary' | 'hex';
6
+ //# sourceMappingURL=BufferEncoding.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=BufferEncoding.js.map
@@ -1,4 +1,6 @@
1
- export * from './Dictionaries.js';
2
- export * from './SpellingDictionary.js';
3
- export * from './SpellingDictionaryError.js';
1
+ export type { DictionaryNameFields } from './Dictionaries.js';
2
+ export { getDictionaryInternal, getInlineConfigDictionaries, loadDictionaryDefs, mapSpecialDictionaryNamesToSettings, refreshDictionaryCache, specialDictionaryNames, } from './Dictionaries.js';
3
+ export type { FindOptions, FindResult, HasOptions, SearchOptions, SpellingDictionary, SpellingDictionaryCollection, SpellingDictionaryOptions, SuggestionCollector, SuggestionResult, SuggestOptions, } from './SpellingDictionary.js';
4
+ export { CompoundWordsMethod, createCollection, createInlineSpellingDictionary, createSpellingDictionary, } from './SpellingDictionary.js';
5
+ export { isSpellingDictionaryLoadError, SpellingDictionaryLoadError } from './SpellingDictionaryError.js';
4
6
  //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,4 @@
1
- export * from './Dictionaries.js';
2
- export * from './SpellingDictionary.js';
3
- export * from './SpellingDictionaryError.js';
1
+ export { getDictionaryInternal, getInlineConfigDictionaries, loadDictionaryDefs, mapSpecialDictionaryNamesToSettings, refreshDictionaryCache, specialDictionaryNames, } from './Dictionaries.js';
2
+ export { CompoundWordsMethod, createCollection, createInlineSpellingDictionary, createSpellingDictionary, } from './SpellingDictionary.js';
3
+ export { isSpellingDictionaryLoadError, SpellingDictionaryLoadError } from './SpellingDictionaryError.js';
4
4
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,7 @@
1
1
  import type { CSpellSettingsWithSourceTrace, CSpellUserSettings } from '@cspell/cspell-types';
2
2
  import type { ICSpellConfigFile } from 'cspell-config-lib';
3
3
  import type { Document, DocumentWithText } from './Document/index.js';
4
+ import type { BufferEncoding } from './Models/BufferEncoding.js';
4
5
  import type { ValidationIssueRPC } from './Models/ValidationIssue.js';
5
6
  import type { ImportFileRefWithError } from './Settings/index.js';
6
7
  import type { Uri } from './util/IUri.js';
@@ -123,15 +123,14 @@ async function spellCheckFullDocument(document, options, settingsOrConfigFile) {
123
123
  const docValOptions = options;
124
124
  const docValidator = await DocumentValidator.create(doc, docValOptions, settingsOrConfigFile).finally(() => timerPrepare.end());
125
125
  Object.assign(perf, Object.fromEntries(Object.entries(docValidator.perfTiming).map(([k, v]) => ['_' + k, v])));
126
- const prep = docValidator._getPreparations();
127
126
  if (docValidator.errors.length) {
128
- const settingsUsed = prep?.localConfig ||
127
+ const settingsUsed = docValidator._getLocalConfig() ||
129
128
  (satisfiesCSpellConfigFile(settingsOrConfigFile) ? settingsOrConfigFile.settings : settingsOrConfigFile);
130
129
  return {
131
130
  document,
132
131
  options,
133
132
  settingsUsed,
134
- localConfigFilepath: prep?.localConfigFilepath,
133
+ localConfigFilepath: docValidator._getLocalConfigFilepath(),
135
134
  issues: [],
136
135
  checked: false,
137
136
  errors: docValidator.errors,
@@ -148,7 +147,7 @@ async function spellCheckFullDocument(document, options, settingsOrConfigFile) {
148
147
  document,
149
148
  options,
150
149
  settingsUsed: docValidator.getFinalizedDocSettings(),
151
- localConfigFilepath: prep?.localConfigFilepath,
150
+ localConfigFilepath: docValidator._getLocalConfigFilepath(),
152
151
  issues,
153
152
  checked: docValidator.shouldCheckDocument(),
154
153
  errors: undefined,
@@ -1,4 +1,3 @@
1
- import assert from 'node:assert';
2
1
  import { resolveDocumentToTextDocument } from '../Document/resolveDocument.js';
3
2
  import { isTextDocument } from '../Models/TextDocument.js';
4
3
  import * as Settings from '../Settings/index.js';
@@ -57,8 +56,6 @@ export async function genCheckText(docValidator) {
57
56
  docValidator.recordCheckedRanges = true;
58
57
  await docValidator.prepare();
59
58
  const issues = docValidator.checkDocument(true);
60
- const preparations = docValidator._getPreparations();
61
- assert(preparations);
62
59
  return genResult(docValidator.document.text, issues, docValidator.getRangesChecked());
63
60
  }
64
61
  function genResult(text, issues, includeRanges) {
@@ -1,13 +1,12 @@
1
- import type { CSpellUserSettings, MappedText, ParsedText } from '@cspell/cspell-types';
1
+ import type { CSpellUserSettings, ParsedText } from '@cspell/cspell-types';
2
2
  import type { ICSpellConfigFile } from 'cspell-config-lib';
3
3
  import type { ExtendedSuggestion } from '../Models/Suggestion.js';
4
4
  import type { TextDocument, TextDocumentRef } from '../Models/TextDocument.js';
5
5
  import type { ValidationIssue } from '../Models/ValidationIssue.js';
6
- import type { CSpellSettingsInternal, CSpellSettingsInternalFinalized, ImportFileRefWithError } from '../Settings/index.js';
7
- import type { SpellingDictionaryCollection } from '../SpellingDictionary/index.js';
6
+ import type { CSpellSettingsInternal, ImportFileRefWithError } from '../Settings/index.js';
8
7
  import type { WordSuggestion } from '../suggestions.js';
9
- import type { MatchRange, SimpleRange, TextTransformer } from '../Transform/index.js';
10
- import type { TextValidationFactoryOptions, TextValidator } from './lineValidatorFactory.js';
8
+ import type { MatchRange, SimpleRange } from '../Transform/index.js';
9
+ import type { Preparations } from './docValidatorPreparations.js';
11
10
  import type { TraceResult } from './traceWord.js';
12
11
  import type { ValidateTextOptions } from './ValidateTextOptions.js';
13
12
  export interface DocumentValidatorOptions extends ValidateTextOptions {
@@ -117,8 +116,20 @@ export declare class DocumentValidator {
117
116
  shouldCheckDocument(): boolean;
118
117
  /**
119
118
  * Internal `cspell-lib` use.
119
+ * @deprecated Will be removed in a future major version. Use {@link _getLocalConfig} and
120
+ * {@link _getLocalConfigFilepath} instead.
120
121
  */
121
122
  _getPreparations(): Preparations | undefined;
123
+ /**
124
+ * Internal `cspell-lib` use.
125
+ * @returns the config file found for the document, if any.
126
+ */
127
+ _getLocalConfig(): CSpellUserSettings | undefined;
128
+ /**
129
+ * Internal `cspell-lib` use.
130
+ * @returns the path of the config file found for the document, if any.
131
+ */
132
+ _getLocalConfigFilepath(): string | undefined;
122
133
  /**
123
134
  * Get the calculated ranges of text that should be included in the spell checking.
124
135
  *
@@ -132,22 +143,6 @@ export declare class DocumentValidator {
132
143
  set recordCheckedRanges(value: boolean);
133
144
  }
134
145
  declare function sanitizeSuggestion(sug: WordSuggestion): ExtendedSuggestion;
135
- interface Preparations {
136
- /** loaded config */
137
- config: CSpellSettingsInternal;
138
- dictionary: SpellingDictionaryCollection;
139
- /** configuration after applying in-doc settings */
140
- docSettings: CSpellSettingsInternal;
141
- finalSettings: CSpellSettingsInternalFinalized;
142
- includeRanges: MatchRange[];
143
- textValidator: TextValidator;
144
- segmenter: (texts: MappedText) => Iterable<MappedText>;
145
- shouldCheck: boolean;
146
- validateOptions: TextValidationFactoryOptions;
147
- localConfig: CSpellUserSettings | undefined;
148
- localConfigFilepath: string | undefined;
149
- transformer: TextTransformer;
150
- }
151
146
  interface ShouldCheckDocumentResult {
152
147
  /** possible errors found while loading configuration. */
153
148
  errors: Error[];
@@ -10,13 +10,14 @@ import { extractImportErrors, finalizeSettings, loadConfig, mergeSettings, resol
10
10
  import { validateInDocumentSettings } from '../Settings/InDocSettings.js';
11
11
  import { getDictionaryInternal } from '../SpellingDictionary/index.js';
12
12
  import { calcSuggestionAdjustedToToMatchCase } from '../suggestions.js';
13
- import { chainTransformers, createIntlSegmentTextTransformer, createMappedTextSegmenter, createSoftWordBreakTextTransformer, createSubstitutionTransformer, } from '../Transform/index.js';
13
+ import { chainTransformers, createIntlSegmentTextTransformer, createSoftWordBreakTextTransformer, createSubstitutionTransformer, } from '../Transform/index.js';
14
14
  import { catchPromiseError, toError } from '../util/errors.js';
15
15
  import { AutoCache } from '../util/simpleCache.js';
16
16
  import { uriToFilePath } from '../util/Uri.js';
17
17
  import { cleanValidationIssue } from './cleanValidationIssue.js';
18
18
  import { defaultMaxDuplicateProblems, defaultMaxNumberOfProblems } from './defaultConstants.js';
19
19
  import { determineTextDocumentSettings } from './determineTextDocumentSettings.js';
20
+ import { DocumentValidatorPreparations } from './docValidatorPreparations.js';
20
21
  import { textValidatorFactory } from './lineValidatorFactory.js';
21
22
  import { settingsToValidateOptions } from './settingsToValidateOptions.js';
22
23
  import { calcTextInclusionRanges } from './textValidator.js';
@@ -108,22 +109,18 @@ export class DocumentValidator {
108
109
  recShouldCheckTime();
109
110
  const recFinalizeTime = recordPerfTime(this.perfTiming, '_finalizeSettings');
110
111
  const finalSettings = finalizeSettings(docSettings);
111
- const { transformer, validateOptions, includeRanges, segmenter, textValidator } = this.#calcSharedPrep(finalSettings, dict);
112
+ const { transformer, validateOptions, calcIncludeRanges, textValidator } = this.#calcSharedPrep(finalSettings, dict);
112
113
  recFinalizeTime();
113
- this._preparations = {
114
- config,
114
+ this._preparations = new DocumentValidatorPreparations(config, localConfig, localConfig?.__importRef?.filename, {
115
115
  dictionary: dict,
116
116
  docSettings,
117
117
  finalSettings,
118
118
  shouldCheck,
119
119
  validateOptions,
120
- includeRanges,
121
- segmenter,
122
120
  textValidator,
123
- localConfig,
124
- localConfigFilepath: localConfig?.__importRef?.filename,
125
121
  transformer,
126
- };
122
+ calcIncludeRanges,
123
+ });
127
124
  this._ready = true;
128
125
  this._preparationTime = timer.elapsed;
129
126
  this.perfTiming.prepTime = this._preparationTime;
@@ -138,19 +135,17 @@ export class DocumentValidator {
138
135
  const stopMeasure = measurePerf('DocumentValidator._updatePrep');
139
136
  const shouldCheck = docSettings.enabled ?? true;
140
137
  const finalSettings = finalizeSettings(docSettings);
141
- const { transformer, validateOptions, includeRanges, segmenter, textValidator } = this.#calcSharedPrep(finalSettings, dict);
142
- this._preparations = {
143
- ...prep,
138
+ const { transformer, validateOptions, calcIncludeRanges, textValidator } = this.#calcSharedPrep(finalSettings, dict);
139
+ prep.update({
144
140
  dictionary: dict,
145
141
  docSettings,
146
142
  finalSettings,
147
143
  shouldCheck,
148
144
  validateOptions,
149
- includeRanges,
150
- segmenter,
151
145
  textValidator,
152
146
  transformer,
153
- };
147
+ calcIncludeRanges,
148
+ });
154
149
  this._preparationTime = timer.elapsed;
155
150
  stopMeasure();
156
151
  }
@@ -169,10 +164,10 @@ export class DocumentValidator {
169
164
  const validateOptions = { ...settingsToValidateOptions(finalSettings), transformer };
170
165
  // Avoid excluding text ranges that have a full substitution applied.
171
166
  const rangeTransformer = finalSettings.substitutions?.length ? sub.transformer : undefined;
172
- const includeRanges = calcTextInclusionRanges(this._document.text, validateOptions, rangeTransformer);
173
- const segmenter = createMappedTextSegmenter(includeRanges);
167
+ const text = this._document.text;
168
+ const calcIncludeRanges = () => calcTextInclusionRanges(text, validateOptions, rangeTransformer);
174
169
  const textValidator = textValidatorFactory(dict, validateOptions);
175
- return { segmenter, textValidator, includeRanges, validateOptions, transformer };
170
+ return { textValidator, calcIncludeRanges, validateOptions, transformer };
176
171
  }
177
172
  /**
178
173
  * The amount of time in ms to prepare for validation.
@@ -415,10 +410,26 @@ export class DocumentValidator {
415
410
  }
416
411
  /**
417
412
  * Internal `cspell-lib` use.
413
+ * @deprecated Will be removed in a future major version. Use {@link _getLocalConfig} and
414
+ * {@link _getLocalConfigFilepath} instead.
418
415
  */
419
416
  _getPreparations() {
420
417
  return this._preparations;
421
418
  }
419
+ /**
420
+ * Internal `cspell-lib` use.
421
+ * @returns the config file found for the document, if any.
422
+ */
423
+ _getLocalConfig() {
424
+ return this._preparations?.localConfig;
425
+ }
426
+ /**
427
+ * Internal `cspell-lib` use.
428
+ * @returns the path of the config file found for the document, if any.
429
+ */
430
+ _getLocalConfigFilepath() {
431
+ return this._preparations?.localConfigFilepath;
432
+ }
422
433
  /**
423
434
  * Get the calculated ranges of text that should be included in the spell checking.
424
435
  *
@@ -0,0 +1,74 @@
1
+ import type { CSpellUserSettings, MappedText } from '@cspell/cspell-types';
2
+ import type { CSpellSettingsInternal, CSpellSettingsInternalFinalized } from '../Settings/index.js';
3
+ import type { SpellingDictionaryCollection } from '../SpellingDictionary/index.js';
4
+ import type { MatchRange, TextTransformer } from '../Transform/index.js';
5
+ import type { TextValidationFactoryOptions, TextValidator } from './lineValidatorFactory.js';
6
+ /**
7
+ * What a `DocumentValidator` needs to spell check its document.
8
+ */
9
+ export interface Preparations {
10
+ /** loaded config */
11
+ config: CSpellSettingsInternal;
12
+ dictionary: SpellingDictionaryCollection;
13
+ /** configuration after applying in-doc settings */
14
+ docSettings: CSpellSettingsInternal;
15
+ finalSettings: CSpellSettingsInternalFinalized;
16
+ includeRanges: MatchRange[];
17
+ textValidator: TextValidator;
18
+ segmenter: (texts: MappedText) => Iterable<MappedText>;
19
+ shouldCheck: boolean;
20
+ validateOptions: TextValidationFactoryOptions;
21
+ localConfig: CSpellUserSettings | undefined;
22
+ localConfigFilepath: string | undefined;
23
+ transformer: TextTransformer;
24
+ }
25
+ /**
26
+ * The preparations that depend on the document's settings. They are replaced when the document changes.
27
+ */
28
+ export interface DocumentSettingsPreparations {
29
+ dictionary: SpellingDictionaryCollection;
30
+ /** configuration after applying in-doc settings */
31
+ docSettings: CSpellSettingsInternal;
32
+ finalSettings: CSpellSettingsInternalFinalized;
33
+ shouldCheck: boolean;
34
+ validateOptions: TextValidationFactoryOptions;
35
+ textValidator: TextValidator;
36
+ transformer: TextTransformer;
37
+ /**
38
+ * Runs every ignore pattern over the whole document, so it is only called once the include ranges are needed.
39
+ */
40
+ calcIncludeRanges: () => MatchRange[];
41
+ }
42
+ /**
43
+ * The include ranges, and the segmenter built from them, are calculated on first use. A document that
44
+ * is never checked never pays for them.
45
+ */
46
+ export declare class DocumentValidatorPreparations implements Preparations {
47
+ #private;
48
+ readonly config: CSpellSettingsInternal;
49
+ readonly localConfig: CSpellUserSettings | undefined;
50
+ readonly localConfigFilepath: string | undefined;
51
+ dictionary: SpellingDictionaryCollection;
52
+ /** configuration after applying in-doc settings */
53
+ docSettings: CSpellSettingsInternal;
54
+ finalSettings: CSpellSettingsInternalFinalized;
55
+ shouldCheck: boolean;
56
+ validateOptions: TextValidationFactoryOptions;
57
+ textValidator: TextValidator;
58
+ transformer: TextTransformer;
59
+ /**
60
+ * @param config - loaded config
61
+ * @param localConfig - the config file found for the document, if any.
62
+ * @param localConfigFilepath - the path of `localConfig`.
63
+ * @param prep - the preparations that depend on the document's settings.
64
+ */
65
+ constructor(config: CSpellSettingsInternal, localConfig: CSpellUserSettings | undefined, localConfigFilepath: string | undefined, prep: DocumentSettingsPreparations);
66
+ /**
67
+ * Replace the preparations that depend on the document's settings. The include ranges are
68
+ * calculated again on next use.
69
+ */
70
+ update(prep: DocumentSettingsPreparations): void;
71
+ get includeRanges(): MatchRange[];
72
+ get segmenter(): (texts: MappedText) => Iterable<MappedText>;
73
+ }
74
+ //# sourceMappingURL=docValidatorPreparations.d.ts.map
@@ -0,0 +1,63 @@
1
+ import { createMappedTextSegmenter } from '../Transform/index.js';
2
+ /**
3
+ * The include ranges, and the segmenter built from them, are calculated on first use. A document that
4
+ * is never checked never pays for them.
5
+ */
6
+ export class DocumentValidatorPreparations {
7
+ config;
8
+ localConfig;
9
+ localConfigFilepath;
10
+ dictionary;
11
+ /** configuration after applying in-doc settings */
12
+ docSettings;
13
+ finalSettings;
14
+ shouldCheck;
15
+ validateOptions;
16
+ textValidator;
17
+ transformer;
18
+ #calcIncludeRanges;
19
+ #includeRanges;
20
+ #segmenter;
21
+ /**
22
+ * @param config - loaded config
23
+ * @param localConfig - the config file found for the document, if any.
24
+ * @param localConfigFilepath - the path of `localConfig`.
25
+ * @param prep - the preparations that depend on the document's settings.
26
+ */
27
+ constructor(config, localConfig, localConfigFilepath, prep) {
28
+ this.config = config;
29
+ this.localConfig = localConfig;
30
+ this.localConfigFilepath = localConfigFilepath;
31
+ this.dictionary = prep.dictionary;
32
+ this.docSettings = prep.docSettings;
33
+ this.finalSettings = prep.finalSettings;
34
+ this.shouldCheck = prep.shouldCheck;
35
+ this.validateOptions = prep.validateOptions;
36
+ this.textValidator = prep.textValidator;
37
+ this.transformer = prep.transformer;
38
+ this.#calcIncludeRanges = prep.calcIncludeRanges;
39
+ }
40
+ /**
41
+ * Replace the preparations that depend on the document's settings. The include ranges are
42
+ * calculated again on next use.
43
+ */
44
+ update(prep) {
45
+ this.dictionary = prep.dictionary;
46
+ this.docSettings = prep.docSettings;
47
+ this.finalSettings = prep.finalSettings;
48
+ this.shouldCheck = prep.shouldCheck;
49
+ this.validateOptions = prep.validateOptions;
50
+ this.textValidator = prep.textValidator;
51
+ this.transformer = prep.transformer;
52
+ this.#calcIncludeRanges = prep.calcIncludeRanges;
53
+ this.#includeRanges = undefined;
54
+ this.#segmenter = undefined;
55
+ }
56
+ get includeRanges() {
57
+ return (this.#includeRanges ??= this.#calcIncludeRanges());
58
+ }
59
+ get segmenter() {
60
+ return (this.#segmenter ??= createMappedTextSegmenter(this.includeRanges));
61
+ }
62
+ }
63
+ //# sourceMappingURL=docValidatorPreparations.js.map
package/dist/rpc.d.ts CHANGED
@@ -1,2 +1,47 @@
1
- export * from '@cspell/rpc';
1
+ export type {
2
+ /** @deprecated Import from `@cspell/rpc` instead. */
3
+ MessagePortLike,
4
+ /** @deprecated Import from `@cspell/rpc` instead. */
5
+ NotifyEvent,
6
+ /** @deprecated Import from `@cspell/rpc` instead. */
7
+ NotifyHandler,
8
+ /** @deprecated Import from `@cspell/rpc` instead. */
9
+ NotifyOnceEvent,
10
+ /** @deprecated Import from `@cspell/rpc` instead. */
11
+ RPCClientConfiguration,
12
+ /** @deprecated Import from `@cspell/rpc` instead. */
13
+ RPCClientOptions,
14
+ /** @deprecated Import from `@cspell/rpc` instead. */
15
+ RPCProtocol,
16
+ /** @deprecated Import from `@cspell/rpc` instead. */
17
+ RPCProtocolMethods,
18
+ /** @deprecated Import from `@cspell/rpc` instead. */
19
+ RPCServerConfiguration,
20
+ /** @deprecated Import from `@cspell/rpc` instead. */
21
+ RPCServerOptions, } from '@cspell/rpc';
22
+ export {
23
+ /** @deprecated Import from `@cspell/rpc` instead. */
24
+ AbortRPCRequestError,
25
+ /** @deprecated Import from `@cspell/rpc` instead. */
26
+ CanceledRPCRequestError,
27
+ /** @deprecated Import from `@cspell/rpc` instead. */
28
+ NotifyEmitter,
29
+ /** @deprecated Import from `@cspell/rpc` instead. */
30
+ notifyEventOnce,
31
+ /** @deprecated Import from `@cspell/rpc` instead. */
32
+ notifyEventToPromise,
33
+ /** @deprecated Import from `@cspell/rpc` instead. */
34
+ protocolDefinition,
35
+ /** @deprecated Import from `@cspell/rpc` instead. */
36
+ protocolMethods,
37
+ /** @deprecated Import from `@cspell/rpc` instead. */
38
+ RPCClient,
39
+ /** @deprecated Import from `@cspell/rpc` instead. */
40
+ RPCRequestError,
41
+ /** @deprecated Import from `@cspell/rpc` instead. */
42
+ RPCServer,
43
+ /** @deprecated Import from `@cspell/rpc` instead. */
44
+ TimeoutRPCRequestError,
45
+ /** @deprecated Import from `@cspell/rpc` instead. */
46
+ UnknownMethodRPCRequestError, } from '@cspell/rpc';
2
47
  //# sourceMappingURL=rpc.d.ts.map
package/dist/rpc.js CHANGED
@@ -1,2 +1,26 @@
1
- export * from '@cspell/rpc';
1
+ export {
2
+ /** @deprecated Import from `@cspell/rpc` instead. */
3
+ AbortRPCRequestError,
4
+ /** @deprecated Import from `@cspell/rpc` instead. */
5
+ CanceledRPCRequestError,
6
+ /** @deprecated Import from `@cspell/rpc` instead. */
7
+ NotifyEmitter,
8
+ /** @deprecated Import from `@cspell/rpc` instead. */
9
+ notifyEventOnce,
10
+ /** @deprecated Import from `@cspell/rpc` instead. */
11
+ notifyEventToPromise,
12
+ /** @deprecated Import from `@cspell/rpc` instead. */
13
+ protocolDefinition,
14
+ /** @deprecated Import from `@cspell/rpc` instead. */
15
+ protocolMethods,
16
+ /** @deprecated Import from `@cspell/rpc` instead. */
17
+ RPCClient,
18
+ /** @deprecated Import from `@cspell/rpc` instead. */
19
+ RPCRequestError,
20
+ /** @deprecated Import from `@cspell/rpc` instead. */
21
+ RPCServer,
22
+ /** @deprecated Import from `@cspell/rpc` instead. */
23
+ TimeoutRPCRequestError,
24
+ /** @deprecated Import from `@cspell/rpc` instead. */
25
+ UnknownMethodRPCRequestError, } from '@cspell/rpc';
2
26
  //# sourceMappingURL=rpc.js.map
package/package.json CHANGED
@@ -1,15 +1,35 @@
1
1
  {
2
2
  "name": "cspell-lib",
3
+ "version": "10.4.0-alpha.1",
4
+ "description": "A library of useful functions used across various cspell tools.",
3
5
  "publishConfig": {
4
6
  "access": "public",
5
7
  "provenance": true
6
8
  },
7
- "version": "10.3.5",
8
- "description": "A library of useful functions used across various cspell tools.",
9
- "type": "module",
9
+ "homepage": "https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell-lib#readme",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/streetsidesoftware/cspell.git",
13
+ "directory": "packages/cspell-lib"
14
+ },
15
+ "bugs": {
16
+ "url": "https://github.com/streetsidesoftware/cspell/issues?q=is%3Aissue%20state%3Aopen%20label%3Acspell-lib"
17
+ },
18
+ "keywords": [
19
+ "spell",
20
+ "checker",
21
+ "code",
22
+ "camel",
23
+ "case",
24
+ "spelling",
25
+ "spell checker",
26
+ "spelling checker",
27
+ "lint"
28
+ ],
29
+ "license": "MIT",
30
+ "author": "Jason Dent",
10
31
  "sideEffects": false,
11
- "types": "dist/index.d.ts",
12
- "module": "dist/index.js",
32
+ "type": "module",
13
33
  "exports": {
14
34
  ".": {
15
35
  "import": "./dist/index.js"
@@ -27,6 +47,8 @@
27
47
  "import": "./dist/cspell-rpc/client.js"
28
48
  }
29
49
  },
50
+ "module": "dist/index.js",
51
+ "types": "dist/index.d.ts",
30
52
  "files": [
31
53
  "dist",
32
54
  "!**/*.tsbuildInfo",
@@ -38,82 +60,56 @@
38
60
  "!**/*.map"
39
61
  ],
40
62
  "scripts": {
41
- "clean": "shx rm -rf dist temp coverage \"*.tsbuildInfo\"",
42
- "clean-build": "pnpm clean && pnpm build",
43
63
  "build": "tsc -p . && pnpm run build:api",
44
64
  "build:api": "tsdown",
45
- "watch": "tsc -p . --watch",
65
+ "clean": "shx rm -rf dist temp coverage \"*.tsbuildInfo\"",
66
+ "clean-build": "pnpm clean && pnpm build",
46
67
  "coverage": "vitest run --coverage --pool=forks",
47
- "test-watch": "vitest",
48
68
  "prepublishOnly": "pnpm run clean-build",
49
69
  "test": "vitest run --pool=forks",
50
- "test:update-snapshot": "vitest run -u",
51
70
  "test:perf": "NODE_ENV=production insight --file \"**/*.perf.{mjs,js}\"",
71
+ "test:perf:prof": "NODE_ENV=production node --cpu-prof ../../node_modules/perf-insight/bin.mjs --file \"dist/**/*.perf.{mjs,js}\" -t 1000",
52
72
  "test:perf:ts": "NODE_ENV=production insight --file \"**/*.perf.{mts,ts}\" ",
53
- "test:perf:prof": "NODE_ENV=production node --cpu-prof ../../node_modules/perf-insight/bin.mjs --file \"dist/**/*.perf.{mjs,js}\" -t 1000"
54
- },
55
- "repository": {
56
- "type": "git",
57
- "url": "https://github.com/streetsidesoftware/cspell.git",
58
- "directory": "packages/cspell-lib"
59
- },
60
- "keywords": [
61
- "spell",
62
- "checker",
63
- "code",
64
- "camel",
65
- "case",
66
- "spelling",
67
- "spell checker",
68
- "spelling checker",
69
- "lint"
70
- ],
71
- "author": "Jason Dent",
72
- "license": "MIT",
73
- "bugs": {
74
- "url": "https://github.com/streetsidesoftware/cspell/labels/cspell-lib"
73
+ "test:update-snapshot": "vitest run -u",
74
+ "test-watch": "vitest",
75
+ "watch": "tsc -p . --watch"
75
76
  },
76
- "homepage": "https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell-lib#readme",
77
77
  "dependencies": {
78
- "@cspell/cspell-bundled-dicts": "10.3.5",
79
- "@cspell/cspell-performance-monitor": "10.3.5",
80
- "@cspell/cspell-pipe": "10.3.5",
81
- "@cspell/cspell-resolver": "10.3.5",
82
- "@cspell/cspell-types": "10.3.5",
83
- "@cspell/dynamic-import": "10.3.5",
84
- "@cspell/filetypes": "10.3.5",
85
- "@cspell/rpc": "10.3.5",
86
- "@cspell/strong-weak-map": "10.3.5",
87
- "@cspell/url": "10.3.5",
88
- "cspell-config-lib": "10.3.5",
89
- "cspell-dictionary": "10.3.5",
90
- "cspell-glob": "10.3.5",
91
- "cspell-grammar": "10.3.5",
92
- "cspell-io": "10.3.5",
93
- "cspell-trie-lib": "10.3.5",
78
+ "@cspell/cspell-bundled-dicts": "10.4.0-alpha.1",
79
+ "@cspell/cspell-performance-monitor": "10.4.0-alpha.1",
80
+ "@cspell/cspell-pipe": "10.4.0-alpha.1",
81
+ "@cspell/cspell-resolver": "10.4.0-alpha.1",
82
+ "@cspell/cspell-types": "10.4.0-alpha.1",
83
+ "@cspell/dynamic-import": "10.4.0-alpha.1",
84
+ "@cspell/filetypes": "10.4.0-alpha.1",
85
+ "@cspell/rpc": "10.4.0-alpha.1",
86
+ "@cspell/strong-weak-map": "10.4.0-alpha.1",
87
+ "@cspell/url": "10.4.0-alpha.1",
88
+ "cspell-config-lib": "10.4.0-alpha.1",
89
+ "cspell-dictionary": "10.4.0-alpha.1",
90
+ "cspell-glob": "10.4.0-alpha.1",
91
+ "cspell-grammar": "10.4.0-alpha.1",
92
+ "cspell-io": "10.4.0-alpha.1",
93
+ "cspell-trie-lib": "10.4.0-alpha.1",
94
94
  "env-paths": "^4.0.0",
95
95
  "gensequence": "^8.0.8",
96
- "import-fresh": "^4.0.0",
96
+ "import-fresh": "^4.0.1",
97
97
  "resolve-from": "^5.0.0",
98
- "vscode-languageserver-textdocument": "^1.0.14",
98
+ "vscode-languageserver-textdocument": "^1.0.15",
99
99
  "vscode-uri": "^3.2.0",
100
100
  "xdg-basedir": "^5.1.0"
101
101
  },
102
- "engines": {
103
- "node": ">=22.18.0"
104
- },
105
102
  "devDependencies": {
106
- "@cspell/cspell-tools": "10.3.5",
107
- "@cspell/dict-cpp": "^7.1.0",
103
+ "@cspell/dict-cpp": "^7.1.2",
108
104
  "@cspell/dict-csharp": "^4.0.8",
109
105
  "@cspell/dict-css": "^4.1.2",
110
- "@cspell/dict-en_us": "^4.4.37",
106
+ "@cspell/dict-en_us": "^4.4.40",
111
107
  "@cspell/dict-fa-ir": "^4.0.5",
112
108
  "@cspell/dict-fr-fr": "^2.3.2",
113
109
  "@cspell/dict-html": "^4.0.16",
114
110
  "@cspell/dict-nl-nl": "^2.4.2",
115
- "@cspell/dict-python": "^4.5.0",
116
- "@cspell/dict-th-th": "^1.0.0",
111
+ "@cspell/dict-python": "^4.5.2",
112
+ "@cspell/dict-th-th": "^1.0.1",
117
113
  "@cspell/dictionary-bundler-plugin": "",
118
114
  "@types/configstore": "^6.0.2",
119
115
  "comment-json": "^5.0.0",
@@ -123,5 +119,8 @@
123
119
  "lorem-ipsum": "^3.0.0",
124
120
  "perf-insight": "^2.0.1"
125
121
  },
126
- "gitHead": "f37a244a54b686fc1ac11272d6019b9a059b062a"
122
+ "engines": {
123
+ "node": ">=22.18.0"
124
+ },
125
+ "gitHead": "628768a6e62b792e628189b41e63e12e5d3d8fe3"
127
126
  }
package/dist/api.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './lib/index.js';
2
- //# sourceMappingURL=api.d.ts.map
package/dist/api.js DELETED
@@ -1,2 +0,0 @@
1
- export * from './lib/index.js';
2
- //# sourceMappingURL=api.js.map