cspell-lib 8.11.0 → 8.13.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/esm/Models/Suggestion.d.ts +5 -0
- package/dist/esm/Models/TextDocument.d.ts +2 -1
- package/dist/esm/Models/TextDocument.js +6 -2
- package/dist/esm/Settings/RegExpPatterns.js +1 -1
- package/dist/esm/textValidation/docValidator.js +13 -9
- package/dist/esm/util/Uri.d.ts +5 -3
- package/dist/esm/util/Uri.js +17 -11
- package/dist/esm/util/text.js +4 -2
- package/dist/esm/util/url.js +2 -1
- package/package.json +17 -17
|
@@ -11,5 +11,10 @@ export interface ExtendedSuggestion {
|
|
|
11
11
|
* The suggested word adjusted to match the original case.
|
|
12
12
|
*/
|
|
13
13
|
wordAdjustedToMatchCase?: string;
|
|
14
|
+
/**
|
|
15
|
+
* The cost of using this word.
|
|
16
|
+
* The lower the cost, the better the suggestion.
|
|
17
|
+
*/
|
|
18
|
+
cost?: number;
|
|
14
19
|
}
|
|
15
20
|
//# sourceMappingURL=Suggestion.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as Uri from '../util/Uri.js';
|
|
2
|
-
export type DocumentUri = Uri.Uri;
|
|
2
|
+
export type DocumentUri = Uri.Uri | URL | string;
|
|
3
3
|
export interface Position {
|
|
4
4
|
line: number;
|
|
5
5
|
character: number;
|
|
@@ -82,4 +82,5 @@ export declare function createTextDocument({ uri, content, languageId, locale, v
|
|
|
82
82
|
export declare function updateTextDocument(doc: TextDocument, edits: TextDocumentContentChangeEvent[], version?: number): TextDocument;
|
|
83
83
|
export declare function loadTextDocument(filename: string | DocumentUri, languageId?: string): Promise<TextDocument>;
|
|
84
84
|
export declare const isTextDocument: (doc: TextDocument | unknown) => doc is TextDocument;
|
|
85
|
+
export declare function documentUriToURL(uri: DocumentUri): URL;
|
|
85
86
|
//# sourceMappingURL=TextDocument.d.ts.map
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import assert from 'node:assert';
|
|
2
|
+
import { toFileURL, toURL } from '@cspell/url';
|
|
2
3
|
import { TextDocument as VsTextDocument } from 'vscode-languageserver-textdocument';
|
|
3
4
|
import { getFileSystem } from '../fileSystem.js';
|
|
4
5
|
import { getLanguagesForBasename } from '../LanguageIds.js';
|
|
5
6
|
import * as Uri from '../util/Uri.js';
|
|
6
7
|
class TextDocumentImpl {
|
|
7
|
-
uri;
|
|
8
8
|
languageId;
|
|
9
9
|
locale;
|
|
10
10
|
vsTextDoc;
|
|
11
|
+
uri;
|
|
11
12
|
constructor(uri, text, languageId, locale, version) {
|
|
12
|
-
this.uri = uri;
|
|
13
13
|
this.languageId = languageId;
|
|
14
14
|
this.locale = locale;
|
|
15
15
|
const primaryLanguageId = typeof languageId === 'string' ? languageId : languageId[0] || 'plaintext';
|
|
16
16
|
this.vsTextDoc = VsTextDocument.create(uri.toString(), primaryLanguageId, version, text);
|
|
17
|
+
this.uri = documentUriToURL(uri);
|
|
17
18
|
}
|
|
18
19
|
get version() {
|
|
19
20
|
return this.vsTextDoc.version;
|
|
@@ -108,4 +109,7 @@ export async function loadTextDocument(filename, languageId) {
|
|
|
108
109
|
return createTextDocument({ uri, languageId, content: file.getText() });
|
|
109
110
|
}
|
|
110
111
|
export const isTextDocument = isTextDocumentImpl;
|
|
112
|
+
export function documentUriToURL(uri) {
|
|
113
|
+
return toURL(uri instanceof URL ? uri : typeof uri === 'string' ? toFileURL(uri) : new URL(Uri.from(uri).toString()));
|
|
114
|
+
}
|
|
111
115
|
//# sourceMappingURL=TextDocument.js.map
|
|
@@ -5,7 +5,7 @@ export const regExHRef = /\bhref\s*=\s*".*?"/gi;
|
|
|
5
5
|
export const regExMatchCommonHexFormats = /(?:#[0-9a-f]{3,8})|(?:0x[0-9a-f]+)|(?:\\u[0-9a-f]{4})|(?:\\x\{[0-9a-f]{4}\})/gi;
|
|
6
6
|
export const regExCommitHash = /\b(?![a-f]+\b)(?:0x)?[0-9a-f]{7,}\b/gi; // Match Commit Hashes that contain at least one digit.
|
|
7
7
|
export const regExCommitHashLink = /\[[0-9a-f]{7,}\]/gi; // Match Commit Hash Markdown link: [abcdef0].
|
|
8
|
-
export const regExCStyleHexValue = /\b0x[0-9a-
|
|
8
|
+
export const regExCStyleHexValue = /\b0x[0-9a-f_]+\b/gi;
|
|
9
9
|
export const regExCSSHexValue = /#[0-9a-f]{3,8}\b/gi;
|
|
10
10
|
export const regExUUID = /\b[0-9a-fx]{8}-[0-9a-fx]{4}-[0-9a-fx]{4}-[0-9a-fx]{4}-[0-9a-fx]{12}\b/gi; // x - represents placeholder values
|
|
11
11
|
export const regExUnicodeRef = /\bU\+[0-9a-f]{4,5}(?:-[0-9a-f]{4,5})?/gi;
|
|
@@ -2,9 +2,9 @@ import assert from 'node:assert';
|
|
|
2
2
|
import { pathToFileURL } from 'node:url';
|
|
3
3
|
import { opConcatMap, opMap, pipeSync } from '@cspell/cspell-pipe/sync';
|
|
4
4
|
import { IssueType } from '@cspell/cspell-types';
|
|
5
|
-
import { toFileURL } from '@cspell/url';
|
|
5
|
+
import { toFilePathOrHref, toFileURL } from '@cspell/url';
|
|
6
6
|
import { getGlobMatcherForExcluding } from '../globs/getGlobMatcher.js';
|
|
7
|
-
import { updateTextDocument } from '../Models/TextDocument.js';
|
|
7
|
+
import { documentUriToURL, updateTextDocument } from '../Models/TextDocument.js';
|
|
8
8
|
import { createPerfTimer } from '../perf/index.js';
|
|
9
9
|
import { finalizeSettings, loadConfig, mergeSettings, resolveSettingsImports, searchForConfig, } from '../Settings/index.js';
|
|
10
10
|
import { validateInDocumentSettings } from '../Settings/InDocSettings.js';
|
|
@@ -292,7 +292,7 @@ export class DocumentValidator {
|
|
|
292
292
|
const parser = this._preparations.finalSettings.parserFn;
|
|
293
293
|
if (typeof parser !== 'object')
|
|
294
294
|
return this.defaultParser();
|
|
295
|
-
return parser.parse(this.document.text, this.document.uri
|
|
295
|
+
return parser.parse(this.document.text, toFilePathOrHref(documentUriToURL(this.document.uri))).parsedTexts;
|
|
296
296
|
}
|
|
297
297
|
getSuggestions(text) {
|
|
298
298
|
return this._suggestions.get(text);
|
|
@@ -355,10 +355,15 @@ function sanitizeSuggestion(sug) {
|
|
|
355
355
|
return { word };
|
|
356
356
|
}
|
|
357
357
|
async function searchForDocumentConfig(document, defaultConfig, pnpSettings) {
|
|
358
|
-
const
|
|
359
|
-
|
|
360
|
-
return defaultConfig;
|
|
361
|
-
|
|
358
|
+
const url = documentUriToURL(document.uri);
|
|
359
|
+
try {
|
|
360
|
+
return await searchForConfig(url, pnpSettings).then((s) => s || defaultConfig);
|
|
361
|
+
}
|
|
362
|
+
catch (e) {
|
|
363
|
+
if (url.protocol !== 'file:')
|
|
364
|
+
return defaultConfig;
|
|
365
|
+
throw e;
|
|
366
|
+
}
|
|
362
367
|
}
|
|
363
368
|
function mapSug(sug) {
|
|
364
369
|
return { cost: 999, ...sug };
|
|
@@ -383,9 +388,8 @@ export async function shouldCheckDocument(doc, options, settings) {
|
|
|
383
388
|
const config = mergeSettings(settings, localConfig);
|
|
384
389
|
const matcher = getGlobMatcherForExcluding(localConfig?.ignorePaths);
|
|
385
390
|
const docSettings = await determineTextDocumentSettings(doc, config);
|
|
386
|
-
const uri = doc.uri;
|
|
387
391
|
// eslint-disable-next-line unicorn/prefer-regexp-test
|
|
388
|
-
return !matcher.match(uriToFilePath(uri)) && (docSettings.enabled ?? true);
|
|
392
|
+
return !matcher.match(uriToFilePath(doc.uri)) && (docSettings.enabled ?? true);
|
|
389
393
|
}
|
|
390
394
|
return { errors, shouldCheck: await shouldCheck() };
|
|
391
395
|
}
|
package/dist/esm/util/Uri.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { URI } from 'vscode-uri';
|
|
2
|
+
import { DocumentUri } from '../Models/TextDocument.js';
|
|
2
3
|
export interface Uri {
|
|
3
4
|
readonly scheme: string;
|
|
4
5
|
readonly path: string;
|
|
@@ -8,15 +9,16 @@ export interface Uri {
|
|
|
8
9
|
}
|
|
9
10
|
export interface UriInstance extends Uri {
|
|
10
11
|
toString(): string;
|
|
12
|
+
toJSON(): unknown;
|
|
11
13
|
}
|
|
12
14
|
export declare function toUri(uriOrFile: string | Uri | URL): UriInstance;
|
|
13
|
-
export declare function uriToFilePath(uri:
|
|
15
|
+
export declare function uriToFilePath(uri: DocumentUri): string;
|
|
14
16
|
export declare function fromFilePath(file: string): UriInstance;
|
|
15
17
|
export declare function fromStdinFilePath(path?: string): UriInstance;
|
|
16
18
|
export declare const file: typeof fromFilePath;
|
|
17
19
|
export declare function parse(uri: string): UriInstance;
|
|
18
20
|
export declare function normalizeDriveLetter(path: string): string;
|
|
19
|
-
export declare function isUri(uri: unknown): uri is
|
|
21
|
+
export declare function isUri(uri: unknown): uri is Uri;
|
|
20
22
|
export declare function basename(uri: Uri): string;
|
|
21
23
|
export declare function dirname(uri: Uri): UriInstance;
|
|
22
24
|
export declare function extname(uri: Uri): string;
|
|
@@ -26,7 +28,7 @@ export declare function from(uri: Uri, ...parts: Partial<Uri>[]): UriInstance;
|
|
|
26
28
|
declare class UriImpl extends URI implements UriInstance {
|
|
27
29
|
constructor(uri: Uri);
|
|
28
30
|
toString(): string;
|
|
29
|
-
|
|
31
|
+
toJSON(): {
|
|
30
32
|
scheme: string;
|
|
31
33
|
authority: string;
|
|
32
34
|
path: string;
|
package/dist/esm/util/Uri.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import assert from 'node:assert';
|
|
2
|
+
import { pathToFileURL } from 'node:url';
|
|
3
|
+
import { toFilePathOrHref, toFileURL } from '@cspell/url';
|
|
2
4
|
import { isUrlLike } from 'cspell-io';
|
|
3
5
|
import { URI, Utils } from 'vscode-uri';
|
|
4
|
-
|
|
5
|
-
const isPossibleUri = /\w:\/\//;
|
|
6
|
+
import { documentUriToURL } from '../Models/TextDocument.js';
|
|
6
7
|
const STDIN_PROTOCOL = 'stdin:';
|
|
7
8
|
export function toUri(uriOrFile) {
|
|
8
9
|
if (UriImpl.isUri(uriOrFile))
|
|
@@ -17,14 +18,15 @@ export function toUri(uriOrFile) {
|
|
|
17
18
|
return UriImpl.from(uriOrFile);
|
|
18
19
|
if (isUrlLike(uriOrFile))
|
|
19
20
|
return UriImpl.parse(uriOrFile);
|
|
20
|
-
return
|
|
21
|
-
? UriImpl.file(normalizeDriveLetter(uriOrFile))
|
|
22
|
-
: UriImpl.parse(uriOrFile);
|
|
21
|
+
return UriImpl.file(normalizeDriveLetter(uriOrFile));
|
|
23
22
|
}
|
|
24
|
-
const
|
|
23
|
+
const isWindows = process.platform === 'win32';
|
|
24
|
+
const hasDriveLetter = /^[a-zA-Z]:[\\/]/;
|
|
25
|
+
const rootUrl = pathToFileURL('/');
|
|
25
26
|
export function uriToFilePath(uri) {
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
let url = documentUriToURL(uri);
|
|
28
|
+
url = url.protocol === 'stdin:' ? new URL(url.pathname, rootUrl) : url;
|
|
29
|
+
return toFilePathOrHref(url);
|
|
28
30
|
}
|
|
29
31
|
export function fromFilePath(file) {
|
|
30
32
|
return UriImpl.file(file);
|
|
@@ -37,7 +39,7 @@ export function parse(uri) {
|
|
|
37
39
|
return UriImpl.parse(uri);
|
|
38
40
|
}
|
|
39
41
|
export function normalizeDriveLetter(path) {
|
|
40
|
-
return hasDriveLetter.test(path) ? path[0].
|
|
42
|
+
return hasDriveLetter.test(path) ? path[0].toUpperCase() + path.slice(1) : path;
|
|
41
43
|
}
|
|
42
44
|
function isHRef(url) {
|
|
43
45
|
return (!!url && typeof url === 'object' && typeof url.href === 'string') || false;
|
|
@@ -84,7 +86,7 @@ class UriImpl extends URI {
|
|
|
84
86
|
const url = base + query + fragment;
|
|
85
87
|
return url;
|
|
86
88
|
}
|
|
87
|
-
|
|
89
|
+
toJSON() {
|
|
88
90
|
const { scheme, authority, path, query, fragment } = this;
|
|
89
91
|
return { scheme, authority, path, query, fragment };
|
|
90
92
|
}
|
|
@@ -116,7 +118,11 @@ class UriImpl extends URI {
|
|
|
116
118
|
return UriImpl.from(u);
|
|
117
119
|
}
|
|
118
120
|
static file(filename) {
|
|
119
|
-
|
|
121
|
+
if (!isWindows && hasDriveLetter.test(filename)) {
|
|
122
|
+
filename = '/' + filename.replaceAll('\\', '/');
|
|
123
|
+
}
|
|
124
|
+
const url = toFileURL(filename);
|
|
125
|
+
return UriImpl.parse(url.href);
|
|
120
126
|
}
|
|
121
127
|
static stdin(filePath = '') {
|
|
122
128
|
return UriImpl.from(UriImpl.file(filePath), { scheme: 'stdin' });
|
package/dist/esm/util/text.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { opConcatMap, opMap, pipe } from '@cspell/cspell-pipe/sync';
|
|
2
|
-
import { sequenceFromRegExpMatch } from 'gensequence';
|
|
3
2
|
import { binarySearch } from './search.js';
|
|
4
3
|
import { regExAccents, regExAllLower, regExAllUpper, regExFirstUpper, regExIgnoreCharacters, regExSplitWords, regExSplitWords2, regExUpperSOrIng, regExWords, regExWordsAndDigits, } from './textRegex.js';
|
|
5
4
|
import { toUri } from './Uri.js';
|
|
@@ -26,7 +25,10 @@ export function splitCamelCaseWord(word) {
|
|
|
26
25
|
* This function lets you iterate over regular expression matches.
|
|
27
26
|
*/
|
|
28
27
|
export function match(reg, text) {
|
|
29
|
-
|
|
28
|
+
if (!text)
|
|
29
|
+
return [];
|
|
30
|
+
reg = reg.global ? reg : new RegExp(reg.source, reg.flags + 'g');
|
|
31
|
+
return text.matchAll(reg);
|
|
30
32
|
}
|
|
31
33
|
export function matchStringToTextOffset(reg, text) {
|
|
32
34
|
return matchToTextOffset(reg, { text, offset: 0 });
|
package/dist/esm/util/url.js
CHANGED
|
@@ -28,7 +28,8 @@ export function toFileUrl(file) {
|
|
|
28
28
|
export function fileURLOrPathToPath(filenameOrURL) {
|
|
29
29
|
return toFilePathOrHref(filenameOrURL);
|
|
30
30
|
}
|
|
31
|
+
const regExpWindowsPathDriveLetter = /^([a-zA-Z]):[\\]/;
|
|
31
32
|
export function windowsDriveLetterToUpper(absoluteFilePath) {
|
|
32
|
-
return absoluteFilePath.replace(
|
|
33
|
+
return absoluteFilePath.replace(regExpWindowsPathDriveLetter, (s) => s.toUpperCase());
|
|
33
34
|
}
|
|
34
35
|
//# sourceMappingURL=url.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cspell-lib",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.13.0",
|
|
4
4
|
"description": "A library of useful functions used across various cspell tools.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -59,21 +59,21 @@
|
|
|
59
59
|
},
|
|
60
60
|
"homepage": "https://github.com/streetsidesoftware/cspell#readme",
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@cspell/cspell-bundled-dicts": "8.
|
|
63
|
-
"@cspell/cspell-pipe": "8.
|
|
64
|
-
"@cspell/cspell-resolver": "8.
|
|
65
|
-
"@cspell/cspell-types": "8.
|
|
66
|
-
"@cspell/dynamic-import": "8.
|
|
67
|
-
"@cspell/strong-weak-map": "8.
|
|
68
|
-
"@cspell/url": "8.
|
|
62
|
+
"@cspell/cspell-bundled-dicts": "8.13.0",
|
|
63
|
+
"@cspell/cspell-pipe": "8.13.0",
|
|
64
|
+
"@cspell/cspell-resolver": "8.13.0",
|
|
65
|
+
"@cspell/cspell-types": "8.13.0",
|
|
66
|
+
"@cspell/dynamic-import": "8.13.0",
|
|
67
|
+
"@cspell/strong-weak-map": "8.13.0",
|
|
68
|
+
"@cspell/url": "8.13.0",
|
|
69
69
|
"clear-module": "^4.1.2",
|
|
70
70
|
"comment-json": "^4.2.4",
|
|
71
|
-
"cspell-config-lib": "8.
|
|
72
|
-
"cspell-dictionary": "8.
|
|
73
|
-
"cspell-glob": "8.
|
|
74
|
-
"cspell-grammar": "8.
|
|
75
|
-
"cspell-io": "8.
|
|
76
|
-
"cspell-trie-lib": "8.
|
|
71
|
+
"cspell-config-lib": "8.13.0",
|
|
72
|
+
"cspell-dictionary": "8.13.0",
|
|
73
|
+
"cspell-glob": "8.13.0",
|
|
74
|
+
"cspell-grammar": "8.13.0",
|
|
75
|
+
"cspell-io": "8.13.0",
|
|
76
|
+
"cspell-trie-lib": "8.13.0",
|
|
77
77
|
"env-paths": "^3.0.0",
|
|
78
78
|
"fast-equals": "^5.0.1",
|
|
79
79
|
"gensequence": "^7.0.0",
|
|
@@ -87,19 +87,19 @@
|
|
|
87
87
|
"node": ">=18"
|
|
88
88
|
},
|
|
89
89
|
"devDependencies": {
|
|
90
|
-
"@cspell/dict-cpp": "^5.1.
|
|
90
|
+
"@cspell/dict-cpp": "^5.1.12",
|
|
91
91
|
"@cspell/dict-csharp": "^4.0.2",
|
|
92
92
|
"@cspell/dict-css": "^4.0.12",
|
|
93
93
|
"@cspell/dict-fa-ir": "^4.0.0",
|
|
94
94
|
"@cspell/dict-fr-fr": "^2.2.2",
|
|
95
95
|
"@cspell/dict-html": "^4.0.5",
|
|
96
96
|
"@cspell/dict-nl-nl": "^2.3.0",
|
|
97
|
-
"@cspell/dict-python": "^4.2.
|
|
97
|
+
"@cspell/dict-python": "^4.2.3",
|
|
98
98
|
"@types/configstore": "^6.0.2",
|
|
99
99
|
"configstore": "^7.0.0",
|
|
100
100
|
"cspell-dict-nl-nl": "^1.1.2",
|
|
101
101
|
"leaked-handles": "^5.2.0",
|
|
102
102
|
"lorem-ipsum": "^2.0.8"
|
|
103
103
|
},
|
|
104
|
-
"gitHead": "
|
|
104
|
+
"gitHead": "2fd3fb430cc96a8a50543f57d96b288219a11923"
|
|
105
105
|
}
|