cspell-lib 5.19.1 → 5.19.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.
@@ -6,6 +6,11 @@ export interface CSpellSettingsInternal extends Omit<CSpellSettingsWithSourceTra
6
6
  [SymbolCSpellSettingsInternal]: true;
7
7
  dictionaryDefinitions?: DictionaryDefinitionInternal[];
8
8
  }
9
+ export interface CSpellSettingsInternalFinalized extends CSpellSettingsInternal {
10
+ finalized: true;
11
+ ignoreRegExpList: RegExp[];
12
+ includeRegExpList: RegExp[];
13
+ }
9
14
  declare type DictionaryDefinitionCustomUniqueFields = Omit<DictionaryDefinitionCustom, keyof DictionaryDefinitionPreferred>;
10
15
  export interface DictionaryDefinitionInternal extends Readonly<DictionaryDefinitionPreferred>, Readonly<Partial<DictionaryDefinitionCustomUniqueFields>>, Readonly<DictionaryDefinitionAugmented> {
11
16
  /**
@@ -1,5 +1,5 @@
1
1
  import type { CSpellSettingsWithSourceTrace, Glob, ImportFileRef } from '@cspell/cspell-types';
2
- import { CSpellSettingsInternal } from '../Models/CSpellSettingsInternalDef';
2
+ import { CSpellSettingsInternal, CSpellSettingsInternalFinalized } from '../Models/CSpellSettingsInternalDef';
3
3
  import { OptionalOrUndefined } from '../util/types';
4
4
  declare type CSpellSettingsWST = CSpellSettingsWithSourceTrace;
5
5
  declare type CSpellSettingsWSTO = OptionalOrUndefined<CSpellSettingsWithSourceTrace>;
@@ -20,7 +20,7 @@ export declare function calcOverrideSettings(settings: CSpellSettingsWSTO, filen
20
20
  * @param settings - settings to finalize
21
21
  * @returns settings where all globs and file paths have been resolved.
22
22
  */
23
- export declare function finalizeSettings(settings: CSpellSettingsWSTO | CSpellSettingsI): CSpellSettingsI;
23
+ export declare function finalizeSettings(settings: CSpellSettingsWSTO | CSpellSettingsI): CSpellSettingsInternalFinalized;
24
24
  export declare function toInternalSettings(settings: undefined): undefined;
25
25
  export declare function toInternalSettings(settings: CSpellSettingsI | CSpellSettingsWSTO): CSpellSettingsI;
26
26
  export declare function toInternalSettings(settings?: CSpellSettingsI | CSpellSettingsWSTO): CSpellSettingsI | undefined;
@@ -221,6 +221,7 @@ function _finalizeSettings(settings) {
221
221
  // apply patterns to any RegExpLists.
222
222
  const finalized = {
223
223
  ...settings,
224
+ finalized: true,
224
225
  ignoreRegExpList: (0, patterns_1.resolvePatterns)(settings.ignoreRegExpList, settings.patterns),
225
226
  includeRegExpList: (0, patterns_1.resolvePatterns)(settings.includeRegExpList, settings.patterns),
226
227
  };
@@ -1,3 +1,3 @@
1
1
  import type { RegExpPatternDefinition } from '@cspell/cspell-types';
2
- export declare function resolvePatterns(regExpList?: (string | RegExp)[], patternDefinitions?: RegExpPatternDefinition[]): (string | RegExp)[];
2
+ export declare function resolvePatterns(regExpList?: (string | RegExp)[], patternDefinitions?: RegExpPatternDefinition[]): RegExp[];
3
3
  //# sourceMappingURL=patterns.d.ts.map
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolvePatterns = void 0;
4
+ const text_1 = require("../util/text");
4
5
  const util_1 = require("../util/util");
5
6
  function resolvePatterns(regExpList = [], patternDefinitions = []) {
6
7
  const patternMap = new Map(patternDefinitions.map((def) => [def.name.toLowerCase(), def.pattern]));
@@ -22,7 +23,10 @@ function resolvePatterns(regExpList = [], patternDefinitions = []) {
22
23
  }
23
24
  }
24
25
  const patternList = regExpList.map(resolvePattern).filter(util_1.isDefined);
25
- return [...flatten(patternList)];
26
+ return [...flatten(patternList)].map(toRegExp).filter(util_1.isDefined);
26
27
  }
27
28
  exports.resolvePatterns = resolvePatterns;
29
+ function toRegExp(pattern) {
30
+ return pattern instanceof RegExp ? new RegExp(pattern) : (0, text_1.stringToRegExp)(pattern, 'gim', 'g');
31
+ }
28
32
  //# sourceMappingURL=patterns.js.map
@@ -25,6 +25,7 @@ export declare class DocumentValidator {
25
25
  readonly errors: Error[];
26
26
  private _prepared;
27
27
  private _preparations;
28
+ private _preparationTime;
28
29
  /**
29
30
  * @param doc - Document to validate
30
31
  * @param config - configuration to use (not finalized).
@@ -34,6 +35,10 @@ export declare class DocumentValidator {
34
35
  prepareSync(): void;
35
36
  prepare(): Promise<void>;
36
37
  private _prepareAsync;
38
+ /**
39
+ * The amount of time in ms to prepare for validation.
40
+ */
41
+ get prepTime(): number;
37
42
  checkText(range: SimpleRange, _text: string, _scope: string[]): ValidationIssue[];
38
43
  get document(): TextDocument;
39
44
  private addPossibleError;
@@ -4,11 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.DocumentValidator = void 0;
7
+ const cspell_pipe_1 = require("@cspell/cspell-pipe");
7
8
  const assert_1 = __importDefault(require("assert"));
8
9
  const Settings_1 = require("../Settings");
9
10
  const configLoader_1 = require("../Settings/configLoader");
10
11
  const SpellingDictionary_1 = require("../SpellingDictionary");
11
12
  const errors_1 = require("../util/errors");
13
+ const timer_1 = require("../util/timer");
12
14
  const util_1 = require("../util/util");
13
15
  const determineTextDocumentSettings_1 = require("./determineTextDocumentSettings");
14
16
  const textValidator_1 = require("./textValidator");
@@ -23,7 +25,9 @@ class DocumentValidator {
23
25
  this.settings = settings;
24
26
  this._ready = false;
25
27
  this.errors = [];
28
+ this._preparationTime = -1;
26
29
  this._document = doc;
30
+ // console.error(`DocumentValidator: ${doc.uri}`);
27
31
  }
28
32
  get ready() {
29
33
  return this._ready;
@@ -36,6 +40,7 @@ class DocumentValidator {
36
40
  // Load dictionaries
37
41
  if (this._ready)
38
42
  return;
43
+ const timer = (0, timer_1.createTimer)();
39
44
  const { options, settings } = this;
40
45
  const useSearchForConfig = (!options.noConfigSearch && !settings.noConfigSearch) || options.noConfigSearch === false;
41
46
  const optionsConfigFile = options.configFile;
@@ -49,8 +54,9 @@ class DocumentValidator {
49
54
  const docSettings = (0, determineTextDocumentSettings_1.determineTextDocumentSettings)(this._document, config);
50
55
  const dict = (0, SpellingDictionary_1.getDictionaryInternalSync)(docSettings);
51
56
  const shouldCheck = (_b = docSettings.enabled) !== null && _b !== void 0 ? _b : true;
52
- const validateOptions = (0, validator_1.settingsToValidateOptions)(docSettings);
53
- const includeRanges = (0, textValidator_1.calcTextInclusionRanges)(this._document.text, docSettings);
57
+ const finalSettings = (0, Settings_1.finalizeSettings)(docSettings);
58
+ const validateOptions = (0, validator_1.settingsToValidateOptions)(finalSettings);
59
+ const includeRanges = (0, textValidator_1.calcTextInclusionRanges)(this._document.text, validateOptions);
54
60
  const segmenter = (0, textValidator_1.mapLineSegmentAgainstRangesFactory)(includeRanges);
55
61
  const lineValidator = (0, textValidator_1.lineValidatorFactory)(dict, validateOptions);
56
62
  this._preparations = {
@@ -63,6 +69,7 @@ class DocumentValidator {
63
69
  lineValidator,
64
70
  };
65
71
  this._ready = true;
72
+ this._preparationTime = timer.elapsed();
66
73
  }
67
74
  async prepare() {
68
75
  if (this._ready)
@@ -75,6 +82,7 @@ class DocumentValidator {
75
82
  async _prepareAsync() {
76
83
  var _a, _b;
77
84
  (0, assert_1.default)(!this._ready);
85
+ const timer = (0, timer_1.createTimer)();
78
86
  const { options, settings } = this;
79
87
  const useSearchForConfig = (!options.noConfigSearch && !settings.noConfigSearch) || options.noConfigSearch === false;
80
88
  const pLocalConfig = options.configFile
@@ -88,8 +96,9 @@ class DocumentValidator {
88
96
  const docSettings = (0, determineTextDocumentSettings_1.determineTextDocumentSettings)(this._document, config);
89
97
  const dict = await (0, SpellingDictionary_1.getDictionaryInternal)(docSettings);
90
98
  const shouldCheck = (_b = docSettings.enabled) !== null && _b !== void 0 ? _b : true;
91
- const validateOptions = (0, validator_1.settingsToValidateOptions)(docSettings);
92
- const includeRanges = (0, textValidator_1.calcTextInclusionRanges)(this._document.text, docSettings);
99
+ const finalSettings = (0, Settings_1.finalizeSettings)(docSettings);
100
+ const validateOptions = (0, validator_1.settingsToValidateOptions)(finalSettings);
101
+ const includeRanges = (0, textValidator_1.calcTextInclusionRanges)(this._document.text, validateOptions);
93
102
  const segmenter = (0, textValidator_1.mapLineSegmentAgainstRangesFactory)(includeRanges);
94
103
  const lineValidator = (0, textValidator_1.lineValidatorFactory)(dict, validateOptions);
95
104
  this._preparations = {
@@ -102,11 +111,19 @@ class DocumentValidator {
102
111
  lineValidator,
103
112
  };
104
113
  this._ready = true;
114
+ this._preparationTime = timer.elapsed();
115
+ }
116
+ /**
117
+ * The amount of time in ms to prepare for validation.
118
+ */
119
+ get prepTime() {
120
+ return this._preparationTime;
105
121
  }
106
122
  checkText(range, _text, _scope) {
107
123
  var _a;
108
124
  (0, assert_1.default)(this._ready);
109
125
  (0, assert_1.default)(this._preparations);
126
+ const { segmenter, lineValidator } = this._preparations;
110
127
  // Determine settings for text range
111
128
  // Slice text based upon include ranges
112
129
  // Check text against dictionaries.
@@ -121,7 +138,8 @@ class DocumentValidator {
121
138
  offset,
122
139
  },
123
140
  };
124
- const issues = [...this._preparations.lineValidator(lineSeg)];
141
+ const aIssues = (0, cspell_pipe_1.pipeSync)(segmenter(lineSeg), (0, cspell_pipe_1.opConcatMap)(lineValidator));
142
+ const issues = [...aIssues];
125
143
  if (!this.options.generateSuggestions) {
126
144
  return issues;
127
145
  }
@@ -17,8 +17,8 @@ export interface CheckOptions extends ValidationOptions {
17
17
  ignoreCase: boolean;
18
18
  }
19
19
  export interface IncludeExcludeOptions {
20
- ignoreRegExpList?: (RegExp | string)[];
21
- includeRegExpList?: (RegExp | string)[];
20
+ ignoreRegExpList?: RegExp[];
21
+ includeRegExpList?: RegExp[];
22
22
  }
23
23
  export interface WordRangeAcc {
24
24
  textOffset: TextOffsetRO;
@@ -54,7 +54,7 @@ exports.validateText = validateText;
54
54
  function calcTextInclusionRanges(text, options) {
55
55
  const { ignoreRegExpList = [], includeRegExpList = [] } = options;
56
56
  const filteredIncludeList = includeRegExpList.filter((a) => !!a);
57
- const finalIncludeList = filteredIncludeList.length ? filteredIncludeList : ['.*'];
57
+ const finalIncludeList = filteredIncludeList.length ? filteredIncludeList : [/.*/gim];
58
58
  const includeRanges = TextRange.excludeRanges(TextRange.findMatchingRangesForPatterns(finalIncludeList, text), TextRange.findMatchingRangesForPatterns(ignoreRegExpList, text));
59
59
  return includeRanges;
60
60
  }
@@ -1,4 +1,5 @@
1
1
  import type { CSpellUserSettings } from '@cspell/cspell-types';
2
+ import { CSpellSettingsInternalFinalized } from '../Models/CSpellSettingsInternalDef';
2
3
  import type { ValidationOptions, ValidationResult } from './textValidator';
3
4
  export declare const diagSource = "cSpell Checker";
4
5
  export interface ValidationIssue extends ValidationResult {
@@ -11,7 +12,7 @@ export interface ValidateTextOptions {
11
12
  numSuggestions?: number;
12
13
  }
13
14
  export declare function validateText(text: string, settings: CSpellUserSettings, options?: ValidateTextOptions): Promise<ValidationIssue[]>;
14
- export declare function settingsToValidateOptions(settings: CSpellUserSettings): ValidationOptions;
15
+ export declare function settingsToValidateOptions(settings: CSpellSettingsInternalFinalized): ValidationOptions;
15
16
  export interface CheckTextInfo {
16
17
  text: string;
17
18
  items: TextInfoItem[];
@@ -8,9 +8,9 @@ export interface MatchRangeWithText extends MatchRange {
8
8
  export interface MatchRangeOptionalText extends MatchRange {
9
9
  text?: string;
10
10
  }
11
- export declare function findMatchingRanges(pattern: string | RegExp, text: string): MatchRangeOptionalText[];
11
+ export declare function findMatchingRanges(pattern: RegExp, text: string): MatchRangeOptionalText[];
12
12
  export declare function unionRanges(ranges: MatchRange[]): MatchRange[];
13
- export declare function findMatchingRangesForPatterns(patterns: (string | RegExp)[], text: string): MatchRange[];
13
+ export declare function findMatchingRangesForPatterns(patterns: RegExp[], text: string): MatchRange[];
14
14
  /**
15
15
  * Create a new set of positions that have the excluded position ranges removed.
16
16
  */
@@ -25,7 +25,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.__testing__ = exports.extractRangeText = exports.excludeRanges = exports.findMatchingRangesForPatterns = exports.unionRanges = exports.findMatchingRanges = void 0;
27
27
  const GS = __importStar(require("gensequence"));
28
- const Text = __importStar(require("./text"));
29
28
  function toMatchRangeWithText(m) {
30
29
  const index = m.index || 0;
31
30
  const _text = m[0];
@@ -36,26 +35,17 @@ function toMatchRangeWithText(m) {
36
35
  };
37
36
  }
38
37
  function findMatchingRanges(pattern, text) {
39
- if (pattern === '.*') {
38
+ if (pattern.source === '.*') {
40
39
  return [{ startPos: 0, endPos: text.length }];
41
40
  }
42
- try {
43
- const regex = pattern instanceof RegExp ? new RegExp(pattern) : Text.stringToRegExp(pattern, 'gim', 'g');
44
- if (regex) {
45
- if (!regex.global) {
46
- const m = text.match(regex);
47
- if (!m)
48
- return [];
49
- return [toMatchRangeWithText(m)];
50
- }
51
- return [...text.matchAll(regex)].map(toMatchRangeWithText);
52
- }
53
- }
54
- catch (e) {
55
- // ignore any malformed regexp from the user.
56
- // console.log(e.message);
41
+ const regex = new RegExp(pattern);
42
+ if (!regex.global) {
43
+ const m = text.match(regex);
44
+ if (!m)
45
+ return [];
46
+ return [toMatchRangeWithText(m)];
57
47
  }
58
- return [];
48
+ return [...text.matchAll(regex)].map(toMatchRangeWithText);
59
49
  }
60
50
  exports.findMatchingRanges = findMatchingRanges;
61
51
  function compareRanges(a, b) {
@@ -0,0 +1,15 @@
1
+ export interface Timer {
2
+ /** Start / restart the timer. */
3
+ start(): void;
4
+ /**
5
+ * Calculate the amount of time in ms since the
6
+ * timer was created / started.
7
+ */
8
+ elapsed(): number;
9
+ }
10
+ export declare function createTimer(hrTimeFn?: HRTimeFn): Timer;
11
+ export declare type HRTimeFn = (time?: HRTime) => HRTime;
12
+ export declare type HRTime = [number, number];
13
+ export declare function toMilliseconds(t: HRTime): number;
14
+ export declare function polyHrTime(time?: HRTime): HRTime;
15
+ //# sourceMappingURL=timer.d.ts.map
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.polyHrTime = exports.toMilliseconds = exports.createTimer = void 0;
4
+ const _hrTime = (process === null || process === void 0 ? void 0 : process.hrtime) || polyHrTime;
5
+ function createTimer(hrTimeFn = _hrTime) {
6
+ let start = hrTimeFn();
7
+ return {
8
+ start() {
9
+ start = hrTimeFn();
10
+ },
11
+ elapsed() {
12
+ return toMilliseconds(hrTimeFn(start));
13
+ },
14
+ };
15
+ }
16
+ exports.createTimer = createTimer;
17
+ function toMilliseconds(t) {
18
+ return (t[0] + t[1] * 1e-9) * 1000;
19
+ }
20
+ exports.toMilliseconds = toMilliseconds;
21
+ function polyHrTime(time) {
22
+ const now = Date.now() - (time ? toMilliseconds(time) : 0);
23
+ const inSeconds = now * 1.0e-3;
24
+ const s = Math.floor(inSeconds);
25
+ const n = (inSeconds - s) * 1.0e9;
26
+ return [s, n];
27
+ }
28
+ exports.polyHrTime = polyHrTime;
29
+ //# sourceMappingURL=timer.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cspell-lib",
3
- "version": "5.19.1",
3
+ "version": "5.19.2",
4
4
  "description": "A library of useful functions used across various cspell tools.",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -48,16 +48,16 @@
48
48
  },
49
49
  "homepage": "https://github.com/streetsidesoftware/cspell#readme",
50
50
  "dependencies": {
51
- "@cspell/cspell-bundled-dicts": "^5.19.1",
52
- "@cspell/cspell-pipe": "^5.19.1",
53
- "@cspell/cspell-types": "^5.19.1",
51
+ "@cspell/cspell-bundled-dicts": "^5.19.2",
52
+ "@cspell/cspell-pipe": "^5.19.2",
53
+ "@cspell/cspell-types": "^5.19.2",
54
54
  "clear-module": "^4.1.2",
55
55
  "comment-json": "^4.2.2",
56
56
  "configstore": "^5.0.1",
57
57
  "cosmiconfig": "^7.0.1",
58
- "cspell-glob": "^5.19.1",
59
- "cspell-io": "^5.19.1",
60
- "cspell-trie-lib": "^5.19.1",
58
+ "cspell-glob": "^5.19.2",
59
+ "cspell-io": "^5.19.2",
60
+ "cspell-trie-lib": "^5.19.2",
61
61
  "fast-equals": "^3.0.0",
62
62
  "find-up": "^5.0.0",
63
63
  "fs-extra": "^10.0.1",
@@ -92,5 +92,5 @@
92
92
  "rollup-plugin-dts": "^4.2.0",
93
93
  "ts-jest": "^27.1.3"
94
94
  },
95
- "gitHead": "622cd59a44bf1f76d538e3cf37983f387c5423e8"
95
+ "gitHead": "6540cb9f716993c554dc50dd54dd76d553f8f5e4"
96
96
  }