cspell-lib 8.2.0 → 8.2.3

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.
@@ -1,6 +1,6 @@
1
1
  import assert from 'assert';
2
- import { promises as fs } from 'fs';
3
2
  import { TextDocument as VsTextDocument } from 'vscode-languageserver-textdocument';
3
+ import { getFileSystem } from '../fileSystem.js';
4
4
  import { getLanguagesForBasename } from '../LanguageIds.js';
5
5
  import * as Uri from '../util/Uri.js';
6
6
  class TextDocumentImpl {
@@ -103,8 +103,9 @@ function isTextDocumentImpl(doc) {
103
103
  }
104
104
  export async function loadTextDocument(filename, languageId) {
105
105
  const uri = Uri.toUri(filename);
106
- const content = await fs.readFile(Uri.uriToFilePath(uri), 'utf8');
107
- return createTextDocument({ uri, languageId, content });
106
+ const url = new URL(uri.toString());
107
+ const file = await getFileSystem().readFile(url);
108
+ return createTextDocument({ uri, languageId, content: file.getText() });
108
109
  }
109
110
  export const isTextDocument = isTextDocumentImpl;
110
111
  //# sourceMappingURL=TextDocument.js.map
@@ -5,7 +5,7 @@ import path from 'path';
5
5
  import { fileURLToPath, pathToFileURL } from 'url';
6
6
  import { URI, Utils as UriUtils } from 'vscode-uri';
7
7
  import { onClearCache } from '../../../events/index.js';
8
- import { createTextFileResource, getVirtualFS } from '../../../fileSystem.js';
8
+ import { getVirtualFS } from '../../../fileSystem.js';
9
9
  import { createCSpellSettingsInternal as csi } from '../../../Models/CSpellSettingsInternalDef.js';
10
10
  import { AutoResolveCache } from '../../../util/AutoResolve.js';
11
11
  import { logError, logWarning } from '../../../util/logger.js';
@@ -321,6 +321,8 @@ export class ConfigLoader {
321
321
  async resolveFilename(filename, relativeTo) {
322
322
  if (filename instanceof URL)
323
323
  return { filename: toFilePathOrHref(filename) };
324
+ if (isUrlLike(filename))
325
+ return { filename: toFilePathOrHref(filename) };
324
326
  const r = await this.fileResolver.resolveFile(filename, relativeTo);
325
327
  if (r.warning) {
326
328
  logWarning(r.warning);
@@ -406,7 +408,7 @@ export function getDefaultConfigLoaderInternal() {
406
408
  return (defaultConfigLoader = createConfigLoaderInternal());
407
409
  }
408
410
  function createIO(fs) {
409
- const readFile = (url) => fs.readFile(url).then((file) => ({ url: file.url, content: createTextFileResource(file).getText() }));
411
+ const readFile = (url) => fs.readFile(url).then((file) => ({ url: file.url, content: file.getText() }));
410
412
  const writeFile = (file) => fs.writeFile(file);
411
413
  return {
412
414
  readFile,
@@ -1,4 +1,4 @@
1
- import { type VFileSystem } from '../../../fileSystem.js';
1
+ import type { VFileSystem } from '../../../fileSystem.js';
2
2
  export declare class ConfigSearch {
3
3
  readonly searchPlaces: readonly string[];
4
4
  private fs;
@@ -1,5 +1,4 @@
1
1
  import { urlBasename } from 'cspell-io';
2
- import { createTextFileResource } from '../../../fileSystem.js';
3
2
  import { createAutoResolveCache } from '../../../util/AutoResolve.js';
4
3
  import { findUpFromUrl } from '../../../util/findUpFromUrl.js';
5
4
  export class ConfigSearch {
@@ -68,6 +67,16 @@ export class ConfigSearch {
68
67
  const dirInfoCache = createAutoResolveCache();
69
68
  const hasFile = async (filename) => {
70
69
  const dir = new URL('.', filename);
70
+ const parent = new URL('..', dir);
71
+ const parentHref = parent.href;
72
+ const parentInfoP = dirInfoCache.get(parentHref);
73
+ if (parentInfoP) {
74
+ const parentInfo = await parentInfoP;
75
+ const name = urlBasename(dir).slice(0, -1);
76
+ const found = parentInfo.get(name);
77
+ if (!found?.isDirectory())
78
+ return false;
79
+ }
71
80
  const dirUrlHref = dir.href;
72
81
  const dirInfo = await dirInfoCache.get(dirUrlHref, async () => new Map((await this.fs.readDirectory(dir).catch(() => [])).map((ent) => [ent.name, ent])));
73
82
  const name = urlBasename(filename);
@@ -102,7 +111,7 @@ export class ConfigSearch {
102
111
  }
103
112
  async function checkPackageJson(fs, filename) {
104
113
  try {
105
- const file = createTextFileResource(await fs.readFile(filename));
114
+ const file = await fs.readFile(filename);
106
115
  const pkg = JSON.parse(file.getText());
107
116
  return typeof pkg.cspell === 'object';
108
117
  }
@@ -110,11 +119,4 @@ async function checkPackageJson(fs, filename) {
110
119
  return false;
111
120
  }
112
121
  }
113
- // async function isDirectory(virtualFs: VirtualFS, path: URL): Promise<boolean> {
114
- // try {
115
- // return (await virtualFs.fs.stat(path)).isDirectory();
116
- // } catch (e) {
117
- // return false;
118
- // }
119
- // }
120
122
  //# sourceMappingURL=configSearch.js.map
@@ -1,2 +1,2 @@
1
- export { SettingsController } from './SettingsController.js';
1
+ export { defaultConfigFilenames } from './configLoader/index.js';
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1,2 +1,2 @@
1
- export { SettingsController } from './SettingsController.js';
1
+ export { defaultConfigFilenames } from './configLoader/index.js';
2
2
  //# sourceMappingURL=index.js.map
@@ -1,8 +1,6 @@
1
1
  import type { SpellingDictionary, SpellingDictionaryCollection } from 'cspell-dictionary';
2
2
  import type { CSpellSettingsInternal, DictionaryDefinitionInternal } from '../Models/CSpellSettingsInternalDef.js';
3
3
  export declare function loadDictionaryDefs(defsToLoad: DictionaryDefinitionInternal[]): Promise<SpellingDictionary>[];
4
- export declare function loadDictionaryDefsSync(defsToLoad: DictionaryDefinitionInternal[]): SpellingDictionary[];
5
4
  export declare function refreshDictionaryCache(maxAge?: number): Promise<void>;
6
5
  export declare function getDictionaryInternal(settings: CSpellSettingsInternal): Promise<SpellingDictionaryCollection>;
7
- export declare function getDictionaryInternalSync(settings: CSpellSettingsInternal): SpellingDictionaryCollection;
8
6
  //# sourceMappingURL=Dictionaries.d.ts.map
@@ -1,13 +1,10 @@
1
1
  import { createCollection, createForbiddenWordsDictionary, createIgnoreWordsDictionary, createSpellingDictionary, createSuggestDictionary, } from 'cspell-dictionary';
2
2
  import { calcDictionaryDefsToLoad } from '../Settings/DictionarySettings.js';
3
3
  import { isDefined } from '../util/util.js';
4
- import { loadDictionary, loadDictionarySync, refreshCacheEntries } from './DictionaryLoader.js';
4
+ import { loadDictionary, refreshCacheEntries } from './DictionaryLoader.js';
5
5
  export function loadDictionaryDefs(defsToLoad) {
6
6
  return defsToLoad.map(loadDictionary);
7
7
  }
8
- export function loadDictionaryDefsSync(defsToLoad) {
9
- return defsToLoad.map(loadDictionarySync);
10
- }
11
8
  export function refreshDictionaryCache(maxAge) {
12
9
  return refreshCacheEntries(maxAge);
13
10
  }
@@ -16,10 +13,6 @@ export async function getDictionaryInternal(settings) {
16
13
  const spellDictionaries = await Promise.all(loadDictionaryDefs(calcDictionaryDefsToLoad(settings)));
17
14
  return _getDictionaryInternal(settings, spellDictionaries);
18
15
  }
19
- export function getDictionaryInternalSync(settings) {
20
- const spellDictionaries = loadDictionaryDefsSync(calcDictionaryDefsToLoad(settings));
21
- return _getDictionaryInternal(settings, spellDictionaries);
22
- }
23
16
  function _getDictionaryInternal(settings, spellDictionaries) {
24
17
  const { words = emptyWords, userWords = emptyWords, flagWords = emptyWords, ignoreWords = emptyWords, suggestWords = emptyWords, } = settings;
25
18
  const settingsWordsDictionary = createSpellingDictionary(words, '[words]', 'From Settings `words`', {
@@ -1,16 +1,15 @@
1
1
  import type { SpellingDictionary } from 'cspell-dictionary';
2
- import type { CSpellIO } from 'cspell-io';
2
+ import type { VFileSystem } from 'cspell-io';
3
3
  import type { DictionaryDefinitionInternal } from '../../Models/CSpellSettingsInternalDef.js';
4
4
  export type LoadOptions = DictionaryDefinitionInternal;
5
5
  export declare class DictionaryLoader {
6
- private cspellIO;
6
+ private fs;
7
7
  private dictionaryCache;
8
8
  private inlineDictionaryCache;
9
9
  private dictionaryCacheByDef;
10
10
  private reader;
11
- constructor(cspellIO: CSpellIO);
11
+ constructor(fs: VFileSystem);
12
12
  loadDictionary(def: DictionaryDefinitionInternal): Promise<SpellingDictionary>;
13
- loadDictionarySync(def: DictionaryDefinitionInternal): SpellingDictionary;
14
13
  /**
15
14
  * Check to see if any of the cached dictionaries have changed. If one has changed, reload it.
16
15
  * @param maxAge - Only check the dictionary if it has been at least `maxAge` ms since the last check.
@@ -21,9 +20,7 @@ export declare class DictionaryLoader {
21
20
  private setCacheEntry;
22
21
  private refreshEntry;
23
22
  private loadEntry;
24
- private loadEntrySync;
25
23
  private getStat;
26
- private getStatSync;
27
24
  private isEqual;
28
25
  private normalizeOptions;
29
26
  private loadInlineDict;
@@ -1,6 +1,7 @@
1
1
  import { opConcatMap, opFilter, opMap, pipe } from '@cspell/cspell-pipe/sync';
2
2
  import { StrongWeakMap } from '@cspell/strong-weak-map';
3
3
  import { createFailedToLoadDictionary, createInlineSpellingDictionary, createSpellingDictionary, createSpellingDictionaryFromTrieFile, } from 'cspell-dictionary';
4
+ import { compareStats, toFileURL, urlBasename } from 'cspell-io';
4
5
  import { isDictionaryDefinitionInlineInternal } from '../../Models/CSpellSettingsInternalDef.js';
5
6
  import { AutoResolveWeakCache } from '../../util/AutoResolve.js';
6
7
  import { toError } from '../../util/errors.js';
@@ -13,27 +14,20 @@ const loaders = {
13
14
  T: loadTrie,
14
15
  default: loadSimpleWordList,
15
16
  };
16
- const loadersSync = {
17
- S: loadSimpleWordListSync,
18
- C: legacyWordListSync,
19
- W: wordsPerLineWordListSync,
20
- T: loadTrieSync,
21
- default: loadSimpleWordListSync,
22
- };
23
17
  var LoadingState;
24
18
  (function (LoadingState) {
25
19
  LoadingState[LoadingState["Loaded"] = 0] = "Loaded";
26
20
  LoadingState[LoadingState["Loading"] = 1] = "Loading";
27
21
  })(LoadingState || (LoadingState = {}));
28
22
  export class DictionaryLoader {
29
- cspellIO;
23
+ fs;
30
24
  dictionaryCache = new StrongWeakMap();
31
25
  inlineDictionaryCache = new AutoResolveWeakCache();
32
26
  dictionaryCacheByDef = new StrongWeakMap();
33
27
  reader;
34
- constructor(cspellIO) {
35
- this.cspellIO = cspellIO;
36
- this.reader = toReader(cspellIO);
28
+ constructor(fs) {
29
+ this.fs = fs;
30
+ this.reader = toReader(fs);
37
31
  }
38
32
  loadDictionary(def) {
39
33
  if (isDictionaryDefinitionInlineInternal(def)) {
@@ -47,18 +41,6 @@ export class DictionaryLoader {
47
41
  this.setCacheEntry(key, loadedEntry, def);
48
42
  return loadedEntry.pending.then(([dictionary]) => dictionary);
49
43
  }
50
- loadDictionarySync(def) {
51
- if (isDictionaryDefinitionInlineInternal(def)) {
52
- return this.loadInlineDict(def);
53
- }
54
- const { key, entry } = this.getCacheEntry(def);
55
- if (entry?.dictionary && entry.loadingState === LoadingState.Loaded) {
56
- return entry.dictionary;
57
- }
58
- const loadedEntry = this.loadEntrySync(this.cspellIO.toFileURL(def.path), def);
59
- this.setCacheEntry(key, loadedEntry, def);
60
- return loadedEntry.dictionary;
61
- }
62
44
  /**
63
45
  * Check to see if any of the cached dictionaries have changed. If one has changed, reload it.
64
46
  * @param maxAge - Only check the dictionary if it has been at least `maxAge` ms since the last check.
@@ -104,9 +86,9 @@ export class DictionaryLoader {
104
86
  }
105
87
  }
106
88
  loadEntry(fileOrUri, options, now = Date.now()) {
107
- const url = this.cspellIO.toFileURL(fileOrUri);
89
+ const url = toFileURL(fileOrUri);
108
90
  options = this.normalizeOptions(url, options);
109
- const pDictionary = load(this.reader, this.cspellIO.toFileURL(fileOrUri), options).catch((e) => createFailedToLoadDictionary(options.name, fileOrUri, new SpellingDictionaryLoadError(url.href, options, e, 'failed to load'), options));
91
+ const pDictionary = load(this.reader, toFileURL(fileOrUri), options).catch((e) => createFailedToLoadDictionary(options.name, fileOrUri, new SpellingDictionaryLoadError(url.href, options, e, 'failed to load'), options));
110
92
  const pStat = this.getStat(fileOrUri);
111
93
  const pending = Promise.all([pDictionary, pStat]);
112
94
  const sig = now + Math.random();
@@ -129,51 +111,8 @@ export class DictionaryLoader {
129
111
  });
130
112
  return entry;
131
113
  }
132
- loadEntrySync(fileOrUri, options, now = Date.now()) {
133
- const url = this.cspellIO.toFileURL(fileOrUri);
134
- options = this.normalizeOptions(url, options);
135
- const stat = this.getStatSync(url);
136
- const sig = now + Math.random();
137
- try {
138
- const dictionary = loadSync(this.reader, url, options);
139
- const pending = Promise.resolve([dictionary, stat]);
140
- return {
141
- uri: url.href,
142
- options,
143
- ts: now,
144
- stat,
145
- dictionary,
146
- pending,
147
- loadingState: LoadingState.Loaded,
148
- sig,
149
- };
150
- }
151
- catch (e) {
152
- const error = toError(e);
153
- const dictionary = createFailedToLoadDictionary(options.name, fileOrUri, new SpellingDictionaryLoadError(url.href, options, error, 'failed to load'), options);
154
- const pending = Promise.resolve([dictionary, stat]);
155
- return {
156
- uri: url.href,
157
- options,
158
- ts: now,
159
- stat,
160
- dictionary,
161
- pending,
162
- loadingState: LoadingState.Loaded,
163
- sig,
164
- };
165
- }
166
- }
167
114
  getStat(uri) {
168
- return this.cspellIO.getStat(this.cspellIO.toFileURL(uri)).catch(toError);
169
- }
170
- getStatSync(uri) {
171
- try {
172
- return this.cspellIO.getStatSync(this.cspellIO.toFileURL(uri));
173
- }
174
- catch (e) {
175
- return toError(e);
176
- }
115
+ return this.fs.stat(toFileURL(uri)).catch(toError);
177
116
  }
178
117
  isEqual(a, b) {
179
118
  if (!b)
@@ -181,30 +120,31 @@ export class DictionaryLoader {
181
120
  if (isError(a)) {
182
121
  return isError(b) && a.message === b.message && a.name === b.name;
183
122
  }
184
- return !isError(b) && !this.cspellIO.compareStats(a, b);
123
+ return !isError(b) && !compareStats(a, b);
185
124
  }
186
125
  normalizeOptions(uri, options) {
187
126
  if (options.name)
188
127
  return options;
189
- return { ...options, name: this.cspellIO.urlBasename(uri) };
128
+ return { ...options, name: urlBasename(uri) };
190
129
  }
191
130
  loadInlineDict(def) {
192
131
  return this.inlineDictionaryCache.get(def, (def) => createInlineSpellingDictionary(def, def.__source || 'memory'));
193
132
  }
194
133
  calcKey(def) {
195
134
  const path = def.path;
196
- const loaderType = determineType(this.cspellIO.toFileURL(path), def);
135
+ const loaderType = determineType(toFileURL(path), def);
197
136
  const optValues = importantOptionKeys.map((k) => def[k]?.toString() || '');
198
137
  const parts = [path, loaderType].concat(optValues);
199
138
  return parts.join('|');
200
139
  }
201
140
  }
202
- function toReader(cspellIO) {
141
+ function toReader(fs) {
142
+ async function readFile(url) {
143
+ return (await fs.readFile(url)).getText();
144
+ }
203
145
  return {
204
- read: async (filename) => (await cspellIO.readFile(filename)).getText(),
205
- readLines: async (filename) => toLines((await cspellIO.readFile(filename)).getText()),
206
- readSync: (filename) => cspellIO.readFileSync(filename).getText(),
207
- readLinesSync: (filename) => toLines(cspellIO.readFileSync(filename).getText()),
146
+ read: readFile,
147
+ readLines: async (filename) => toLines(await readFile(filename)),
208
148
  };
209
149
  }
210
150
  const importantOptionKeys = ['name', 'noSuggest', 'useCompounds', 'type'];
@@ -224,19 +164,10 @@ function load(reader, uri, options) {
224
164
  const loader = loaders[type] || loaders.default;
225
165
  return loader(reader, uri, options);
226
166
  }
227
- function loadSync(reader, uri, options) {
228
- const type = determineType(uri, options);
229
- const loader = loadersSync[type] || loaders.default;
230
- return loader(reader, uri, options);
231
- }
232
167
  async function legacyWordList(reader, filename, options) {
233
168
  const lines = await reader.readLines(filename);
234
169
  return _legacyWordListSync(lines, filename, options);
235
170
  }
236
- function legacyWordListSync(reader, filename, options) {
237
- const lines = reader.readLinesSync(filename);
238
- return _legacyWordListSync(lines, filename, options);
239
- }
240
171
  function _legacyWordListSync(lines, filename, options) {
241
172
  const words = pipe(lines,
242
173
  // Remove comments
@@ -249,10 +180,6 @@ async function wordsPerLineWordList(reader, filename, options) {
249
180
  const lines = await reader.readLines(filename);
250
181
  return _wordsPerLineWordList(lines, filename.toString(), options);
251
182
  }
252
- function wordsPerLineWordListSync(reader, filename, options) {
253
- const lines = reader.readLinesSync(filename);
254
- return _wordsPerLineWordList(lines, filename.toString(), options);
255
- }
256
183
  function _wordsPerLineWordList(lines, filename, options) {
257
184
  const words = pipe(lines,
258
185
  // Remove comments
@@ -265,18 +192,10 @@ async function loadSimpleWordList(reader, filename, options) {
265
192
  const lines = await reader.readLines(filename);
266
193
  return createSpellingDictionary(lines, options.name, filename.href, options);
267
194
  }
268
- function loadSimpleWordListSync(reader, filename, options) {
269
- const lines = reader.readLinesSync(filename);
270
- return createSpellingDictionary(lines, options.name, filename.href, options);
271
- }
272
195
  async function loadTrie(reader, filename, options) {
273
196
  const content = await reader.read(filename);
274
197
  return createSpellingDictionaryFromTrieFile(content, options.name, filename.href, options);
275
198
  }
276
- function loadTrieSync(reader, filename, options) {
277
- const content = reader.readSync(filename);
278
- return createSpellingDictionaryFromTrieFile(content, options.name, filename.href, options);
279
- }
280
199
  function toLines(content) {
281
200
  return content.split(/\n|\r\n|\r/);
282
201
  }
@@ -1,11 +1,10 @@
1
1
  import type { SpellingDictionary } from 'cspell-dictionary';
2
- import type { CSpellIO } from 'cspell-io';
2
+ import type { VFileSystem } from '../fileSystem.js';
3
3
  import type { DictionaryDefinitionInternal } from '../Models/CSpellSettingsInternalDef.js';
4
4
  import { DictionaryLoader } from './DictionaryController/index.js';
5
5
  export type { LoadOptions } from './DictionaryController/index.js';
6
- export declare function getDictionaryLoader(cspellIO?: CSpellIO): DictionaryLoader;
6
+ export declare function getDictionaryLoader(vfs?: VFileSystem): DictionaryLoader;
7
7
  export declare function loadDictionary(def: DictionaryDefinitionInternal): Promise<SpellingDictionary>;
8
- export declare function loadDictionarySync(def: DictionaryDefinitionInternal): SpellingDictionary;
9
8
  /**
10
9
  * Check to see if any of the cached dictionaries have changed. If one has changed, reload it.
11
10
  * @param maxAge - Only check the dictionary if it has been at least `maxAge` ms since the last check.
@@ -1,17 +1,14 @@
1
- import { getCSpellIO } from '../fileSystem.js';
1
+ import { getFileSystem } from '../fileSystem.js';
2
2
  import { DictionaryLoader } from './DictionaryController/index.js';
3
3
  let loader;
4
- export function getDictionaryLoader(cspellIO) {
4
+ export function getDictionaryLoader(vfs) {
5
5
  if (loader)
6
6
  return loader;
7
- return (loader = new DictionaryLoader(cspellIO || getCSpellIO()));
7
+ return (loader = new DictionaryLoader(vfs || getFileSystem()));
8
8
  }
9
9
  export function loadDictionary(def) {
10
10
  return getDictionaryLoader().loadDictionary(def);
11
11
  }
12
- export function loadDictionarySync(def) {
13
- return getDictionaryLoader().loadDictionarySync(def);
14
- }
15
12
  /**
16
13
  * Check to see if any of the cached dictionaries have changed. If one has changed, reload it.
17
14
  * @param maxAge - Only check the dictionary if it has been at least `maxAge` ms since the last check.
@@ -1,8 +1,8 @@
1
- import type { CSpellIO, VFileSystemProvider } from 'cspell-io';
1
+ import type { TextEncoding, VFileSystemProvider } from 'cspell-io';
2
2
  export type { VFileSystemProvider, VfsDirEntry, VirtualFS } from 'cspell-io';
3
- export { createTextFileResource, FSCapabilityFlags, VFileSystem } from 'cspell-io';
4
- export declare function getCSpellIO(): CSpellIO;
3
+ export { FSCapabilityFlags, VFileSystem } from 'cspell-io';
5
4
  export declare function getVirtualFS(): import("cspell-io").VirtualFS;
6
5
  export declare function getFileSystem(): Required<import("cspell-io").VFileSystem>;
7
6
  export declare function registerCSpell(fsp: VFileSystemProvider): void;
7
+ export declare function readTextFile(url: URL, encoding?: TextEncoding): Promise<string>;
8
8
  //# sourceMappingURL=fileSystem.d.ts.map
@@ -1,8 +1,5 @@
1
- import { getDefaultCSpellIO, getDefaultVirtualFs } from 'cspell-io';
2
- export { createTextFileResource, FSCapabilityFlags } from 'cspell-io';
3
- export function getCSpellIO() {
4
- return getDefaultCSpellIO();
5
- }
1
+ import { getDefaultVirtualFs } from 'cspell-io';
2
+ export { FSCapabilityFlags } from 'cspell-io';
6
3
  export function getVirtualFS() {
7
4
  return getDefaultVirtualFs();
8
5
  }
@@ -13,4 +10,8 @@ export function registerCSpell(fsp) {
13
10
  const vfs = getVirtualFS();
14
11
  vfs.registerFileSystemProvider(fsp);
15
12
  }
13
+ export async function readTextFile(url, encoding = 'utf8') {
14
+ const file = await getFileSystem().readFile(url, encoding);
15
+ return file.getText();
16
+ }
16
17
  //# sourceMappingURL=fileSystem.js.map
@@ -6,7 +6,7 @@ import { updateTextDocument } from '../Models/TextDocument.js';
6
6
  import { createPerfTimer } from '../perf/index.js';
7
7
  import { finalizeSettings, loadConfig, mergeSettings, searchForConfig } from '../Settings/index.js';
8
8
  import { validateInDocumentSettings } from '../Settings/InDocSettings.js';
9
- import { getDictionaryInternal, getDictionaryInternalSync } from '../SpellingDictionary/index.js';
9
+ import { getDictionaryInternal } from '../SpellingDictionary/index.js';
10
10
  import { calcSuggestionAdjustedToToMatchCase } from '../suggestions.js';
11
11
  import { catchPromiseError, toError } from '../util/errors.js';
12
12
  import { AutoCache } from '../util/simpleCache.js';
@@ -108,7 +108,7 @@ export class DocumentValidator {
108
108
  const timer = createPerfTimer('_updatePrep');
109
109
  const prep = this._preparations;
110
110
  const docSettings = await determineTextDocumentSettings(this._document, prep.config);
111
- const dict = getDictionaryInternalSync(docSettings);
111
+ const dict = await getDictionaryInternal(docSettings);
112
112
  const shouldCheck = docSettings.enabled ?? true;
113
113
  const finalSettings = finalizeSettings(docSettings);
114
114
  const validateOptions = settingsToValidateOptions(finalSettings);
@@ -77,7 +77,7 @@ class UriImpl extends URI {
77
77
  }
78
78
  toString() {
79
79
  // if (this.scheme !== 'stdin') return super.toString(true);
80
- const path = (this.path || '').split('/').map(encodeURIComponent).join('/').replace(/%3A/g, ':');
80
+ const path = encodeURI(this.path || '').replace(/[#?]/g, (c) => `%${c.charCodeAt(0).toString(16)}`);
81
81
  const base = `${this.scheme}://${this.authority || ''}${path}`;
82
82
  const query = (this.query && `?${this.query}`) || '';
83
83
  const fragment = (this.fragment && `#${this.fragment}`) || '';
@@ -1,4 +1,3 @@
1
- import type { TextEncoding } from 'cspell-io';
2
- export declare function readLines(filename: string, encoding?: TextEncoding): Promise<IterableIterator<string>>;
3
- export declare function readLinesSync(filename: string, encoding?: TextEncoding): string[];
1
+ import { type TextEncoding } from 'cspell-io';
2
+ export declare function readLines(url: URL | string, encoding?: TextEncoding): Promise<IterableIterator<string>>;
4
3
  //# sourceMappingURL=fileReader.d.ts.map
@@ -1,16 +1,14 @@
1
- import { readFileText, readFileTextSync } from 'cspell-io';
1
+ import { toFileURL } from 'cspell-io';
2
+ import { readTextFile } from '../fileSystem.js';
2
3
  import { toIterableIterator } from './iterableIteratorLib.js';
3
- export async function readLines(filename, encoding = 'utf8') {
4
+ export async function readLines(url, encoding = 'utf8') {
4
5
  try {
5
- const content = await readFileText(filename, encoding);
6
+ url = toFileURL(url);
7
+ const content = await readTextFile(url, encoding);
6
8
  return toIterableIterator(content.split(/\r?\n/g));
7
9
  }
8
10
  catch (e) {
9
11
  return Promise.reject(e);
10
12
  }
11
13
  }
12
- export function readLinesSync(filename, encoding = 'utf8') {
13
- const content = readFileTextSync(filename, encoding);
14
- return content.split(/\r?\n/g);
15
- }
16
14
  //# sourceMappingURL=fileReader.js.map
@@ -30,6 +30,14 @@ export declare class FileResolver {
30
30
  resolveFile(filename: string | URL, relativeTo: string | URL): Promise<ResolveFileResult>;
31
31
  _resolveFile(filename: string, relativeTo: string | URL): Promise<ResolveFileResult>;
32
32
  private doesExist;
33
+ /**
34
+ * Check to see if it is a URL.
35
+ * Note: URLs are absolute!
36
+ * If relativeTo is a non-file URL, then it will try to resolve the filename relative to it.
37
+ * @param filename - url string
38
+ * @returns ResolveFileResult
39
+ */
40
+ tryUrlRel: (filename: string, relativeToURL: string | URL) => Promise<ResolveFileResult | undefined>;
33
41
  /**
34
42
  * Check to see if it is a URL.
35
43
  * Note: URLs are absolute!
@@ -45,7 +45,7 @@ export class FileResolver {
45
45
  async _resolveFile(filename, relativeTo) {
46
46
  filename = patchFilename(filename, this.templateReplacements);
47
47
  const steps = [
48
- { filename, fn: this.tryUrl },
48
+ { filename, fn: this.tryUrlRel },
49
49
  { filename, fn: this.tryCreateRequire },
50
50
  { filename, fn: this.tryNodeRequireResolve },
51
51
  { filename, fn: this.tryImportResolve },
@@ -84,7 +84,7 @@ export class FileResolver {
84
84
  * @param filename - url string
85
85
  * @returns ResolveFileResult
86
86
  */
87
- tryUrl = async (filename, relativeToURL) => {
87
+ tryUrlRel = async (filename, relativeToURL) => {
88
88
  if (isURLLike(filename)) {
89
89
  const fileURL = toURL(filename);
90
90
  return {
@@ -94,6 +94,26 @@ export class FileResolver {
94
94
  method: 'tryUrl',
95
95
  };
96
96
  }
97
+ if (isRelative(filename) && isURLLike(relativeToURL) && !isDataURL(relativeToURL)) {
98
+ const relToURL = toURL(relativeToURL);
99
+ const url = resolveFileWithURL(filename, relToURL);
100
+ return {
101
+ filename: toFilePathOrHref(url),
102
+ relativeTo: toFilePathOrHref(relToURL),
103
+ found: await this.doesExist(url),
104
+ method: 'tryUrl',
105
+ };
106
+ }
107
+ return undefined;
108
+ };
109
+ /**
110
+ * Check to see if it is a URL.
111
+ * Note: URLs are absolute!
112
+ * If relativeTo is a non-file URL, then it will try to resolve the filename relative to it.
113
+ * @param filename - url string
114
+ * @returns ResolveFileResult
115
+ */
116
+ tryUrl = async (filename, relativeToURL) => {
97
117
  if (isURLLike(relativeToURL) && !isDataURL(relativeToURL)) {
98
118
  const relToURL = toURL(relativeToURL);
99
119
  const url = resolveFileWithURL(filename, relToURL);
@@ -3,13 +3,15 @@ import { readLines } from './util/fileReader.js';
3
3
  import { concatIterables, toIterableIterator } from './util/iterableIteratorLib.js';
4
4
  import { logError } from './util/logger.js';
5
5
  import * as Text from './util/text.js';
6
+ import { toFileUrl } from './util/url.js';
6
7
  const regExpWordsWithSpaces = /^\s*\p{L}+(?:\s+\p{L}+){0,3}$/u;
7
8
  /**
8
9
  * Reads words from a file. It will not throw and error.
9
10
  * @param filename the file to read
10
11
  */
11
12
  export function loadWordsNoError(filename) {
12
- return readLines(filename).catch((e) => (logError(e), toIterableIterator([])));
13
+ const url = toFileUrl(filename);
14
+ return readLines(url).catch((e) => (logError(e), toIterableIterator([])));
13
15
  }
14
16
  export function splitLine(line) {
15
17
  return [...Text.extractWordsFromText(line)].map(({ text }) => text);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cspell-lib",
3
- "version": "8.2.0",
3
+ "version": "8.2.3",
4
4
  "description": "A library of useful functions used across various cspell tools.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -57,21 +57,21 @@
57
57
  },
58
58
  "homepage": "https://github.com/streetsidesoftware/cspell#readme",
59
59
  "dependencies": {
60
- "@cspell/cspell-bundled-dicts": "8.2.0",
61
- "@cspell/cspell-pipe": "8.2.0",
62
- "@cspell/cspell-resolver": "8.2.0",
63
- "@cspell/cspell-types": "8.2.0",
64
- "@cspell/dynamic-import": "8.2.0",
65
- "@cspell/strong-weak-map": "8.2.0",
60
+ "@cspell/cspell-bundled-dicts": "8.2.3",
61
+ "@cspell/cspell-pipe": "8.2.3",
62
+ "@cspell/cspell-resolver": "8.2.3",
63
+ "@cspell/cspell-types": "8.2.3",
64
+ "@cspell/dynamic-import": "8.2.3",
65
+ "@cspell/strong-weak-map": "8.2.3",
66
66
  "clear-module": "^4.1.2",
67
67
  "comment-json": "^4.2.3",
68
68
  "configstore": "^6.0.0",
69
- "cspell-config-lib": "8.2.0",
70
- "cspell-dictionary": "8.2.0",
71
- "cspell-glob": "8.2.0",
72
- "cspell-grammar": "8.2.0",
73
- "cspell-io": "8.2.0",
74
- "cspell-trie-lib": "8.2.0",
69
+ "cspell-config-lib": "8.2.3",
70
+ "cspell-dictionary": "8.2.3",
71
+ "cspell-glob": "8.2.3",
72
+ "cspell-grammar": "8.2.3",
73
+ "cspell-io": "8.2.3",
74
+ "cspell-trie-lib": "8.2.3",
75
75
  "fast-equals": "^5.0.1",
76
76
  "gensequence": "^6.0.0",
77
77
  "import-fresh": "^3.3.0",
@@ -95,5 +95,5 @@
95
95
  "cspell-dict-nl-nl": "^1.1.2",
96
96
  "lorem-ipsum": "^2.0.8"
97
97
  },
98
- "gitHead": "3bcd6430bb33fb221d07030a60a2d61a2479e7ae"
98
+ "gitHead": "e3098b21e0a199d61226f8ff4989d48b385eddfa"
99
99
  }
@@ -1,9 +0,0 @@
1
- import type { CSpellIO } from 'cspell-io';
2
- /**
3
- * The settings controller manages requests to resolve configuration settings and files.
4
- */
5
- export declare class SettingsController {
6
- readonly cspellIO: CSpellIO;
7
- constructor(cspellIO: CSpellIO);
8
- }
9
- //# sourceMappingURL=SettingsController.d.ts.map
@@ -1,10 +0,0 @@
1
- /**
2
- * The settings controller manages requests to resolve configuration settings and files.
3
- */
4
- export class SettingsController {
5
- cspellIO;
6
- constructor(cspellIO) {
7
- this.cspellIO = cspellIO;
8
- }
9
- }
10
- //# sourceMappingURL=SettingsController.js.map