cspell 6.26.2 → 6.27.0

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/README.md CHANGED
@@ -242,12 +242,18 @@ Options:
242
242
  looks for cspell.json in the current directory.
243
243
  --locale <locale> Set language locales. i.e. "en,fr" for English
244
244
  and French, or "en-GB" for British English.
245
- --language-id <language> Use programming language. i.e. "php" or "scala"
245
+ --language-id <language> Use programming language. i.e. "php" or "scala".
246
246
  --allow-compound-words Turn on allowCompoundWords
247
247
  --no-allow-compound-words Turn off allowCompoundWords
248
+ --ignore-case Ignore case and accents when searching for words.
248
249
  --no-ignore-case Do not ignore case and accents when searching for
249
- words
250
+ words.
251
+ --dictionary-path <format> Configure how to display the dictionary path.
252
+ (choices: "hide", "short", "long", "full",
253
+ default: Display most of the path.)
250
254
  --stdin Read words from stdin.
255
+ --all Show all dictionaries.
256
+ --only-found Show only dictionaries that have the words.
251
257
  --no-color Turn off color.
252
258
  --color Force color
253
259
  --no-default-configuration Do not load the default configuration and
@@ -26,6 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.commandTrace = void 0;
27
27
  const commander_1 = require("commander");
28
28
  const App = __importStar(require("./application"));
29
+ const DictionaryPathFormat_1 = require("./emitters/DictionaryPathFormat");
29
30
  const traceEmitter_1 = require("./emitters/traceEmitter");
30
31
  const errors_1 = require("./util/errors");
31
32
  function commandTrace(prog) {
@@ -34,13 +35,19 @@ function commandTrace(prog) {
34
35
  .description(`Trace words -- Search for words in the configuration and dictionaries.`)
35
36
  .option('-c, --config <cspell.json>', 'Configuration file to use. By default cspell looks for cspell.json in the current directory.')
36
37
  .option('--locale <locale>', 'Set language locales. i.e. "en,fr" for English and French, or "en-GB" for British English.')
37
- .option('--language-id <language>', 'Use programming language. i.e. "php" or "scala"')
38
- .addOption(new commander_1.Option('--languageId <language>', 'Use programming language. i.e. "php" or "scala"').hideHelp())
38
+ .option('--language-id <language>', 'Use programming language. i.e. "php" or "scala".')
39
+ .addOption(new commander_1.Option('--languageId <language>', 'Use programming language. i.e. "php" or "scala".').hideHelp())
39
40
  .option('--allow-compound-words', 'Turn on allowCompoundWords')
40
- .addOption(new commander_1.Option('--allowCompoundWords', 'Turn on allowCompoundWords').hideHelp())
41
+ .addOption(new commander_1.Option('--allowCompoundWords', 'Turn on allowCompoundWords.').hideHelp())
41
42
  .option('--no-allow-compound-words', 'Turn off allowCompoundWords')
42
- .option('--no-ignore-case', 'Do not ignore case and accents when searching for words')
43
+ .option('--ignore-case', 'Ignore case and accents when searching for words.')
44
+ .option('--no-ignore-case', 'Do not ignore case and accents when searching for words.')
45
+ .addOption(new commander_1.Option('--dictionary-path <format>', 'Configure how to display the dictionary path.')
46
+ .choices(['hide', 'short', 'long', 'full'])
47
+ .default('long', 'Display most of the path.'))
43
48
  .option('--stdin', 'Read words from stdin.')
49
+ .option('--all', 'Show all dictionaries.')
50
+ .addOption(new commander_1.Option('--only-found', 'Show only dictionaries that have the words.').conflicts('all'))
44
51
  .option('--no-color', 'Turn off color.')
45
52
  .option('--color', 'Force color')
46
53
  .addOption(new commander_1.Option('--default-configuration', 'Load the default configuration and dictionaries.').hideHelp())
@@ -49,8 +56,12 @@ function commandTrace(prog) {
49
56
  .action(async (words, options) => {
50
57
  App.parseApplicationFeatureFlags(options.flag);
51
58
  let numFound = 0;
59
+ const dictionaryPathFormat = (0, DictionaryPathFormat_1.isDictionaryPathFormat)(options.dictionaryPath)
60
+ ? options.dictionaryPath
61
+ : 'long';
52
62
  for await (const results of App.trace(words, options)) {
53
- (0, traceEmitter_1.emitTraceResults)(results, { cwd: process.cwd() });
63
+ const filtered = filterTraceResults(results, options);
64
+ (0, traceEmitter_1.emitTraceResults)(filtered, { cwd: process.cwd(), dictionaryPathFormat });
54
65
  numFound += results.reduce((n, r) => n + (r.found ? 1 : 0), 0);
55
66
  const numErrors = results.map((r) => r.errors?.length || 0).reduce((n, r) => n + r, 0);
56
67
  if (numErrors) {
@@ -65,4 +76,12 @@ function commandTrace(prog) {
65
76
  });
66
77
  }
67
78
  exports.commandTrace = commandTrace;
79
+ function filterTraceResults(results, options) {
80
+ if (options.all)
81
+ return results;
82
+ return results.filter((r) => filterTraceResult(r, options.onlyFound));
83
+ }
84
+ function filterTraceResult(result, onlyFound) {
85
+ return result.found || result.forbidden || result.noSuggest || (!onlyFound && result.dictActive);
86
+ }
68
87
  //# sourceMappingURL=commandTrace.js.map
@@ -0,0 +1,3 @@
1
+ export type DictionaryPathFormat = 'hide' | 'long' | 'short' | 'full';
2
+ export declare function isDictionaryPathFormat(value: string | undefined): value is DictionaryPathFormat;
3
+ //# sourceMappingURL=DictionaryPathFormat.d.ts.map
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isDictionaryPathFormat = void 0;
4
+ const formats = {
5
+ full: true,
6
+ hide: true,
7
+ long: true,
8
+ short: true,
9
+ };
10
+ function isDictionaryPathFormat(value) {
11
+ if (!value || typeof value !== 'string')
12
+ return false;
13
+ return value in formats;
14
+ }
15
+ exports.isDictionaryPathFormat = isDictionaryPathFormat;
16
+ //# sourceMappingURL=DictionaryPathFormat.js.map
@@ -1,8 +1,21 @@
1
1
  import type { TraceResult } from '../application';
2
+ import type { DictionaryPathFormat } from './DictionaryPathFormat';
3
+ interface PathInterface {
4
+ relative(from: string, to: string): string;
5
+ basename(path: string): string;
6
+ sep: string;
7
+ }
2
8
  export interface EmitTraceOptions {
3
9
  /** current working directory */
4
10
  cwd: string;
5
11
  lineWidth?: number;
12
+ dictionaryPathFormat: DictionaryPathFormat;
13
+ iPath?: PathInterface;
6
14
  }
7
15
  export declare function emitTraceResults(results: TraceResult[], options: EmitTraceOptions): void;
16
+ declare function trimMidPath(s: string, w: number, sep: string): string;
17
+ export declare const __testing__: {
18
+ trimMidPath: typeof trimMidPath;
19
+ };
20
+ export {};
8
21
  //# sourceMappingURL=traceEmitter.d.ts.map
@@ -26,9 +26,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.emitTraceResults = void 0;
29
+ exports.__testing__ = exports.emitTraceResults = void 0;
30
30
  const chalk_1 = __importDefault(require("chalk"));
31
- const Path = __importStar(require("path"));
31
+ const iPath = __importStar(require("path"));
32
32
  const strip_ansi_1 = __importDefault(require("strip-ansi"));
33
33
  const util_1 = require("../util/util");
34
34
  const colWidthDictionaryName = 20;
@@ -36,10 +36,14 @@ function emitTraceResults(results, options) {
36
36
  const maxWordLength = results
37
37
  .map((r) => r.foundWord || r.word)
38
38
  .reduce((a, b) => Math.max(a, (0, util_1.width)(b)), 'Word'.length);
39
+ const maxDictNameLength = results
40
+ .map((r) => r.dictName.length)
41
+ .reduce((a, b) => Math.max(a, b), colWidthDictionaryName);
39
42
  const cols = {
40
43
  word: maxWordLength,
41
- dictName: colWidthDictionaryName,
44
+ dictName: maxDictNameLength,
42
45
  terminalWidth: options.lineWidth ?? (process.stdout.columns || 120),
46
+ location: options.dictionaryPathFormat === 'hide' ? 0 : 30,
43
47
  };
44
48
  const col = new Intl.Collator();
45
49
  results.sort((a, b) => col.compare(a.dictName, b.dictName));
@@ -52,9 +56,9 @@ function emitHeader(colWidths) {
52
56
  (0, util_1.pad)('Word', colWidths.word),
53
57
  'F',
54
58
  (0, util_1.pad)('Dictionary', colWidths.dictName),
55
- (0, util_1.pad)('Dictionary Location', 30),
59
+ colWidths.location ? (0, util_1.pad)('Dictionary Location', colWidths.location) : '',
56
60
  ];
57
- console.log(chalk_1.default.underline(line.join(' ').slice(0, colWidths.terminalWidth)));
61
+ console.log(chalk_1.default.underline(line.join(' ').trim().slice(0, colWidths.terminalWidth)));
58
62
  }
59
63
  function emitTraceResult(r, colWidths, options) {
60
64
  const { word: wordColWidth, terminalWidth, dictName: widthName } = colWidths;
@@ -70,10 +74,10 @@ function emitTraceResult(r, colWidths, options) {
70
74
  const info = [w, f, n].join(' ') + ' ';
71
75
  const used = (0, util_1.width)((0, strip_ansi_1.default)(info));
72
76
  const widthSrc = terminalWidth - used;
73
- const c = errors ? chalk_1.default.red : chalk_1.default.white;
74
- const s = c(formatDictionaryLocation(r.dictSource, widthSrc, options.cwd));
77
+ const c = colorize(errors ? chalk_1.default.red : chalk_1.default.white);
78
+ const s = c(formatDictionaryLocation(r.dictSource, widthSrc, { iPath, ...options }));
75
79
  const line = info + s;
76
- console.log(line);
80
+ console.log(line.trim());
77
81
  if (errors) {
78
82
  console.error('\t' + chalk_1.default.red(errors));
79
83
  }
@@ -101,9 +105,67 @@ function calcFoundChar(r) {
101
105
  char = errors ? 'X' : char;
102
106
  return color(char);
103
107
  }
104
- function formatDictionaryLocation(dictSource, maxWidth, cwd) {
105
- const relPath = cwd ? Path.relative(cwd, dictSource) : dictSource;
108
+ function formatDictionaryLocation(dictSource, maxWidth, { cwd, dictionaryPathFormat: format, iPath, }) {
109
+ let relPath = cwd ? iPath.relative(cwd, dictSource) : dictSource;
110
+ const idxNodeModule = relPath.lastIndexOf('node_modules');
111
+ const isNodeModule = idxNodeModule >= 0;
112
+ if (format === 'hide')
113
+ return '';
114
+ if (format === 'short') {
115
+ const prefix = isNodeModule
116
+ ? '[node_modules]/'
117
+ : relPath.startsWith('..' + iPath.sep + '..')
118
+ ? '.../'
119
+ : relPath.startsWith('..' + iPath.sep)
120
+ ? '../'
121
+ : '';
122
+ return prefix + iPath.basename(dictSource);
123
+ }
124
+ if (format === 'full')
125
+ return dictSource;
126
+ relPath = isNodeModule ? relPath.slice(idxNodeModule) : relPath;
106
127
  const usePath = relPath.length < dictSource.length ? relPath : dictSource;
107
- return trimMid(usePath, maxWidth);
128
+ return trimMidPath(usePath, maxWidth, iPath.sep);
129
+ }
130
+ function colorize(fn) {
131
+ return (s) => (s ? fn(s) : '');
108
132
  }
133
+ function trimMidPath(s, w, sep) {
134
+ if (s.length <= w)
135
+ return s;
136
+ const parts = s.split(sep);
137
+ if (parts[parts.length - 1].length > w)
138
+ return trimMid(s, w);
139
+ function join(left, right) {
140
+ // if (left === right) return parts.join(sep);
141
+ return [...parts.slice(0, left), '...', ...parts.slice(right)].join(sep);
142
+ }
143
+ let left = 0, right = parts.length, last = '';
144
+ for (let i = 0; i < parts.length; ++i) {
145
+ const incLeft = i & 1 ? 1 : 0;
146
+ const incRight = incLeft ? 0 : -1;
147
+ const next = join(left + incLeft, right + incRight);
148
+ if (next.length > w)
149
+ break;
150
+ left += incLeft;
151
+ right += incRight;
152
+ last = next;
153
+ }
154
+ for (let i = left + 1; i < right; ++i) {
155
+ const next = join(i, right);
156
+ if (next.length > w)
157
+ break;
158
+ last = next;
159
+ }
160
+ for (let i = right - 1; i > left; --i) {
161
+ const next = join(left, i);
162
+ if (next.length > w)
163
+ break;
164
+ last = next;
165
+ }
166
+ return last || trimMid(s, w);
167
+ }
168
+ exports.__testing__ = {
169
+ trimMidPath,
170
+ };
109
171
  //# sourceMappingURL=traceEmitter.js.map
package/dist/lint/lint.js CHANGED
@@ -28,6 +28,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.runLint = void 0;
30
30
  const cspell_pipe_1 = require("@cspell/cspell-pipe");
31
+ const sync_1 = require("@cspell/cspell-pipe/sync");
31
32
  const cspell_types_1 = require("@cspell/cspell-types");
32
33
  const chalk_1 = __importDefault(require("chalk"));
33
34
  const cspell_gitignore_1 = require("cspell-gitignore");
@@ -41,12 +42,14 @@ const cache_1 = require("../util/cache");
41
42
  const errors_1 = require("../util/errors");
42
43
  const fileHelper_1 = require("../util/fileHelper");
43
44
  const glob_1 = require("../util/glob");
45
+ const prefetch_1 = require("../util/prefetch");
44
46
  const reporters_1 = require("../util/reporters");
45
47
  const timer_1 = require("../util/timer");
46
48
  const util = __importStar(require("../util/util"));
47
49
  // eslint-disable-next-line @typescript-eslint/no-var-requires
48
50
  const npmPackage = require('../../package.json');
49
51
  const version = npmPackage.version;
52
+ const BATCH_SIZE = 8;
50
53
  const { opFilterAsync } = cspell_pipe_1.operators;
51
54
  async function runLint(cfg) {
52
55
  let { reporter } = cfg;
@@ -60,7 +63,30 @@ async function runLint(cfg) {
60
63
  console.log(`Elapsed Time: ${elapsed.toFixed(2)}ms`);
61
64
  }
62
65
  return lintResult;
63
- async function processFile(filename, configInfo, cache) {
66
+ function prefetch(filename, configInfo, cache) {
67
+ if ((0, fileHelper_1.isBinaryFile)(filename, cfg.root))
68
+ return { filename, result: Promise.resolve({ skip: true }) };
69
+ async function fetch() {
70
+ const getElapsedTimeMs = (0, timer_1.getTimeMeasurer)();
71
+ const cachedResult = await cache.getCachedLintResults(filename);
72
+ if (cachedResult) {
73
+ reporter.debug(`Filename: ${filename}, using cache`);
74
+ const fileResult = { ...cachedResult, elapsedTimeMs: getElapsedTimeMs() };
75
+ return { fileResult };
76
+ }
77
+ const uri = (0, fileHelper_1.filenameToUri)(filename, cfg.root);
78
+ const checkResult = await cspell.shouldCheckDocument({ uri }, {}, configInfo.config);
79
+ if (!checkResult.shouldCheck)
80
+ return { skip: true };
81
+ const fileInfo = await (0, fileHelper_1.readFileInfo)(filename, undefined, true);
82
+ return { fileInfo };
83
+ }
84
+ const result = fetch();
85
+ return { filename, result };
86
+ }
87
+ async function processFile(filename, configInfo, cache, prefetch) {
88
+ if (prefetch?.fileResult)
89
+ return prefetch.fileResult;
64
90
  const getElapsedTimeMs = (0, timer_1.getTimeMeasurer)();
65
91
  const cachedResult = await cache.getCachedLintResults(filename);
66
92
  if (cachedResult) {
@@ -77,7 +103,7 @@ async function runLint(cfg) {
77
103
  configErrors: 0,
78
104
  elapsedTimeMs: 0,
79
105
  };
80
- const fileInfo = await (0, fileHelper_1.readFileInfo)(filename, undefined, true);
106
+ const fileInfo = prefetch?.fileInfo || (await (0, fileHelper_1.readFileInfo)(filename, undefined, true));
81
107
  if (fileInfo.errorCode) {
82
108
  if (fileInfo.errorCode !== 'EISDIR' && cfg.options.mustFindFiles) {
83
109
  const err = (0, errors_1.toError)(`File not found: "${filename}"`);
@@ -153,13 +179,52 @@ async function runLint(cfg) {
153
179
  numErrors: result?.issues.length || result?.errors,
154
180
  cached: result?.cached,
155
181
  });
182
+ function* prefetchFiles(files) {
183
+ const iter = (0, prefetch_1.prefetchIterable)((0, sync_1.pipe)(files, (0, sync_1.opMap)((filename) => prefetch(filename, configInfo, cache))), BATCH_SIZE);
184
+ for (const v of iter) {
185
+ yield v;
186
+ }
187
+ }
188
+ async function* prefetchFilesAsync(files) {
189
+ for await (const filename of files) {
190
+ yield prefetch(filename, configInfo, cache);
191
+ }
192
+ }
193
+ const emptyResult = {
194
+ fileInfo: { filename: '' },
195
+ issues: [],
196
+ processed: false,
197
+ errors: 0,
198
+ configErrors: 0,
199
+ elapsedTimeMs: 1,
200
+ };
201
+ async function processPrefetchFileResult(pf, index) {
202
+ const { filename, result: pFetchResult } = pf;
203
+ const getElapsedTimeMs = (0, timer_1.getTimeMeasurer)();
204
+ const fetchResult = await pFetchResult;
205
+ emitProgressBegin(filename, index, fileCount ?? index);
206
+ if (fetchResult?.skip) {
207
+ return {
208
+ filename,
209
+ fileNum: index,
210
+ result: { ...emptyResult, fileInfo: { filename }, elapsedTimeMs: getElapsedTimeMs() },
211
+ };
212
+ }
213
+ const result = await processFile(filename, configInfo, cache, fetchResult);
214
+ return { filename, fileNum: index, result };
215
+ }
156
216
  async function* loadAndProcessFiles() {
157
217
  let i = 0;
158
- for await (const filename of files) {
159
- ++i;
160
- emitProgressBegin(filename, i, fileCount ?? i);
161
- const result = await processFile(filename, configInfo, cache);
162
- yield { filename, fileNum: i, result };
218
+ if ((0, cspell_pipe_1.isAsyncIterable)(files)) {
219
+ for await (const pf of prefetchFilesAsync(files)) {
220
+ yield processPrefetchFileResult(pf, ++i);
221
+ }
222
+ }
223
+ else {
224
+ for (const pf of prefetchFiles(files)) {
225
+ await pf.result;
226
+ yield await processPrefetchFileResult(pf, ++i);
227
+ }
163
228
  }
164
229
  }
165
230
  for await (const fileP of loadAndProcessFiles()) {
@@ -293,7 +358,6 @@ async function determineGlobs(configInfo, cfg) {
293
358
  const excludeGlobs = combinedGlobs.filter((g) => g.startsWith('!')).concat(normalizedExcludes);
294
359
  const fileGlobs = includeGlobs;
295
360
  const appGlobs = { allGlobs, gitIgnore, fileGlobs, excludeGlobs, normalizedExcludes };
296
- // console.log('%o', appGlobs);
297
361
  return appGlobs;
298
362
  }
299
363
  async function determineFilesToCheck(configInfo, cfg, reporter, globInfo) {
package/dist/options.d.ts CHANGED
@@ -72,6 +72,9 @@ export interface TraceOptions extends BaseOptions {
72
72
  stdin?: boolean;
73
73
  allowCompoundWords?: boolean;
74
74
  ignoreCase?: boolean;
75
+ all?: boolean;
76
+ onlyFound?: boolean;
77
+ dictionaryPath?: 'hide' | 'long' | 'short' | 'full';
75
78
  }
76
79
  export interface SuggestionOptions extends BaseOptions {
77
80
  /**
@@ -32,6 +32,7 @@ async function calcCacheSettings(config, cacheOptions, root) {
32
32
  const useCache = cacheOptions.cache ?? cs.useCache ?? false;
33
33
  const cacheLocation = await resolveCacheLocation(path_1.default.resolve(root, cacheOptions.cacheLocation ?? cs.cacheLocation ?? exports.DEFAULT_CACHE_LOCATION));
34
34
  const cacheStrategy = cacheOptions.cacheStrategy ?? cs.cacheStrategy ?? 'metadata';
35
+ const cacheFormat = cacheOptions.cacheFormat ?? cs.cacheFormat ?? 'legacy';
35
36
  const optionals = {};
36
37
  if (cacheOptions.cacheReset) {
37
38
  optionals.reset = true;
@@ -42,7 +43,7 @@ async function calcCacheSettings(config, cacheOptions, root) {
42
43
  cacheLocation,
43
44
  cacheStrategy,
44
45
  version: cacheOptions.version,
45
- cacheFormat: cacheOptions.cacheFormat || 'legacy',
46
+ cacheFormat,
46
47
  };
47
48
  }
48
49
  exports.calcCacheSettings = calcCacheSettings;
@@ -1,5 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import type { CSpellUserSettings, Document, Issue } from 'cspell-lib';
3
+ import { URI } from 'vscode-uri';
3
4
  import type { GlobOptions } from './glob';
4
5
  export interface ConfigInfo {
5
6
  source: string;
@@ -27,7 +28,10 @@ export interface FileResult {
27
28
  cached?: boolean;
28
29
  }
29
30
  export declare function fileInfoToDocument(fileInfo: FileInfo, languageId: string | undefined, locale: string | undefined): Document;
30
- interface ReadFileInfoResult extends FileInfo {
31
+ export declare function filenameToUrlString(filename: string, cwd?: string): string;
32
+ export declare function filenameToUri(filename: string, cwd?: string): URI;
33
+ export declare function isBinaryFile(filename: string, cwd?: string): boolean;
34
+ export interface ReadFileInfoResult extends FileInfo {
31
35
  text: string;
32
36
  }
33
37
  export declare function resolveFilename(filename: string, cwd?: string): string;
@@ -56,5 +60,4 @@ export declare function readFileListFile(listFile: string): Promise<string[]>;
56
60
  export declare function isFile(filename: string): Promise<boolean>;
57
61
  export declare function isDir(filename: string): Promise<boolean>;
58
62
  export declare function isNotDir(filename: string): Promise<boolean>;
59
- export {};
60
63
  //# sourceMappingURL=fileHelper.d.ts.map
@@ -26,18 +26,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.isNotDir = exports.isDir = exports.isFile = exports.readFileListFile = exports.readFileListFiles = exports.calcFinalConfigInfo = exports.findFiles = exports.readFile = exports.readFileInfo = exports.resolveFilename = exports.fileInfoToDocument = exports.readConfig = void 0;
29
+ exports.isNotDir = exports.isDir = exports.isFile = exports.readFileListFile = exports.readFileListFiles = exports.calcFinalConfigInfo = exports.findFiles = exports.readFile = exports.readFileInfo = exports.resolveFilename = exports.isBinaryFile = exports.filenameToUri = exports.filenameToUrlString = exports.fileInfoToDocument = exports.readConfig = void 0;
30
+ const cspell_io_1 = require("cspell-io");
30
31
  const cspell = __importStar(require("cspell-lib"));
31
32
  const cspell_lib_1 = require("cspell-lib");
32
33
  const fs_1 = require("fs");
33
34
  const get_stdin_1 = __importDefault(require("get-stdin"));
34
35
  const path = __importStar(require("path"));
35
36
  const url_1 = require("url");
37
+ const vscode_uri_1 = require("vscode-uri");
36
38
  const async_1 = require("./async");
37
39
  const constants_1 = require("./constants");
38
40
  const errors_1 = require("./errors");
39
41
  const glob_1 = require("./glob");
40
42
  const stdin_1 = require("./stdin");
43
+ const doesMatchUrl = /^(file|stdin|https?):\/\//;
41
44
  async function readConfig(configFile, root) {
42
45
  if (configFile) {
43
46
  const config = (await cspell.loadConfig(configFile)) || {};
@@ -51,17 +54,42 @@ function fileInfoToDocument(fileInfo, languageId, locale) {
51
54
  const { filename, text } = fileInfo;
52
55
  languageId = languageId || undefined;
53
56
  locale = locale || undefined;
54
- if (filename === constants_1.STDIN || filename.startsWith(constants_1.STDINProtocol)) {
57
+ const uri = filenameToUrlString(filename);
58
+ if (uri.startsWith(constants_1.STDINProtocol)) {
55
59
  return {
56
- uri: filename === constants_1.STDIN ? 'stdin:///' : filename,
60
+ uri,
57
61
  text,
58
62
  languageId,
59
63
  locale,
60
64
  };
61
65
  }
62
- return (0, cspell_lib_1.fileToDocument)(filename, text, languageId, locale);
66
+ return (0, cspell_lib_1.fileToDocument)(uri, text, languageId, locale);
63
67
  }
64
68
  exports.fileInfoToDocument = fileInfoToDocument;
69
+ function filenameToUrlString(filename, cwd = '.') {
70
+ if (filename === constants_1.STDIN)
71
+ return 'stdin:///';
72
+ if (filename.startsWith(constants_1.STDINProtocol)) {
73
+ const filePath = filename.slice(constants_1.STDINProtocol.length);
74
+ const fullPath = path.resolve(cwd, filePath);
75
+ return (0, url_1.pathToFileURL)(fullPath).toString();
76
+ }
77
+ if (doesMatchUrl.test(filename))
78
+ return filename;
79
+ return (0, url_1.pathToFileURL)(path.resolve(cwd, filename)).toString();
80
+ }
81
+ exports.filenameToUrlString = filenameToUrlString;
82
+ function filenameToUri(filename, cwd) {
83
+ return vscode_uri_1.URI.parse(filenameToUrlString(filename, cwd));
84
+ }
85
+ exports.filenameToUri = filenameToUri;
86
+ function isBinaryFile(filename, cwd) {
87
+ const uri = filenameToUri(filename, cwd);
88
+ if (uri.scheme.startsWith('stdin'))
89
+ return false;
90
+ return (0, cspell_lib_1.isBinaryFile)(uri);
91
+ }
92
+ exports.isBinaryFile = isBinaryFile;
65
93
  function resolveFilename(filename, cwd) {
66
94
  cwd = cwd || process.cwd();
67
95
  if (filename === constants_1.STDIN)
@@ -77,7 +105,7 @@ function resolveFilename(filename, cwd) {
77
105
  exports.resolveFilename = resolveFilename;
78
106
  function readFileInfo(filename, encoding = constants_1.UTF8, handleNotFound = false) {
79
107
  filename = resolveFilename(filename);
80
- const pText = filename.startsWith(constants_1.STDINProtocol) ? (0, get_stdin_1.default)() : fs_1.promises.readFile(filename, encoding);
108
+ const pText = filename.startsWith(constants_1.STDINProtocol) ? (0, get_stdin_1.default)() : (0, cspell_io_1.readFile)(filename, encoding);
81
109
  return pText.then((text) => ({ text, filename }), (e) => {
82
110
  const error = (0, errors_1.toError)(e);
83
111
  return handleNotFound && error.code === 'EISDIR'
@@ -0,0 +1,2 @@
1
+ export declare function prefetchIterable<T>(iterable: Iterable<T>, size: number): Iterable<T>;
2
+ //# sourceMappingURL=prefetch.d.ts.map
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.prefetchIterable = void 0;
7
+ const assert_1 = __importDefault(require("assert"));
8
+ function* prefetchIterable(iterable, size) {
9
+ (0, assert_1.default)(size >= 0);
10
+ const iter = iterable[Symbol.iterator]();
11
+ const buffer = [];
12
+ for (let next = iter.next(); !next.done; next = iter.next()) {
13
+ buffer.push(next.value);
14
+ if (buffer.length >= size - 1) {
15
+ const value = buffer[0];
16
+ buffer.shift();
17
+ yield value;
18
+ }
19
+ }
20
+ yield* buffer;
21
+ }
22
+ exports.prefetchIterable = prefetchIterable;
23
+ //# sourceMappingURL=prefetch.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cspell",
3
- "version": "6.26.2",
3
+ "version": "6.27.0",
4
4
  "description": "A Spelling Checker for Code!",
5
5
  "funding": "https://github.com/streetsidesoftware/cspell?sponsor=1",
6
6
  "main": "dist/index.js",
@@ -76,13 +76,14 @@
76
76
  },
77
77
  "homepage": "https://streetsidesoftware.github.io/cspell/",
78
78
  "dependencies": {
79
- "@cspell/cspell-pipe": "6.26.2",
80
- "@cspell/dynamic-import": "6.26.2",
79
+ "@cspell/cspell-pipe": "6.27.0",
80
+ "@cspell/dynamic-import": "6.27.0",
81
81
  "chalk": "^4.1.2",
82
82
  "commander": "^10.0.0",
83
- "cspell-gitignore": "6.26.2",
84
- "cspell-glob": "6.26.2",
85
- "cspell-lib": "6.26.2",
83
+ "cspell-gitignore": "6.27.0",
84
+ "cspell-glob": "6.27.0",
85
+ "cspell-io": "6.27.0",
86
+ "cspell-lib": "6.27.0",
86
87
  "fast-glob": "^3.2.12",
87
88
  "fast-json-stable-stringify": "^2.1.0",
88
89
  "file-entry-cache": "^6.0.1",
@@ -96,18 +97,18 @@
96
97
  "node": ">=14"
97
98
  },
98
99
  "devDependencies": {
99
- "@cspell/cspell-json-reporter": "6.26.2",
100
- "@cspell/cspell-types": "6.26.2",
100
+ "@cspell/cspell-json-reporter": "6.27.0",
101
+ "@cspell/cspell-types": "6.27.0",
101
102
  "@types/file-entry-cache": "^5.0.2",
102
- "@types/glob": "^8.0.1",
103
+ "@types/glob": "^8.1.0",
103
104
  "@types/imurmurhash": "^0.1.1",
104
105
  "@types/micromatch": "^4.0.2",
105
106
  "@types/semver": "^7.3.13",
106
107
  "micromatch": "^4.0.5",
107
- "minimatch": "^6.2.0",
108
- "rollup": "^3.15.0",
108
+ "minimatch": "^7.1.3",
109
+ "rollup": "^3.17.3",
109
110
  "rollup-plugin-dts": "^5.2.0",
110
111
  "vitest": "^0.28.5"
111
112
  },
112
- "gitHead": "9c983b5f96c3d7b089e49178ab0b437b5eada256"
113
+ "gitHead": "b0e31c7ba91ba467d5fd9c66f238bb5d899f4833"
113
114
  }