cspell-lib 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/dist/Document/Document.d.ts +2 -0
- package/dist/Document/isBinaryDoc.d.ts +3 -2
- package/dist/Document/isBinaryDoc.js +6 -5
- package/dist/Document/resolveDocument.js +28 -5
- package/dist/LanguageIds.js +2 -1
- package/dist/Models/TextDocument.d.ts +21 -1
- package/dist/Models/TextDocument.js +2 -2
- package/dist/Settings/CSpellSettingsServer.js +19 -7
- package/dist/Settings/Controller/configLoader/PnPSettings.d.ts +12 -0
- package/dist/Settings/Controller/configLoader/PnPSettings.js +26 -0
- package/dist/Settings/Controller/configLoader/configLoader.d.ts +36 -13
- package/dist/Settings/Controller/configLoader/configLoader.js +83 -76
- package/dist/Settings/Controller/pnpLoader.d.ts +6 -6
- package/dist/Settings/Controller/pnpLoader.js +5 -5
- package/dist/Settings/LanguageSettings.js +8 -1
- package/dist/Settings/TextDocumentSettings.d.ts +1 -1
- package/dist/Settings/TextDocumentSettings.js +3 -0
- package/dist/exclusionHelper.js +3 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -1
- package/dist/spellCheckFile.d.ts +3 -1
- package/dist/spellCheckFile.js +2 -2
- package/dist/test/test.matchers.d.ts +9 -0
- package/dist/test/test.matchers.js +27 -0
- package/dist/textValidation/determineTextDocumentSettings.d.ts +2 -2
- package/dist/textValidation/determineTextDocumentSettings.js +2 -1
- package/dist/textValidation/docValidator.d.ts +5 -1
- package/dist/textValidation/docValidator.js +41 -5
- package/dist/textValidation/index.d.ts +1 -1
- package/dist/textValidation/index.js +2 -1
- package/dist/util/AutoResolveLRUCache.d.ts +54 -0
- package/dist/util/AutoResolveLRUCache.js +138 -0
- package/dist/util/Uri.d.ts +51 -0
- package/dist/util/Uri.js +178 -0
- package/dist/util/text.d.ts +3 -1
- package/dist/util/text.js +3 -1
- package/dist/util/util.d.ts +1 -2
- package/dist/util/util.js +17 -11
- package/package.json +17 -16
- package/dist/Models/Uri.d.ts +0 -5
- package/dist/Models/Uri.js +0 -16
|
@@ -3,11 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.DocumentValidator = void 0;
|
|
6
|
+
exports.shouldCheckDocument = exports.DocumentValidator = void 0;
|
|
7
7
|
const sync_1 = require("@cspell/cspell-pipe/sync");
|
|
8
8
|
const cspell_types_1 = require("@cspell/cspell-types");
|
|
9
9
|
const assert_1 = __importDefault(require("assert"));
|
|
10
10
|
const cspell_glob_1 = require("cspell-glob");
|
|
11
|
+
const path_1 = __importDefault(require("path"));
|
|
11
12
|
const TextDocument_1 = require("../Models/TextDocument");
|
|
12
13
|
const Settings_1 = require("../Settings");
|
|
13
14
|
const configLoader_1 = require("../Settings/Controller/configLoader");
|
|
@@ -17,6 +18,7 @@ const suggestions_1 = require("../suggestions");
|
|
|
17
18
|
const errors_1 = require("../util/errors");
|
|
18
19
|
const simpleCache_1 = require("../util/simpleCache");
|
|
19
20
|
const timer_1 = require("../util/timer");
|
|
21
|
+
const Uri_1 = require("../util/Uri");
|
|
20
22
|
const defaultConstants_1 = require("./defaultConstants");
|
|
21
23
|
const determineTextDocumentSettings_1 = require("./determineTextDocumentSettings");
|
|
22
24
|
const lineValidatorFactory_1 = require("./lineValidatorFactory");
|
|
@@ -24,6 +26,7 @@ const parsedText_1 = require("./parsedText");
|
|
|
24
26
|
const settingsToValidateOptions_1 = require("./settingsToValidateOptions");
|
|
25
27
|
const textValidator_1 = require("./textValidator");
|
|
26
28
|
const ERROR_NOT_PREPARED = 'Validator Must be prepared before calling this function.';
|
|
29
|
+
const skipValidation = false;
|
|
27
30
|
class DocumentValidator {
|
|
28
31
|
/**
|
|
29
32
|
* @param doc - Document to validate
|
|
@@ -75,7 +78,7 @@ class DocumentValidator {
|
|
|
75
78
|
const dict = (0, SpellingDictionary_1.getDictionaryInternalSync)(docSettings);
|
|
76
79
|
const matcher = new cspell_glob_1.GlobMatcher(localConfig?.ignorePaths || [], { root: process.cwd(), dot: true });
|
|
77
80
|
const uri = this._document.uri;
|
|
78
|
-
const shouldCheck = !matcher.match(
|
|
81
|
+
const shouldCheck = !matcher.match((0, Uri_1.uriToFilePath)(uri)) && (docSettings.enabled ?? true);
|
|
79
82
|
const finalSettings = (0, Settings_1.finalizeSettings)(docSettings);
|
|
80
83
|
const validateOptions = (0, settingsToValidateOptions_1.settingsToValidateOptions)(finalSettings);
|
|
81
84
|
const includeRanges = (0, textValidator_1.calcTextInclusionRanges)(this._document.text, validateOptions);
|
|
@@ -123,7 +126,7 @@ class DocumentValidator {
|
|
|
123
126
|
const dict = await (0, SpellingDictionary_1.getDictionaryInternal)(docSettings);
|
|
124
127
|
const matcher = new cspell_glob_1.GlobMatcher(localConfig?.ignorePaths || [], { root: process.cwd(), dot: true });
|
|
125
128
|
const uri = this._document.uri;
|
|
126
|
-
const shouldCheck = !matcher.match(
|
|
129
|
+
const shouldCheck = !matcher.match((0, Uri_1.uriToFilePath)(uri)) && (docSettings.enabled ?? true);
|
|
127
130
|
const finalSettings = (0, Settings_1.finalizeSettings)(docSettings);
|
|
128
131
|
const validateOptions = (0, settingsToValidateOptions_1.settingsToValidateOptions)(finalSettings);
|
|
129
132
|
const includeRanges = (0, textValidator_1.calcTextInclusionRanges)(this._document.text, validateOptions);
|
|
@@ -232,6 +235,8 @@ class DocumentValidator {
|
|
|
232
235
|
* @returns the validation issues.
|
|
233
236
|
*/
|
|
234
237
|
checkDocument(forceCheck = false) {
|
|
238
|
+
if (skipValidation)
|
|
239
|
+
return [];
|
|
235
240
|
(0, assert_1.default)(this._ready);
|
|
236
241
|
(0, assert_1.default)(this._preparations, ERROR_NOT_PREPARED);
|
|
237
242
|
const spellingIssues = forceCheck || this.shouldCheckDocument() ? [...this._checkParsedText(this._parse())] : [];
|
|
@@ -375,12 +380,43 @@ async function searchForDocumentConfig(document, defaultConfig, pnpSettings) {
|
|
|
375
380
|
const { uri } = document;
|
|
376
381
|
if (uri.scheme !== 'file')
|
|
377
382
|
return Promise.resolve(defaultConfig);
|
|
378
|
-
return (0, Settings_1.searchForConfig)(
|
|
383
|
+
return (0, Settings_1.searchForConfig)(path_1.default.dirname((0, Uri_1.uriToFilePath)(uri)), pnpSettings).then((s) => s || defaultConfig);
|
|
379
384
|
}
|
|
380
385
|
function searchForDocumentConfigSync(document, defaultConfig, pnpSettings) {
|
|
381
386
|
const { uri } = document;
|
|
382
387
|
if (uri.scheme !== 'file')
|
|
383
388
|
defaultConfig;
|
|
384
|
-
return (0, configLoader_1.searchForConfigSync)(uri
|
|
389
|
+
return (0, configLoader_1.searchForConfigSync)((0, Uri_1.uriToFilePath)(uri), pnpSettings) || defaultConfig;
|
|
390
|
+
}
|
|
391
|
+
async function shouldCheckDocument(doc, options, settings) {
|
|
392
|
+
const errors = [];
|
|
393
|
+
function addPossibleError(error) {
|
|
394
|
+
if (!error)
|
|
395
|
+
return;
|
|
396
|
+
error = errors.push((0, errors_1.toError)(error));
|
|
397
|
+
}
|
|
398
|
+
function catchError(p) {
|
|
399
|
+
return p.catch((error) => {
|
|
400
|
+
addPossibleError(error);
|
|
401
|
+
return undefined;
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
async function shouldCheck() {
|
|
405
|
+
const useSearchForConfig = (!options.noConfigSearch && !settings.noConfigSearch) || options.noConfigSearch === false;
|
|
406
|
+
const pLocalConfig = options.configFile
|
|
407
|
+
? catchError((0, Settings_1.loadConfig)(options.configFile, settings))
|
|
408
|
+
: useSearchForConfig
|
|
409
|
+
? catchError(searchForDocumentConfig(doc, settings, settings))
|
|
410
|
+
: undefined;
|
|
411
|
+
const localConfig = (await pLocalConfig) || {};
|
|
412
|
+
addPossibleError(localConfig?.__importRef?.error);
|
|
413
|
+
const config = (0, Settings_1.mergeSettings)(settings, localConfig);
|
|
414
|
+
const matcher = new cspell_glob_1.GlobMatcher(localConfig?.ignorePaths || [], { root: process.cwd(), dot: true });
|
|
415
|
+
const docSettings = (0, determineTextDocumentSettings_1.determineTextDocumentSettings)(doc, config);
|
|
416
|
+
const uri = doc.uri;
|
|
417
|
+
return !matcher.match((0, Uri_1.uriToFilePath)(uri)) && (docSettings.enabled ?? true);
|
|
418
|
+
}
|
|
419
|
+
return { errors, shouldCheck: await shouldCheck() };
|
|
385
420
|
}
|
|
421
|
+
exports.shouldCheckDocument = shouldCheckDocument;
|
|
386
422
|
//# sourceMappingURL=docValidator.js.map
|
|
@@ -3,7 +3,7 @@ export type { ValidationResult } from '../Models/ValidationResult';
|
|
|
3
3
|
export type { CheckTextInfo, TextInfoItem } from './checkText';
|
|
4
4
|
export { checkText, checkTextDocument, IncludeExcludeFlag } from './checkText';
|
|
5
5
|
export type { DocumentValidatorOptions } from './docValidator';
|
|
6
|
-
export { DocumentValidator } from './docValidator';
|
|
6
|
+
export { DocumentValidator, shouldCheckDocument } from './docValidator';
|
|
7
7
|
export type { Offset, SimpleRange } from './parsedText';
|
|
8
8
|
export { calcTextInclusionRanges } from './textValidator';
|
|
9
9
|
export type { ValidateTextOptions } from './ValidateTextOptions';
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateText = exports.calcTextInclusionRanges = exports.DocumentValidator = exports.IncludeExcludeFlag = exports.checkTextDocument = exports.checkText = void 0;
|
|
3
|
+
exports.validateText = exports.calcTextInclusionRanges = exports.shouldCheckDocument = exports.DocumentValidator = exports.IncludeExcludeFlag = exports.checkTextDocument = exports.checkText = void 0;
|
|
4
4
|
var checkText_1 = require("./checkText");
|
|
5
5
|
Object.defineProperty(exports, "checkText", { enumerable: true, get: function () { return checkText_1.checkText; } });
|
|
6
6
|
Object.defineProperty(exports, "checkTextDocument", { enumerable: true, get: function () { return checkText_1.checkTextDocument; } });
|
|
7
7
|
Object.defineProperty(exports, "IncludeExcludeFlag", { enumerable: true, get: function () { return checkText_1.IncludeExcludeFlag; } });
|
|
8
8
|
var docValidator_1 = require("./docValidator");
|
|
9
9
|
Object.defineProperty(exports, "DocumentValidator", { enumerable: true, get: function () { return docValidator_1.DocumentValidator; } });
|
|
10
|
+
Object.defineProperty(exports, "shouldCheckDocument", { enumerable: true, get: function () { return docValidator_1.shouldCheckDocument; } });
|
|
10
11
|
var textValidator_1 = require("./textValidator");
|
|
11
12
|
Object.defineProperty(exports, "calcTextInclusionRanges", { enumerable: true, get: function () { return textValidator_1.calcTextInclusionRanges; } });
|
|
12
13
|
var validator_1 = require("./validator");
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
interface LLNode<T> {
|
|
2
|
+
value: T;
|
|
3
|
+
n?: LLNode<T> | undefined;
|
|
4
|
+
p?: LLNode<T> | undefined;
|
|
5
|
+
}
|
|
6
|
+
interface LL<T> {
|
|
7
|
+
n?: LLNode<T> | undefined;
|
|
8
|
+
p?: LLNode<T> | undefined;
|
|
9
|
+
}
|
|
10
|
+
export declare class AutoResolveLRUCache<T, V> {
|
|
11
|
+
readonly maxSize: number;
|
|
12
|
+
readonly isEqual: (a: T, b: T) => boolean;
|
|
13
|
+
protected list: LL<{
|
|
14
|
+
p: T;
|
|
15
|
+
r: V;
|
|
16
|
+
}>;
|
|
17
|
+
private count;
|
|
18
|
+
private _misses;
|
|
19
|
+
private _hits;
|
|
20
|
+
private _added;
|
|
21
|
+
private _removed;
|
|
22
|
+
constructor(maxSize: number, isEqual: (a: T, b: T) => boolean);
|
|
23
|
+
get(params: T): V | undefined;
|
|
24
|
+
get(params: T, fn: (p: T) => V): V;
|
|
25
|
+
get(params: T, fn?: (p: T) => V): V | undefined;
|
|
26
|
+
get size(): number;
|
|
27
|
+
get hits(): number;
|
|
28
|
+
get misses(): number;
|
|
29
|
+
get added(): number;
|
|
30
|
+
get removed(): number;
|
|
31
|
+
clear(): void;
|
|
32
|
+
private addToHead;
|
|
33
|
+
stats(): {
|
|
34
|
+
size: number;
|
|
35
|
+
hits: number;
|
|
36
|
+
misses: number;
|
|
37
|
+
added: number;
|
|
38
|
+
removed: number;
|
|
39
|
+
};
|
|
40
|
+
toJSON(): {
|
|
41
|
+
size: number;
|
|
42
|
+
hits: number;
|
|
43
|
+
misses: number;
|
|
44
|
+
added: number;
|
|
45
|
+
removed: number;
|
|
46
|
+
};
|
|
47
|
+
static assertValid<T, V>(cache: AutoResolveLRUCache<T, V>): void;
|
|
48
|
+
}
|
|
49
|
+
export declare function assertValidateLL<T>(list: LL<T>): void;
|
|
50
|
+
export declare class AutoResolveLastNCalls<Params extends unknown[], Result> extends AutoResolveLRUCache<Params, Result> {
|
|
51
|
+
constructor(maxSize: number);
|
|
52
|
+
}
|
|
53
|
+
export {};
|
|
54
|
+
//# sourceMappingURL=AutoResolveLRUCache.d.ts.map
|
|
@@ -0,0 +1,138 @@
|
|
|
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.AutoResolveLastNCalls = exports.assertValidateLL = exports.AutoResolveLRUCache = void 0;
|
|
7
|
+
const assert_1 = __importDefault(require("assert"));
|
|
8
|
+
const util_1 = require("./util");
|
|
9
|
+
class AutoResolveLRUCache {
|
|
10
|
+
constructor(maxSize, isEqual) {
|
|
11
|
+
this.maxSize = maxSize;
|
|
12
|
+
this.isEqual = isEqual;
|
|
13
|
+
this.list = {};
|
|
14
|
+
this.count = 0;
|
|
15
|
+
this._misses = 0;
|
|
16
|
+
this._hits = 0;
|
|
17
|
+
this._added = 0;
|
|
18
|
+
this._removed = 0;
|
|
19
|
+
(0, assert_1.default)(maxSize > 0);
|
|
20
|
+
}
|
|
21
|
+
get(params, fn) {
|
|
22
|
+
const isEqual = this.isEqual;
|
|
23
|
+
for (let n = this.list.n; n; n = n.n) {
|
|
24
|
+
if (isEqual(n.value.p, params)) {
|
|
25
|
+
this.addToHead(n);
|
|
26
|
+
++this._hits;
|
|
27
|
+
return n.value.r;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
++this._misses;
|
|
31
|
+
if (!fn)
|
|
32
|
+
return undefined;
|
|
33
|
+
const value = {
|
|
34
|
+
p: params,
|
|
35
|
+
r: fn(params),
|
|
36
|
+
};
|
|
37
|
+
this.addToHead({ value, n: undefined, p: undefined });
|
|
38
|
+
return value.r;
|
|
39
|
+
}
|
|
40
|
+
get size() {
|
|
41
|
+
return this.count;
|
|
42
|
+
}
|
|
43
|
+
get hits() {
|
|
44
|
+
return this._hits;
|
|
45
|
+
}
|
|
46
|
+
get misses() {
|
|
47
|
+
return this._misses;
|
|
48
|
+
}
|
|
49
|
+
get added() {
|
|
50
|
+
return this._added;
|
|
51
|
+
}
|
|
52
|
+
get removed() {
|
|
53
|
+
return this._removed;
|
|
54
|
+
}
|
|
55
|
+
clear() {
|
|
56
|
+
this._added = 0;
|
|
57
|
+
this._hits = 0;
|
|
58
|
+
this._misses = 0;
|
|
59
|
+
this._removed = 0;
|
|
60
|
+
this.list.n = undefined;
|
|
61
|
+
this.list.p = undefined;
|
|
62
|
+
this.count = 0;
|
|
63
|
+
}
|
|
64
|
+
addToHead(n) {
|
|
65
|
+
if (!this.list.n) {
|
|
66
|
+
this.list.n = n;
|
|
67
|
+
this.list.p = n;
|
|
68
|
+
n.n = undefined;
|
|
69
|
+
n.p = undefined;
|
|
70
|
+
this.count = 1;
|
|
71
|
+
this._added = 1;
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (this.list.n === n)
|
|
75
|
+
return;
|
|
76
|
+
if (this.list.p === n) {
|
|
77
|
+
this.list.p = n.p;
|
|
78
|
+
}
|
|
79
|
+
const isNew = !n.n && !n.p;
|
|
80
|
+
n.p && (n.p.n = n.n);
|
|
81
|
+
n.n && (n.n.p = n.p);
|
|
82
|
+
n.p = undefined;
|
|
83
|
+
n.n = this.list.n;
|
|
84
|
+
n.n && (n.n.p = n);
|
|
85
|
+
this.list.n = n;
|
|
86
|
+
const add = (isNew && 1) || 0;
|
|
87
|
+
this._added += add;
|
|
88
|
+
this.count += add;
|
|
89
|
+
if (this.count > this.maxSize) {
|
|
90
|
+
const prev = this.list.p?.p;
|
|
91
|
+
(0, assert_1.default)(prev);
|
|
92
|
+
prev.n = undefined;
|
|
93
|
+
this.list.p = prev;
|
|
94
|
+
++this._removed;
|
|
95
|
+
--this.count;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
stats() {
|
|
99
|
+
return { size: this.count, hits: this.hits, misses: this.misses, added: this.added, removed: this.removed };
|
|
100
|
+
}
|
|
101
|
+
toJSON() {
|
|
102
|
+
return this.stats();
|
|
103
|
+
}
|
|
104
|
+
static assertValid(cache) {
|
|
105
|
+
assertValidateLL(cache.list);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.AutoResolveLRUCache = AutoResolveLRUCache;
|
|
109
|
+
function assertValidateLL(list) {
|
|
110
|
+
if (!list.n && !list.p)
|
|
111
|
+
return;
|
|
112
|
+
(0, assert_1.default)(list.n, 'Bad Next');
|
|
113
|
+
(0, assert_1.default)(list.p, 'Bad Prev');
|
|
114
|
+
const visited = new Set();
|
|
115
|
+
// validate forwards
|
|
116
|
+
let n = list;
|
|
117
|
+
for (; n.n; n = n.n) {
|
|
118
|
+
(0, assert_1.default)(!visited.has(n.n), 'Circular');
|
|
119
|
+
visited.add(n.n);
|
|
120
|
+
}
|
|
121
|
+
(0, assert_1.default)(list.p === n, 'Tail matches');
|
|
122
|
+
visited.clear();
|
|
123
|
+
// validate backwards
|
|
124
|
+
n = list;
|
|
125
|
+
for (; n.p; n = n.p) {
|
|
126
|
+
(0, assert_1.default)(!visited.has(n.p), 'Circular');
|
|
127
|
+
visited.add(n.p);
|
|
128
|
+
}
|
|
129
|
+
(0, assert_1.default)(list.n === n, 'Head matches');
|
|
130
|
+
}
|
|
131
|
+
exports.assertValidateLL = assertValidateLL;
|
|
132
|
+
class AutoResolveLastNCalls extends AutoResolveLRUCache {
|
|
133
|
+
constructor(maxSize) {
|
|
134
|
+
super(maxSize, util_1.isArrayEqual);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
exports.AutoResolveLastNCalls = AutoResolveLastNCalls;
|
|
138
|
+
//# sourceMappingURL=AutoResolveLRUCache.js.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export interface Uri {
|
|
3
|
+
readonly scheme: string;
|
|
4
|
+
readonly path: string;
|
|
5
|
+
readonly authority?: string;
|
|
6
|
+
readonly fragment?: string;
|
|
7
|
+
readonly query?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface UriInstance extends Uri {
|
|
10
|
+
toString(): string;
|
|
11
|
+
}
|
|
12
|
+
export declare function toUri(uriOrFile: string | Uri | URL): UriInstance;
|
|
13
|
+
export declare function uriToFilePath(uri: Uri): string;
|
|
14
|
+
export declare function fromFilePath(file: string): UriInstance;
|
|
15
|
+
export declare function fromStdinFilePath(path?: string): UriInstance;
|
|
16
|
+
export declare const file: typeof fromFilePath;
|
|
17
|
+
export declare function parse(uri: string): UriInstance;
|
|
18
|
+
export declare function normalizeDriveLetter(path: string): string;
|
|
19
|
+
export declare function isUri(uri: unknown): uri is UriInstance;
|
|
20
|
+
export declare function basename(uri: Uri): string;
|
|
21
|
+
export declare function dirname(uri: Uri): UriInstance;
|
|
22
|
+
export declare function extname(uri: Uri): string;
|
|
23
|
+
export declare function joinPath(uri: Uri, ...paths: string[]): UriInstance;
|
|
24
|
+
export declare function resolvePath(uri: Uri, ...paths: string[]): UriInstance;
|
|
25
|
+
export declare function from(uri: Uri, ...parts: Partial<Uri>[]): UriInstance;
|
|
26
|
+
declare class UriImpl implements UriInstance {
|
|
27
|
+
readonly scheme: string;
|
|
28
|
+
readonly authority?: string;
|
|
29
|
+
readonly path: string;
|
|
30
|
+
readonly query?: string;
|
|
31
|
+
readonly fragment?: string;
|
|
32
|
+
constructor(uri: PartialWithUndefined<Uri>);
|
|
33
|
+
toString(): string;
|
|
34
|
+
toJson(): PartialWithUndefined<Uri>;
|
|
35
|
+
with(change: Partial<Uri>): UriImpl;
|
|
36
|
+
static isUri(uri: unknown): uri is UriImpl;
|
|
37
|
+
static from(uri: Uri, ...parts: Partial<Uri>[]): UriImpl;
|
|
38
|
+
static parse(uri: string): UriImpl;
|
|
39
|
+
static file(filename: string): UriImpl;
|
|
40
|
+
static stdin(filePath?: string): UriImpl;
|
|
41
|
+
}
|
|
42
|
+
declare function normalizeFilePath(path: string): string;
|
|
43
|
+
type PartialWithUndefined<T> = {
|
|
44
|
+
[P in keyof T]?: T[P] | undefined;
|
|
45
|
+
};
|
|
46
|
+
export declare const __testing__: {
|
|
47
|
+
UriImpl: typeof UriImpl;
|
|
48
|
+
normalizeFilePath: typeof normalizeFilePath;
|
|
49
|
+
};
|
|
50
|
+
export {};
|
|
51
|
+
//# sourceMappingURL=Uri.d.ts.map
|
package/dist/util/Uri.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
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.__testing__ = exports.from = exports.resolvePath = exports.joinPath = exports.extname = exports.dirname = exports.basename = exports.isUri = exports.normalizeDriveLetter = exports.parse = exports.file = exports.fromStdinFilePath = exports.fromFilePath = exports.uriToFilePath = exports.toUri = void 0;
|
|
7
|
+
const assert_1 = __importDefault(require("assert"));
|
|
8
|
+
const vscode_uri_1 = require("vscode-uri");
|
|
9
|
+
const isFile = /^(?:[a-zA-Z]:|[/\\])/;
|
|
10
|
+
const isPossibleUri = /\w:\/\//;
|
|
11
|
+
const isUrl = /^(file:|stdin:|https?:|s?ftp:)/;
|
|
12
|
+
const STDIN_PROTOCOL = 'stdin:';
|
|
13
|
+
function toUri(uriOrFile) {
|
|
14
|
+
if (UriImpl.isUri(uriOrFile))
|
|
15
|
+
return uriOrFile;
|
|
16
|
+
if (vscode_uri_1.URI.isUri(uriOrFile))
|
|
17
|
+
return UriImpl.from(uriOrFile);
|
|
18
|
+
if (uriOrFile instanceof URL)
|
|
19
|
+
return UriImpl.parse(uriOrFile.toString());
|
|
20
|
+
if (isUrlLike(uriOrFile))
|
|
21
|
+
return UriImpl.parse(uriOrFile.href);
|
|
22
|
+
if (isUri(uriOrFile))
|
|
23
|
+
return UriImpl.from(uriOrFile);
|
|
24
|
+
if (isUrl.test(uriOrFile))
|
|
25
|
+
return UriImpl.parse(uriOrFile);
|
|
26
|
+
return isFile.test(uriOrFile) && !isPossibleUri.test(uriOrFile)
|
|
27
|
+
? UriImpl.file(normalizeDriveLetter(uriOrFile))
|
|
28
|
+
: UriImpl.parse(uriOrFile);
|
|
29
|
+
}
|
|
30
|
+
exports.toUri = toUri;
|
|
31
|
+
const hasDriveLetter = /^[A-Z]:/i;
|
|
32
|
+
function uriToFilePath(uri) {
|
|
33
|
+
const adj = uri.scheme === 'stdin' ? { scheme: 'file' } : {};
|
|
34
|
+
return normalizeDriveLetter(vscode_uri_1.URI.from(UriImpl.from(uri, adj)).fsPath);
|
|
35
|
+
}
|
|
36
|
+
exports.uriToFilePath = uriToFilePath;
|
|
37
|
+
function fromFilePath(file) {
|
|
38
|
+
return UriImpl.file(file);
|
|
39
|
+
}
|
|
40
|
+
exports.fromFilePath = fromFilePath;
|
|
41
|
+
function fromStdinFilePath(path) {
|
|
42
|
+
return UriImpl.stdin(path);
|
|
43
|
+
}
|
|
44
|
+
exports.fromStdinFilePath = fromStdinFilePath;
|
|
45
|
+
exports.file = fromFilePath;
|
|
46
|
+
function parse(uri) {
|
|
47
|
+
return UriImpl.parse(uri);
|
|
48
|
+
}
|
|
49
|
+
exports.parse = parse;
|
|
50
|
+
function normalizeDriveLetter(path) {
|
|
51
|
+
return hasDriveLetter.test(path) ? path[0].toLowerCase() + path.slice(1) : path;
|
|
52
|
+
}
|
|
53
|
+
exports.normalizeDriveLetter = normalizeDriveLetter;
|
|
54
|
+
function isUrlLike(url) {
|
|
55
|
+
return (!!url && typeof url === 'object' && typeof url.href === 'string') || false;
|
|
56
|
+
}
|
|
57
|
+
function isUri(uri) {
|
|
58
|
+
if (!uri || typeof uri !== 'object')
|
|
59
|
+
return false;
|
|
60
|
+
if (UriImpl.isUri(uri))
|
|
61
|
+
return true;
|
|
62
|
+
if (vscode_uri_1.URI.isUri(uri))
|
|
63
|
+
return true;
|
|
64
|
+
const u = uri;
|
|
65
|
+
return typeof u.path === 'string' && typeof u.scheme === 'string';
|
|
66
|
+
}
|
|
67
|
+
exports.isUri = isUri;
|
|
68
|
+
function basename(uri) {
|
|
69
|
+
return vscode_uri_1.Utils.basename(vscode_uri_1.URI.from(uri));
|
|
70
|
+
}
|
|
71
|
+
exports.basename = basename;
|
|
72
|
+
function dirname(uri) {
|
|
73
|
+
return UriImpl.from(vscode_uri_1.Utils.dirname(vscode_uri_1.URI.from(uri)));
|
|
74
|
+
}
|
|
75
|
+
exports.dirname = dirname;
|
|
76
|
+
function extname(uri) {
|
|
77
|
+
return vscode_uri_1.Utils.extname(vscode_uri_1.URI.from(uri));
|
|
78
|
+
}
|
|
79
|
+
exports.extname = extname;
|
|
80
|
+
function joinPath(uri, ...paths) {
|
|
81
|
+
return UriImpl.from(vscode_uri_1.Utils.joinPath(vscode_uri_1.URI.from(uri), ...paths));
|
|
82
|
+
}
|
|
83
|
+
exports.joinPath = joinPath;
|
|
84
|
+
function resolvePath(uri, ...paths) {
|
|
85
|
+
return UriImpl.from(vscode_uri_1.Utils.resolvePath(vscode_uri_1.URI.from(uri), ...paths));
|
|
86
|
+
}
|
|
87
|
+
exports.resolvePath = resolvePath;
|
|
88
|
+
function from(uri, ...parts) {
|
|
89
|
+
return UriImpl.from(uri, ...parts);
|
|
90
|
+
}
|
|
91
|
+
exports.from = from;
|
|
92
|
+
const keys = ['scheme', 'authority', 'path', 'query', 'fragment'];
|
|
93
|
+
class UriImpl {
|
|
94
|
+
constructor(uri) {
|
|
95
|
+
this.scheme = uri.scheme || '';
|
|
96
|
+
uri.authority && (this.authority = uri.authority);
|
|
97
|
+
this.path = uri.path || '';
|
|
98
|
+
uri.query && (this.query = uri.query);
|
|
99
|
+
uri.fragment && (this.fragment = uri.fragment);
|
|
100
|
+
}
|
|
101
|
+
toString() {
|
|
102
|
+
const path = this.path;
|
|
103
|
+
const base = `${this.scheme}://${this.authority || ''}${path}`;
|
|
104
|
+
const query = (this.query && `?${this.query}`) || '';
|
|
105
|
+
const fragment = (this.fragment && `#${this.fragment}`) || '';
|
|
106
|
+
const url = base + query + fragment;
|
|
107
|
+
return encodeURI(url);
|
|
108
|
+
}
|
|
109
|
+
toJson() {
|
|
110
|
+
const { scheme, authority, path, query, fragment } = this;
|
|
111
|
+
return { scheme, authority, path, query, fragment };
|
|
112
|
+
}
|
|
113
|
+
with(change) {
|
|
114
|
+
const { scheme, authority, path, query, fragment } = this;
|
|
115
|
+
const u = { scheme, authority, path, query, fragment };
|
|
116
|
+
for (const key of keys) {
|
|
117
|
+
if (change[key] && typeof change[key] === 'string') {
|
|
118
|
+
u[key] = change[key];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return new UriImpl(u);
|
|
122
|
+
}
|
|
123
|
+
static isUri(uri) {
|
|
124
|
+
return uri instanceof UriImpl;
|
|
125
|
+
}
|
|
126
|
+
static from(uri, ...parts) {
|
|
127
|
+
let u = new UriImpl(uri);
|
|
128
|
+
for (const part of parts) {
|
|
129
|
+
u = u.with(part);
|
|
130
|
+
}
|
|
131
|
+
return u;
|
|
132
|
+
}
|
|
133
|
+
static parse(uri) {
|
|
134
|
+
if (uri.startsWith(STDIN_PROTOCOL)) {
|
|
135
|
+
return UriImpl.from(parseStdinUri(uri));
|
|
136
|
+
}
|
|
137
|
+
const u = vscode_uri_1.URI.parse(uri);
|
|
138
|
+
return UriImpl.from(u);
|
|
139
|
+
}
|
|
140
|
+
static file(filename) {
|
|
141
|
+
return UriImpl.from(vscode_uri_1.URI.file(normalizeFilePath(filename)));
|
|
142
|
+
}
|
|
143
|
+
static stdin(filePath = '') {
|
|
144
|
+
return UriImpl.from(UriImpl.file(filePath), { scheme: 'stdin' });
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function normalizeFilePath(path) {
|
|
148
|
+
return normalizeDriveLetter(path.replace(/\\/g, '/'));
|
|
149
|
+
}
|
|
150
|
+
function parseStdinUri(uri) {
|
|
151
|
+
(0, assert_1.default)(uri.startsWith(STDIN_PROTOCOL));
|
|
152
|
+
const idxSlash = STDIN_PROTOCOL.length;
|
|
153
|
+
let idxSlashEnd = idxSlash;
|
|
154
|
+
for (; uri[idxSlashEnd] === '/'; ++idxSlashEnd) {
|
|
155
|
+
// empty
|
|
156
|
+
}
|
|
157
|
+
const pathStart = idxSlashEnd;
|
|
158
|
+
const iH = uri.indexOf('#', pathStart);
|
|
159
|
+
const idxHash = iH > 0 ? iH : uri.length;
|
|
160
|
+
const iQ = uri.indexOf('?', pathStart);
|
|
161
|
+
const idxQ = iQ > 0 && iQ < idxHash ? iQ : idxHash;
|
|
162
|
+
const pathEnd = idxQ;
|
|
163
|
+
const path = uri.slice(pathStart, pathEnd);
|
|
164
|
+
const query = idxQ < idxHash ? uri.slice(idxQ + 1, idxHash) : '';
|
|
165
|
+
const hash = uri.slice(idxHash + 1);
|
|
166
|
+
const pathPrefix = idxSlashEnd - idxSlash > 2 ? '/' : '';
|
|
167
|
+
return {
|
|
168
|
+
scheme: 'stdin',
|
|
169
|
+
path: pathPrefix + normalizeFilePath(decodeURI(path)),
|
|
170
|
+
query: decodeURI(query),
|
|
171
|
+
fragment: decodeURI(hash),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
exports.__testing__ = {
|
|
175
|
+
UriImpl,
|
|
176
|
+
normalizeFilePath,
|
|
177
|
+
};
|
|
178
|
+
//# sourceMappingURL=Uri.js.map
|
package/dist/util/text.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import type { TextDocumentOffset, TextOffset } from '@cspell/cspell-types';
|
|
3
|
+
import type { Uri } from './Uri';
|
|
2
4
|
export { stringToRegExp } from './textRegex';
|
|
3
5
|
export declare function splitCamelCaseWordWithOffset(wo: TextOffset): Array<TextOffset>;
|
|
4
6
|
/**
|
|
@@ -39,7 +41,7 @@ export declare function camelToSnake(word: string): string;
|
|
|
39
41
|
export declare function matchCase(example: string, word: string): string;
|
|
40
42
|
export declare function textOffset(text: string, offset?: number): TextOffset;
|
|
41
43
|
export declare function extractText(textOffset: TextOffset, startPos: number, endPos: number): string;
|
|
42
|
-
export declare function calculateTextDocumentOffsets<T extends TextOffset>(uri: string, doc: string, wordOffsets: T[]): (TextDocumentOffset & T)[];
|
|
44
|
+
export declare function calculateTextDocumentOffsets<T extends TextOffset>(uri: string | Uri | URL, doc: string, wordOffsets: T[]): (TextDocumentOffset & T)[];
|
|
43
45
|
export declare function removeAccents(text: string): string;
|
|
44
46
|
export declare const __testing__: {
|
|
45
47
|
regExWords: RegExp;
|
package/dist/util/text.js
CHANGED
|
@@ -5,6 +5,7 @@ const sync_1 = require("@cspell/cspell-pipe/sync");
|
|
|
5
5
|
const gensequence_1 = require("gensequence");
|
|
6
6
|
const search_1 = require("./search");
|
|
7
7
|
const textRegex_1 = require("./textRegex");
|
|
8
|
+
const Uri_1 = require("./Uri");
|
|
8
9
|
const util_1 = require("./util");
|
|
9
10
|
var textRegex_2 = require("./textRegex");
|
|
10
11
|
Object.defineProperty(exports, "stringToRegExp", { enumerable: true, get: function () { return textRegex_2.stringToRegExp; } });
|
|
@@ -186,9 +187,10 @@ function calculateTextDocumentOffsets(uri, doc, wordOffsets) {
|
|
|
186
187
|
lastLine = r;
|
|
187
188
|
return r;
|
|
188
189
|
}
|
|
190
|
+
const _uri = (0, Uri_1.toUri)(uri).toString();
|
|
189
191
|
return wordOffsets.map((wo) => {
|
|
190
192
|
const [row, col] = findRowCol(wo.offset);
|
|
191
|
-
return { ...wo, row, col, doc, uri, line: calcLine(row) };
|
|
193
|
+
return { ...wo, row, col, doc, uri: _uri, line: calcLine(row) };
|
|
192
194
|
});
|
|
193
195
|
}
|
|
194
196
|
exports.calculateTextDocumentOffsets = calculateTextDocumentOffsets;
|
package/dist/util/util.d.ts
CHANGED
|
@@ -14,8 +14,6 @@ export declare function clean<T extends object>(src: T): RemoveUndefined<T>;
|
|
|
14
14
|
export declare function scanMap<T>(accFn: (acc: T, value: T) => T, init?: T): (value: T) => T;
|
|
15
15
|
export declare function scanMap<T, U>(accFn: (acc: U, value: T) => U, init: U): (value: T) => U;
|
|
16
16
|
export declare function isDefined<T>(v: T | undefined): v is T;
|
|
17
|
-
export declare function flattenIterable<T>(values: Iterable<Iterable<T>> | T[][]): Iterable<T>;
|
|
18
|
-
export declare function flatten<T>(values: Iterable<Iterable<T>> | T[][]): T[];
|
|
19
17
|
export declare function asyncIterableToArray<T>(iter: Iterable<T> | AsyncIterable<T>): Promise<Awaited<T>[]>;
|
|
20
18
|
/**
|
|
21
19
|
* Shallow is Equal test.
|
|
@@ -31,4 +29,5 @@ export declare function isArrayEqual<K>(a: K[], b: K[]): boolean;
|
|
|
31
29
|
* @returns true iff any element of `a` is in `b`
|
|
32
30
|
*/
|
|
33
31
|
export declare function doSetsIntersect<T>(a: Set<T>, b: Set<T>): boolean;
|
|
32
|
+
export declare function isRecordEqual<T extends Record<string, unknown>>(a: T | undefined, b: T | undefined): boolean;
|
|
34
33
|
//# sourceMappingURL=util.d.ts.map
|
package/dist/util/util.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.isRecordEqual = exports.doSetsIntersect = exports.isArrayEqual = exports.asyncIterableToArray = exports.isDefined = exports.scanMap = exports.clean = exports.unique = exports.uniqueFilterFnGenerator = exports.uniqueFn = void 0;
|
|
4
4
|
// alias for uniqueFilterFnGenerator
|
|
5
5
|
exports.uniqueFn = uniqueFilterFnGenerator;
|
|
6
6
|
function uniqueFilterFnGenerator(extractFn) {
|
|
@@ -50,16 +50,6 @@ function isDefined(v) {
|
|
|
50
50
|
return v !== undefined;
|
|
51
51
|
}
|
|
52
52
|
exports.isDefined = isDefined;
|
|
53
|
-
function* flattenIterable(values) {
|
|
54
|
-
for (const v of values) {
|
|
55
|
-
yield* v;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
exports.flattenIterable = flattenIterable;
|
|
59
|
-
function flatten(values) {
|
|
60
|
-
return [...flattenIterable(values)];
|
|
61
|
-
}
|
|
62
|
-
exports.flatten = flatten;
|
|
63
53
|
async function asyncIterableToArray(iter) {
|
|
64
54
|
const acc = [];
|
|
65
55
|
for await (const t of iter) {
|
|
@@ -101,4 +91,20 @@ function doSetsIntersect(a, b) {
|
|
|
101
91
|
return a.size <= b.size ? compare(a, b) : compare(b, a);
|
|
102
92
|
}
|
|
103
93
|
exports.doSetsIntersect = doSetsIntersect;
|
|
94
|
+
function isRecordEqual(a, b) {
|
|
95
|
+
if (a === b)
|
|
96
|
+
return true;
|
|
97
|
+
if (a === undefined || b === undefined)
|
|
98
|
+
return false;
|
|
99
|
+
for (const key of Object.keys(a)) {
|
|
100
|
+
if (a[key] !== b[key])
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
for (const key of Object.keys(b)) {
|
|
104
|
+
if (a[key] !== b[key])
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
exports.isRecordEqual = isRecordEqual;
|
|
104
110
|
//# sourceMappingURL=util.js.map
|