cspell-lib 8.2.1 → 8.2.4
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/esm/Models/TextDocument.js +4 -3
- package/dist/esm/Settings/Controller/configLoader/configLoader.js +4 -2
- package/dist/esm/Settings/Controller/configLoader/configSearch.d.ts +2 -1
- package/dist/esm/Settings/Controller/configLoader/configSearch.js +22 -11
- package/dist/esm/Settings/Controller/index.d.ts +1 -1
- package/dist/esm/Settings/Controller/index.js +1 -1
- package/dist/esm/Settings/DictionarySettings.js +2 -2
- package/dist/esm/SpellingDictionary/Dictionaries.d.ts +0 -2
- package/dist/esm/SpellingDictionary/Dictionaries.js +1 -8
- package/dist/esm/SpellingDictionary/DictionaryController/DictionaryLoader.d.ts +5 -6
- package/dist/esm/SpellingDictionary/DictionaryController/DictionaryLoader.js +26 -100
- package/dist/esm/SpellingDictionary/DictionaryLoader.d.ts +2 -3
- package/dist/esm/SpellingDictionary/DictionaryLoader.js +3 -6
- package/dist/esm/fileSystem.d.ts +3 -3
- package/dist/esm/fileSystem.js +6 -5
- package/dist/esm/textValidation/docValidator.d.ts +15 -0
- package/dist/esm/textValidation/docValidator.js +36 -2
- package/dist/esm/trace.js +2 -5
- package/dist/esm/util/AutoResolve.d.ts +15 -0
- package/dist/esm/util/AutoResolve.js +53 -0
- package/dist/esm/util/TextRange.d.ts +4 -0
- package/dist/esm/util/Uri.js +1 -1
- package/dist/esm/util/fileReader.d.ts +2 -3
- package/dist/esm/util/fileReader.js +5 -7
- package/dist/esm/util/resolveFile.d.ts +8 -0
- package/dist/esm/util/resolveFile.js +22 -2
- package/dist/esm/util/simpleCache.d.ts +1 -0
- package/dist/esm/util/simpleCache.js +10 -1
- package/dist/esm/wordListHelper.js +3 -1
- package/package.json +15 -15
- package/dist/esm/Settings/Controller/SettingsController.d.ts +0 -9
- package/dist/esm/Settings/Controller/SettingsController.js +0 -10
|
@@ -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
|
|
107
|
-
|
|
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 {
|
|
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:
|
|
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 {
|
|
1
|
+
import type { VFileSystem } from '../../../fileSystem.js';
|
|
2
2
|
export declare class ConfigSearch {
|
|
3
3
|
readonly searchPlaces: readonly string[];
|
|
4
4
|
private fs;
|
|
@@ -10,6 +10,7 @@ export declare class ConfigSearch {
|
|
|
10
10
|
private findUpConfigPath;
|
|
11
11
|
private hasConfig;
|
|
12
12
|
private createHasFileDirSearch;
|
|
13
|
+
private readDir;
|
|
13
14
|
private createHasFileStatCheck;
|
|
14
15
|
private hasConfigDir;
|
|
15
16
|
}
|
|
@@ -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,14 +67,33 @@ 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() && !found?.isSymbolicLink())
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
71
80
|
const dirUrlHref = dir.href;
|
|
72
|
-
const dirInfo = await dirInfoCache.get(dirUrlHref, async () =>
|
|
81
|
+
const dirInfo = await dirInfoCache.get(dirUrlHref, async () => await this.readDir(dir));
|
|
73
82
|
const name = urlBasename(filename);
|
|
74
83
|
const found = dirInfo.get(name);
|
|
75
|
-
return
|
|
84
|
+
return found?.isFile() || found?.isSymbolicLink() || false;
|
|
76
85
|
};
|
|
77
86
|
return hasFile;
|
|
78
87
|
}
|
|
88
|
+
async readDir(dir) {
|
|
89
|
+
try {
|
|
90
|
+
const dirInfo = await this.fs.readDirectory(dir);
|
|
91
|
+
return new Map(dirInfo.map((ent) => [ent.name, ent]));
|
|
92
|
+
}
|
|
93
|
+
catch (e) {
|
|
94
|
+
return new Map();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
79
97
|
createHasFileStatCheck() {
|
|
80
98
|
const hasFile = async (filename) => {
|
|
81
99
|
const stat = await this.fs.stat(filename).catch(() => undefined);
|
|
@@ -102,7 +120,7 @@ export class ConfigSearch {
|
|
|
102
120
|
}
|
|
103
121
|
async function checkPackageJson(fs, filename) {
|
|
104
122
|
try {
|
|
105
|
-
const file =
|
|
123
|
+
const file = await fs.readFile(filename);
|
|
106
124
|
const pkg = JSON.parse(file.getText());
|
|
107
125
|
return typeof pkg.cspell === 'object';
|
|
108
126
|
}
|
|
@@ -110,11 +128,4 @@ async function checkPackageJson(fs, filename) {
|
|
|
110
128
|
return false;
|
|
111
129
|
}
|
|
112
130
|
}
|
|
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
131
|
//# sourceMappingURL=configSearch.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { defaultConfigFilenames } from './configLoader/index.js';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { defaultConfigFilenames } from './configLoader/index.js';
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { mapDictionaryInformationToWeightMap } from 'cspell-trie-lib';
|
|
2
2
|
import * as path from 'path';
|
|
3
3
|
import { isDictionaryDefinitionInlineInternal } from '../Models/CSpellSettingsInternalDef.js';
|
|
4
|
-
import {
|
|
4
|
+
import { createAutoResolveWeakWeakCache } from '../util/AutoResolve.js';
|
|
5
5
|
import { resolveRelativeTo } from '../util/resolveFile.js';
|
|
6
6
|
import { toFilePathOrHref } from '../util/url.js';
|
|
7
7
|
import { clean } from '../util/util.js';
|
|
@@ -40,7 +40,7 @@ function fixDicPath(defPath, defFile) {
|
|
|
40
40
|
export function mapDictDefsToInternal(defs, pathToSettingsFile) {
|
|
41
41
|
return defs?.map((def) => mapDictDefToInternal(def, pathToSettingsFile));
|
|
42
42
|
}
|
|
43
|
-
const internalDefs =
|
|
43
|
+
const internalDefs = createAutoResolveWeakWeakCache();
|
|
44
44
|
export function mapDictDefToInternal(def, pathToSettingsFile) {
|
|
45
45
|
return internalDefs.get(def, (def) => _mapDictDefToInternal(def, pathToSettingsFile));
|
|
46
46
|
}
|
|
@@ -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,
|
|
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,17 @@
|
|
|
1
1
|
import type { SpellingDictionary } from 'cspell-dictionary';
|
|
2
|
-
import type {
|
|
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
|
|
6
|
+
private fs;
|
|
7
7
|
private dictionaryCache;
|
|
8
8
|
private inlineDictionaryCache;
|
|
9
9
|
private dictionaryCacheByDef;
|
|
10
10
|
private reader;
|
|
11
|
-
|
|
11
|
+
/** The keepAliveCache is to hold onto the most recently loaded dictionaries. */
|
|
12
|
+
private keepAliveCache;
|
|
13
|
+
constructor(fs: VFileSystem, keepAliveSize?: number);
|
|
12
14
|
loadDictionary(def: DictionaryDefinitionInternal): Promise<SpellingDictionary>;
|
|
13
|
-
loadDictionarySync(def: DictionaryDefinitionInternal): SpellingDictionary;
|
|
14
15
|
/**
|
|
15
16
|
* Check to see if any of the cached dictionaries have changed. If one has changed, reload it.
|
|
16
17
|
* @param maxAge - Only check the dictionary if it has been at least `maxAge` ms since the last check.
|
|
@@ -21,9 +22,7 @@ export declare class DictionaryLoader {
|
|
|
21
22
|
private setCacheEntry;
|
|
22
23
|
private refreshEntry;
|
|
23
24
|
private loadEntry;
|
|
24
|
-
private loadEntrySync;
|
|
25
25
|
private getStat;
|
|
26
|
-
private getStatSync;
|
|
27
26
|
private isEqual;
|
|
28
27
|
private normalizeOptions;
|
|
29
28
|
private loadInlineDict;
|
|
@@ -1,9 +1,11 @@
|
|
|
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
|
-
import { AutoResolveWeakCache } from '../../util/AutoResolve.js';
|
|
6
|
+
import { AutoResolveWeakCache, AutoResolveWeakWeakCache } from '../../util/AutoResolve.js';
|
|
6
7
|
import { toError } from '../../util/errors.js';
|
|
8
|
+
import { SimpleCache } from '../../util/simpleCache.js';
|
|
7
9
|
import { SpellingDictionaryLoadError } from '../SpellingDictionaryError.js';
|
|
8
10
|
const MAX_AGE = 10000;
|
|
9
11
|
const loaders = {
|
|
@@ -13,27 +15,23 @@ const loaders = {
|
|
|
13
15
|
T: loadTrie,
|
|
14
16
|
default: loadSimpleWordList,
|
|
15
17
|
};
|
|
16
|
-
const loadersSync = {
|
|
17
|
-
S: loadSimpleWordListSync,
|
|
18
|
-
C: legacyWordListSync,
|
|
19
|
-
W: wordsPerLineWordListSync,
|
|
20
|
-
T: loadTrieSync,
|
|
21
|
-
default: loadSimpleWordListSync,
|
|
22
|
-
};
|
|
23
18
|
var LoadingState;
|
|
24
19
|
(function (LoadingState) {
|
|
25
20
|
LoadingState[LoadingState["Loaded"] = 0] = "Loaded";
|
|
26
21
|
LoadingState[LoadingState["Loading"] = 1] = "Loading";
|
|
27
22
|
})(LoadingState || (LoadingState = {}));
|
|
28
23
|
export class DictionaryLoader {
|
|
29
|
-
|
|
24
|
+
fs;
|
|
30
25
|
dictionaryCache = new StrongWeakMap();
|
|
31
26
|
inlineDictionaryCache = new AutoResolveWeakCache();
|
|
32
|
-
dictionaryCacheByDef = new
|
|
27
|
+
dictionaryCacheByDef = new AutoResolveWeakWeakCache();
|
|
33
28
|
reader;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
/** The keepAliveCache is to hold onto the most recently loaded dictionaries. */
|
|
30
|
+
keepAliveCache;
|
|
31
|
+
constructor(fs, keepAliveSize = 10) {
|
|
32
|
+
this.fs = fs;
|
|
33
|
+
this.reader = toReader(fs);
|
|
34
|
+
this.keepAliveCache = new SimpleCache(keepAliveSize);
|
|
37
35
|
}
|
|
38
36
|
loadDictionary(def) {
|
|
39
37
|
if (isDictionaryDefinitionInlineInternal(def)) {
|
|
@@ -45,20 +43,9 @@ export class DictionaryLoader {
|
|
|
45
43
|
}
|
|
46
44
|
const loadedEntry = this.loadEntry(def.path, def);
|
|
47
45
|
this.setCacheEntry(key, loadedEntry, def);
|
|
46
|
+
this.keepAliveCache.set(def, loadedEntry);
|
|
48
47
|
return loadedEntry.pending.then(([dictionary]) => dictionary);
|
|
49
48
|
}
|
|
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
49
|
/**
|
|
63
50
|
* Check to see if any of the cached dictionaries have changed. If one has changed, reload it.
|
|
64
51
|
* @param maxAge - Only check the dictionary if it has been at least `maxAge` ms since the last check.
|
|
@@ -70,6 +57,7 @@ export class DictionaryLoader {
|
|
|
70
57
|
getCacheEntry(def) {
|
|
71
58
|
const defEntry = this.dictionaryCacheByDef.get(def);
|
|
72
59
|
if (defEntry) {
|
|
60
|
+
this.keepAliveCache.get(def);
|
|
73
61
|
return defEntry;
|
|
74
62
|
}
|
|
75
63
|
const key = this.calcKey(def);
|
|
@@ -77,6 +65,7 @@ export class DictionaryLoader {
|
|
|
77
65
|
if (entry) {
|
|
78
66
|
// replace old entry so it can be released.
|
|
79
67
|
entry.options = def;
|
|
68
|
+
this.keepAliveCache.set(def, entry);
|
|
80
69
|
}
|
|
81
70
|
return { key, entry };
|
|
82
71
|
}
|
|
@@ -104,9 +93,9 @@ export class DictionaryLoader {
|
|
|
104
93
|
}
|
|
105
94
|
}
|
|
106
95
|
loadEntry(fileOrUri, options, now = Date.now()) {
|
|
107
|
-
const url =
|
|
96
|
+
const url = toFileURL(fileOrUri);
|
|
108
97
|
options = this.normalizeOptions(url, options);
|
|
109
|
-
const pDictionary = load(this.reader,
|
|
98
|
+
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
99
|
const pStat = this.getStat(fileOrUri);
|
|
111
100
|
const pending = Promise.all([pDictionary, pStat]);
|
|
112
101
|
const sig = now + Math.random();
|
|
@@ -129,51 +118,8 @@ export class DictionaryLoader {
|
|
|
129
118
|
});
|
|
130
119
|
return entry;
|
|
131
120
|
}
|
|
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
121
|
getStat(uri) {
|
|
168
|
-
return this.
|
|
169
|
-
}
|
|
170
|
-
getStatSync(uri) {
|
|
171
|
-
try {
|
|
172
|
-
return this.cspellIO.getStatSync(this.cspellIO.toFileURL(uri));
|
|
173
|
-
}
|
|
174
|
-
catch (e) {
|
|
175
|
-
return toError(e);
|
|
176
|
-
}
|
|
122
|
+
return this.fs.stat(toFileURL(uri)).catch(toError);
|
|
177
123
|
}
|
|
178
124
|
isEqual(a, b) {
|
|
179
125
|
if (!b)
|
|
@@ -181,30 +127,31 @@ export class DictionaryLoader {
|
|
|
181
127
|
if (isError(a)) {
|
|
182
128
|
return isError(b) && a.message === b.message && a.name === b.name;
|
|
183
129
|
}
|
|
184
|
-
return !isError(b) && !
|
|
130
|
+
return !isError(b) && !compareStats(a, b);
|
|
185
131
|
}
|
|
186
132
|
normalizeOptions(uri, options) {
|
|
187
133
|
if (options.name)
|
|
188
134
|
return options;
|
|
189
|
-
return { ...options, name:
|
|
135
|
+
return { ...options, name: urlBasename(uri) };
|
|
190
136
|
}
|
|
191
137
|
loadInlineDict(def) {
|
|
192
138
|
return this.inlineDictionaryCache.get(def, (def) => createInlineSpellingDictionary(def, def.__source || 'memory'));
|
|
193
139
|
}
|
|
194
140
|
calcKey(def) {
|
|
195
141
|
const path = def.path;
|
|
196
|
-
const loaderType = determineType(
|
|
142
|
+
const loaderType = determineType(toFileURL(path), def);
|
|
197
143
|
const optValues = importantOptionKeys.map((k) => def[k]?.toString() || '');
|
|
198
144
|
const parts = [path, loaderType].concat(optValues);
|
|
199
145
|
return parts.join('|');
|
|
200
146
|
}
|
|
201
147
|
}
|
|
202
|
-
function toReader(
|
|
148
|
+
function toReader(fs) {
|
|
149
|
+
async function readFile(url) {
|
|
150
|
+
return (await fs.readFile(url)).getText();
|
|
151
|
+
}
|
|
203
152
|
return {
|
|
204
|
-
read:
|
|
205
|
-
readLines: async (filename) => toLines(
|
|
206
|
-
readSync: (filename) => cspellIO.readFileSync(filename).getText(),
|
|
207
|
-
readLinesSync: (filename) => toLines(cspellIO.readFileSync(filename).getText()),
|
|
153
|
+
read: readFile,
|
|
154
|
+
readLines: async (filename) => toLines(await readFile(filename)),
|
|
208
155
|
};
|
|
209
156
|
}
|
|
210
157
|
const importantOptionKeys = ['name', 'noSuggest', 'useCompounds', 'type'];
|
|
@@ -224,19 +171,10 @@ function load(reader, uri, options) {
|
|
|
224
171
|
const loader = loaders[type] || loaders.default;
|
|
225
172
|
return loader(reader, uri, options);
|
|
226
173
|
}
|
|
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
174
|
async function legacyWordList(reader, filename, options) {
|
|
233
175
|
const lines = await reader.readLines(filename);
|
|
234
176
|
return _legacyWordListSync(lines, filename, options);
|
|
235
177
|
}
|
|
236
|
-
function legacyWordListSync(reader, filename, options) {
|
|
237
|
-
const lines = reader.readLinesSync(filename);
|
|
238
|
-
return _legacyWordListSync(lines, filename, options);
|
|
239
|
-
}
|
|
240
178
|
function _legacyWordListSync(lines, filename, options) {
|
|
241
179
|
const words = pipe(lines,
|
|
242
180
|
// Remove comments
|
|
@@ -249,10 +187,6 @@ async function wordsPerLineWordList(reader, filename, options) {
|
|
|
249
187
|
const lines = await reader.readLines(filename);
|
|
250
188
|
return _wordsPerLineWordList(lines, filename.toString(), options);
|
|
251
189
|
}
|
|
252
|
-
function wordsPerLineWordListSync(reader, filename, options) {
|
|
253
|
-
const lines = reader.readLinesSync(filename);
|
|
254
|
-
return _wordsPerLineWordList(lines, filename.toString(), options);
|
|
255
|
-
}
|
|
256
190
|
function _wordsPerLineWordList(lines, filename, options) {
|
|
257
191
|
const words = pipe(lines,
|
|
258
192
|
// Remove comments
|
|
@@ -265,18 +199,10 @@ async function loadSimpleWordList(reader, filename, options) {
|
|
|
265
199
|
const lines = await reader.readLines(filename);
|
|
266
200
|
return createSpellingDictionary(lines, options.name, filename.href, options);
|
|
267
201
|
}
|
|
268
|
-
function loadSimpleWordListSync(reader, filename, options) {
|
|
269
|
-
const lines = reader.readLinesSync(filename);
|
|
270
|
-
return createSpellingDictionary(lines, options.name, filename.href, options);
|
|
271
|
-
}
|
|
272
202
|
async function loadTrie(reader, filename, options) {
|
|
273
203
|
const content = await reader.read(filename);
|
|
274
204
|
return createSpellingDictionaryFromTrieFile(content, options.name, filename.href, options);
|
|
275
205
|
}
|
|
276
|
-
function loadTrieSync(reader, filename, options) {
|
|
277
|
-
const content = reader.readSync(filename);
|
|
278
|
-
return createSpellingDictionaryFromTrieFile(content, options.name, filename.href, options);
|
|
279
|
-
}
|
|
280
206
|
function toLines(content) {
|
|
281
207
|
return content.split(/\n|\r\n|\r/);
|
|
282
208
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import type { SpellingDictionary } from 'cspell-dictionary';
|
|
2
|
-
import type {
|
|
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(
|
|
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 {
|
|
1
|
+
import { getFileSystem } from '../fileSystem.js';
|
|
2
2
|
import { DictionaryLoader } from './DictionaryController/index.js';
|
|
3
3
|
let loader;
|
|
4
|
-
export function getDictionaryLoader(
|
|
4
|
+
export function getDictionaryLoader(vfs) {
|
|
5
5
|
if (loader)
|
|
6
6
|
return loader;
|
|
7
|
-
return (loader = new DictionaryLoader(
|
|
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.
|
package/dist/esm/fileSystem.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TextEncoding, VFileSystemProvider } from 'cspell-io';
|
|
2
2
|
export type { VFileSystemProvider, VfsDirEntry, VirtualFS } from 'cspell-io';
|
|
3
|
-
export {
|
|
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
|
package/dist/esm/fileSystem.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
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
|
|
@@ -72,6 +72,21 @@ export declare class DocumentValidator {
|
|
|
72
72
|
checkDocumentDirectives(forceCheck?: boolean): ValidationIssue[];
|
|
73
73
|
get document(): TextDocument;
|
|
74
74
|
updateDocumentText(text: string): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Get the calculated ranges of text that should be included in the spell checking.
|
|
77
|
+
* @returns MatchRanges of text to include.
|
|
78
|
+
*/
|
|
79
|
+
getCheckedTextRanges(): MatchRange[];
|
|
80
|
+
traceWord(word: string): {
|
|
81
|
+
word: string;
|
|
82
|
+
found: boolean;
|
|
83
|
+
foundWord: string | undefined;
|
|
84
|
+
forbidden: boolean;
|
|
85
|
+
noSuggest: boolean;
|
|
86
|
+
dictName: string;
|
|
87
|
+
dictSource: string;
|
|
88
|
+
errors: Error[] | undefined;
|
|
89
|
+
}[];
|
|
75
90
|
private defaultParser;
|
|
76
91
|
private _checkParsedText;
|
|
77
92
|
private addPossibleError;
|
|
@@ -6,11 +6,12 @@ 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
|
|
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';
|
|
13
13
|
import { uriToFilePath } from '../util/Uri.js';
|
|
14
|
+
import { toFilePathOrHref } from '../util/url.js';
|
|
14
15
|
import { defaultMaxDuplicateProblems, defaultMaxNumberOfProblems } from './defaultConstants.js';
|
|
15
16
|
import { determineTextDocumentSettings } from './determineTextDocumentSettings.js';
|
|
16
17
|
import { textValidatorFactory } from './lineValidatorFactory.js';
|
|
@@ -108,7 +109,7 @@ export class DocumentValidator {
|
|
|
108
109
|
const timer = createPerfTimer('_updatePrep');
|
|
109
110
|
const prep = this._preparations;
|
|
110
111
|
const docSettings = await determineTextDocumentSettings(this._document, prep.config);
|
|
111
|
-
const dict =
|
|
112
|
+
const dict = await getDictionaryInternal(docSettings);
|
|
112
113
|
const shouldCheck = docSettings.enabled ?? true;
|
|
113
114
|
const finalSettings = finalizeSettings(docSettings);
|
|
114
115
|
const validateOptions = settingsToValidateOptions(finalSettings);
|
|
@@ -237,6 +238,36 @@ export class DocumentValidator {
|
|
|
237
238
|
updateTextDocument(this._document, [{ text }]);
|
|
238
239
|
await this._updatePrep();
|
|
239
240
|
}
|
|
241
|
+
/**
|
|
242
|
+
* Get the calculated ranges of text that should be included in the spell checking.
|
|
243
|
+
* @returns MatchRanges of text to include.
|
|
244
|
+
*/
|
|
245
|
+
getCheckedTextRanges() {
|
|
246
|
+
assert(this._preparations, ERROR_NOT_PREPARED);
|
|
247
|
+
return this._preparations.includeRanges;
|
|
248
|
+
}
|
|
249
|
+
traceWord(word) {
|
|
250
|
+
assert(this._preparations, ERROR_NOT_PREPARED);
|
|
251
|
+
const dictCollection = this._preparations.dictionary;
|
|
252
|
+
const config = this._preparations.config;
|
|
253
|
+
const opts = {
|
|
254
|
+
ignoreCase: true,
|
|
255
|
+
allowCompoundWords: config.allowCompoundWords || false,
|
|
256
|
+
};
|
|
257
|
+
const trace = dictCollection.dictionaries
|
|
258
|
+
.map((dict) => ({ dict, findResult: dict.find(word, opts) }))
|
|
259
|
+
.map(({ dict, findResult }) => ({
|
|
260
|
+
word,
|
|
261
|
+
found: !!findResult?.found,
|
|
262
|
+
foundWord: findResult?.found || undefined,
|
|
263
|
+
forbidden: findResult?.forbidden || false,
|
|
264
|
+
noSuggest: findResult?.noSuggest || false,
|
|
265
|
+
dictName: dict.name,
|
|
266
|
+
dictSource: toFilePathOrHref(dict.source),
|
|
267
|
+
errors: normalizeErrors(dict.getErrors?.()),
|
|
268
|
+
}));
|
|
269
|
+
return trace;
|
|
270
|
+
}
|
|
240
271
|
defaultParser() {
|
|
241
272
|
return pipeSync(this.document.getLines(), opMap((line) => {
|
|
242
273
|
const { text, offset } = line;
|
|
@@ -378,4 +409,7 @@ function recordPerfTime(timings, name) {
|
|
|
378
409
|
function timePromise(timings, name, p) {
|
|
379
410
|
return p.finally(recordPerfTime(timings, name));
|
|
380
411
|
}
|
|
412
|
+
function normalizeErrors(errors) {
|
|
413
|
+
return errors?.length ? errors : undefined;
|
|
414
|
+
}
|
|
381
415
|
//# sourceMappingURL=docValidator.js.map
|
package/dist/esm/trace.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { fileURLToPath } from 'node:url';
|
|
2
1
|
import { genSequence } from 'gensequence';
|
|
3
2
|
import { toInternalSettings } from './Settings/CSpellSettingsServer.js';
|
|
4
3
|
import { finalizeSettings, mergeSettings } from './Settings/index.js';
|
|
5
4
|
import { calcSettingsForLanguageId } from './Settings/LanguageSettings.js';
|
|
6
5
|
import { getDictionaryInternal, refreshDictionaryCache } from './SpellingDictionary/index.js';
|
|
6
|
+
import { toFilePathOrHref } from './util/url.js';
|
|
7
7
|
import * as util from './util/util.js';
|
|
8
8
|
export async function traceWords(words, settings, options) {
|
|
9
9
|
const results = await util.asyncIterableToArray(traceWordsAsync(words, settings, options));
|
|
@@ -64,9 +64,6 @@ export async function* traceWordsAsync(words, settings, options) {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
function dictSourceToFilename(source) {
|
|
67
|
-
|
|
68
|
-
return fileURLToPath(source);
|
|
69
|
-
}
|
|
70
|
-
return source;
|
|
67
|
+
return toFilePathOrHref(source);
|
|
71
68
|
}
|
|
72
69
|
//# sourceMappingURL=trace.js.map
|
|
@@ -46,5 +46,20 @@ export declare class AutoResolveWeakCache<K extends object, V> implements IWeakM
|
|
|
46
46
|
stats(): AutoResolveCacheStats;
|
|
47
47
|
}
|
|
48
48
|
export declare function createAutoResolveWeakCache<K extends object, V>(): AutoResolveWeakCache<K, V>;
|
|
49
|
+
export declare class AutoResolveWeakWeakCache<K extends object, V extends object> implements IWeakMap<K, V> {
|
|
50
|
+
private _map;
|
|
51
|
+
private _stats;
|
|
52
|
+
get(k: K): V | undefined;
|
|
53
|
+
get(k: K, resolve: (k: K) => V): V;
|
|
54
|
+
get(k: K, resolve?: (k: K) => V): V | undefined;
|
|
55
|
+
get map(): WeakMap<K, WeakRef<V>>;
|
|
56
|
+
has(k: K): boolean;
|
|
57
|
+
set(k: K, v: V): this;
|
|
58
|
+
clear(): void;
|
|
59
|
+
delete(k: K): boolean;
|
|
60
|
+
dispose(): void;
|
|
61
|
+
stats(): AutoResolveCacheStats;
|
|
62
|
+
}
|
|
63
|
+
export declare function createAutoResolveWeakWeakCache<K extends object, V extends object>(): AutoResolveWeakWeakCache<K, V>;
|
|
49
64
|
export {};
|
|
50
65
|
//# sourceMappingURL=AutoResolve.d.ts.map
|
|
@@ -116,4 +116,57 @@ export class AutoResolveWeakCache {
|
|
|
116
116
|
export function createAutoResolveWeakCache() {
|
|
117
117
|
return new AutoResolveWeakCache();
|
|
118
118
|
}
|
|
119
|
+
export class AutoResolveWeakWeakCache {
|
|
120
|
+
_map = new WeakMap();
|
|
121
|
+
_stats = new CacheStatsTracker();
|
|
122
|
+
get(k, resolve) {
|
|
123
|
+
const map = this._map;
|
|
124
|
+
const found = map.get(k);
|
|
125
|
+
const foundValue = found?.deref();
|
|
126
|
+
if (found !== undefined && foundValue) {
|
|
127
|
+
++this._stats.hits;
|
|
128
|
+
return foundValue;
|
|
129
|
+
}
|
|
130
|
+
++this._stats.misses;
|
|
131
|
+
if (!resolve) {
|
|
132
|
+
if (found) {
|
|
133
|
+
map.delete(k);
|
|
134
|
+
}
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
++this._stats.resolved;
|
|
138
|
+
const value = resolve(k);
|
|
139
|
+
map.set(k, new WeakRef(value));
|
|
140
|
+
return value;
|
|
141
|
+
}
|
|
142
|
+
get map() {
|
|
143
|
+
return this._map;
|
|
144
|
+
}
|
|
145
|
+
has(k) {
|
|
146
|
+
return !!this._map.get(k)?.deref();
|
|
147
|
+
}
|
|
148
|
+
set(k, v) {
|
|
149
|
+
++this._stats.sets;
|
|
150
|
+
this._map.set(k, new WeakRef(v));
|
|
151
|
+
return this;
|
|
152
|
+
}
|
|
153
|
+
clear() {
|
|
154
|
+
this._stats.clear();
|
|
155
|
+
this._map = new WeakMap();
|
|
156
|
+
}
|
|
157
|
+
delete(k) {
|
|
158
|
+
++this._stats.deletes;
|
|
159
|
+
return this._map.delete(k);
|
|
160
|
+
}
|
|
161
|
+
dispose() {
|
|
162
|
+
++this._stats.disposals;
|
|
163
|
+
this.clear();
|
|
164
|
+
}
|
|
165
|
+
stats() {
|
|
166
|
+
return this._stats.stats();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
export function createAutoResolveWeakWeakCache() {
|
|
170
|
+
return new AutoResolveWeakWeakCache();
|
|
171
|
+
}
|
|
119
172
|
//# sourceMappingURL=AutoResolve.js.map
|
package/dist/esm/util/Uri.js
CHANGED
|
@@ -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 || '').
|
|
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
|
|
2
|
-
export declare function readLines(
|
|
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 {
|
|
1
|
+
import { toFileURL } from 'cspell-io';
|
|
2
|
+
import { readTextFile } from '../fileSystem.js';
|
|
2
3
|
import { toIterableIterator } from './iterableIteratorLib.js';
|
|
3
|
-
export async function readLines(
|
|
4
|
+
export async function readLines(url, encoding = 'utf8') {
|
|
4
5
|
try {
|
|
5
|
-
|
|
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.
|
|
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
|
-
|
|
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);
|
|
@@ -103,6 +103,13 @@ export class SimpleCache {
|
|
|
103
103
|
set(key, value) {
|
|
104
104
|
this._set(key, { v: value });
|
|
105
105
|
}
|
|
106
|
+
delete(key) {
|
|
107
|
+
let deleted = false;
|
|
108
|
+
for (const c of this.caches()) {
|
|
109
|
+
deleted = c.delete(key) || deleted;
|
|
110
|
+
}
|
|
111
|
+
return deleted;
|
|
112
|
+
}
|
|
106
113
|
_set(key, entry) {
|
|
107
114
|
if (this.L0.has(key)) {
|
|
108
115
|
this.L0.set(key, entry);
|
|
@@ -117,9 +124,11 @@ export class SimpleCache {
|
|
|
117
124
|
return [this.L0, this.L1, this.L2];
|
|
118
125
|
}
|
|
119
126
|
rotate() {
|
|
127
|
+
const L2 = this.L2;
|
|
120
128
|
this.L2 = this.L1;
|
|
121
129
|
this.L1 = this.L0;
|
|
122
|
-
this.L0 =
|
|
130
|
+
this.L0 = L2;
|
|
131
|
+
this.L0.clear();
|
|
123
132
|
}
|
|
124
133
|
}
|
|
125
134
|
export class AutoCache extends SimpleCache {
|
|
@@ -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
|
-
|
|
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.
|
|
3
|
+
"version": "8.2.4",
|
|
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.
|
|
61
|
-
"@cspell/cspell-pipe": "8.2.
|
|
62
|
-
"@cspell/cspell-resolver": "8.2.
|
|
63
|
-
"@cspell/cspell-types": "8.2.
|
|
64
|
-
"@cspell/dynamic-import": "8.2.
|
|
65
|
-
"@cspell/strong-weak-map": "8.2.
|
|
60
|
+
"@cspell/cspell-bundled-dicts": "8.2.4",
|
|
61
|
+
"@cspell/cspell-pipe": "8.2.4",
|
|
62
|
+
"@cspell/cspell-resolver": "8.2.4",
|
|
63
|
+
"@cspell/cspell-types": "8.2.4",
|
|
64
|
+
"@cspell/dynamic-import": "8.2.4",
|
|
65
|
+
"@cspell/strong-weak-map": "8.2.4",
|
|
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.
|
|
70
|
-
"cspell-dictionary": "8.2.
|
|
71
|
-
"cspell-glob": "8.2.
|
|
72
|
-
"cspell-grammar": "8.2.
|
|
73
|
-
"cspell-io": "8.2.
|
|
74
|
-
"cspell-trie-lib": "8.2.
|
|
69
|
+
"cspell-config-lib": "8.2.4",
|
|
70
|
+
"cspell-dictionary": "8.2.4",
|
|
71
|
+
"cspell-glob": "8.2.4",
|
|
72
|
+
"cspell-grammar": "8.2.4",
|
|
73
|
+
"cspell-io": "8.2.4",
|
|
74
|
+
"cspell-trie-lib": "8.2.4",
|
|
75
75
|
"fast-equals": "^5.0.1",
|
|
76
76
|
"gensequence": "^6.0.0",
|
|
77
77
|
"import-fresh": "^3.3.0",
|
|
@@ -90,10 +90,10 @@
|
|
|
90
90
|
"@cspell/dict-fr-fr": "^2.2.2",
|
|
91
91
|
"@cspell/dict-html": "^4.0.5",
|
|
92
92
|
"@cspell/dict-nl-nl": "^2.3.0",
|
|
93
|
-
"@cspell/dict-python": "^4.1.
|
|
93
|
+
"@cspell/dict-python": "^4.1.11",
|
|
94
94
|
"@types/configstore": "^6.0.2",
|
|
95
95
|
"cspell-dict-nl-nl": "^1.1.2",
|
|
96
96
|
"lorem-ipsum": "^2.0.8"
|
|
97
97
|
},
|
|
98
|
-
"gitHead": "
|
|
98
|
+
"gitHead": "d3c5ff685b3aa2bf984f557d81380f2c994547e0"
|
|
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
|