cspell-lib 9.6.0 → 9.6.2
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/cspell-rpc/api.d.ts +28 -0
- package/dist/cspell-rpc/api.js +6 -0
- package/dist/cspell-rpc/client.d.ts +17 -0
- package/dist/cspell-rpc/client.js +20 -0
- package/dist/cspell-rpc/index.d.ts +7 -0
- package/dist/cspell-rpc/index.js +4 -0
- package/dist/cspell-rpc/server.d.ts +16 -0
- package/dist/cspell-rpc/server.js +37 -0
- package/dist/cspell-rpc/spellCheckFile.d.ts +2 -0
- package/dist/cspell-rpc/spellCheckFile.js +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/lib/Settings/CSpellSettingsServer.d.ts +4 -2
- package/dist/lib/Settings/CSpellSettingsServer.js +10 -2
- package/dist/lib/Settings/Controller/configLoader/configLoader.js +1 -1
- package/dist/lib/Settings/Controller/configLoader/defaultSettings.js +1 -1
- package/dist/lib/Settings/Controller/configLoader/normalizeRawSettings.js +1 -1
- package/dist/lib/Settings/Controller/configLoader/types.d.ts +1 -1
- package/dist/lib/Settings/DefaultSettings.d.ts +1 -1
- package/dist/lib/Settings/DefaultSettings.js +1 -1
- package/dist/lib/Settings/InDocSettings.d.ts +0 -3
- package/dist/lib/Settings/InDocSettings.js +2 -3
- package/dist/lib/Settings/LanguageSettings.js +3 -3
- package/dist/lib/Settings/TextDocumentSettings.d.ts +1 -1
- package/dist/lib/Settings/index.d.ts +3 -1
- package/dist/lib/Settings/index.js +2 -1
- package/dist/lib/Settings/internal/CSpellSettingsInternalDef.d.ts +18 -0
- package/dist/lib/{Models → Settings/internal}/CSpellSettingsInternalDef.js +1 -10
- package/dist/lib/Settings/{DictionarySettings.d.ts → internal/DictionarySettings.d.ts} +3 -2
- package/dist/lib/Settings/{DictionarySettings.js → internal/DictionarySettings.js} +14 -9
- package/dist/lib/{Models/CSpellSettingsInternalDef.d.ts → Settings/internal/InternalDictionaryDef.d.ts} +2 -17
- package/dist/lib/Settings/internal/InternalDictionaryDef.js +10 -0
- package/dist/lib/Settings/internal/index.d.ts +6 -0
- package/dist/lib/Settings/internal/index.js +4 -0
- package/dist/lib/Settings/sanitizeSettings.d.ts +11 -0
- package/dist/lib/Settings/sanitizeSettings.js +254 -0
- package/dist/lib/Settings/util/settingsToJson.d.ts +28 -0
- package/dist/lib/Settings/util/settingsToJson.js +125 -0
- package/dist/lib/SpellingDictionary/Dictionaries.d.ts +1 -1
- package/dist/lib/SpellingDictionary/Dictionaries.js +1 -1
- package/dist/lib/SpellingDictionary/DictionaryController/DictionaryLoader.d.ts +1 -1
- package/dist/lib/SpellingDictionary/DictionaryController/DictionaryLoader.js +99 -20
- package/dist/lib/SpellingDictionary/DictionaryLoader.d.ts +1 -1
- package/dist/lib/index.d.ts +2 -2
- package/dist/lib/index.js +2 -2
- package/dist/lib/perf/index.d.ts +1 -1
- package/dist/lib/perf/index.js +1 -1
- package/dist/lib/spellCheckFile.d.ts +10 -0
- package/dist/lib/spellCheckFile.js +24 -4
- package/dist/lib/suggestions.js +3 -3
- package/dist/lib/textValidation/cleanValidationIssue.d.ts +3 -0
- package/dist/lib/textValidation/cleanValidationIssue.js +21 -0
- package/dist/lib/textValidation/determineTextDocumentSettings.d.ts +1 -1
- package/dist/lib/textValidation/docValidator.d.ts +4 -1
- package/dist/lib/textValidation/docValidator.js +18 -1
- package/dist/lib/textValidation/settingsToValidateOptions.d.ts +1 -1
- package/dist/lib/util/clone.d.ts +35 -0
- package/dist/lib/util/clone.js +76 -0
- package/dist/lib/util/memoizeLastCall.d.ts +13 -0
- package/dist/lib/util/{memorizeLastCall.js → memoizeLastCall.js} +2 -2
- package/dist/lib/util/memoizeWeak.d.ts +6 -0
- package/dist/lib/util/{memorizerWeak.js → memoizeWeak.js} +2 -2
- package/dist/lib/util/text.js +6 -4
- package/dist/lib/util/textRegex.d.ts +2 -2
- package/dist/lib/util/textRegex.js +2 -2
- package/dist/rpc/Future.d.ts +18 -0
- package/dist/rpc/Future.js +49 -0
- package/dist/rpc/MessagePortEvents.d.ts +56 -0
- package/dist/rpc/MessagePortEvents.js +94 -0
- package/dist/rpc/assert.d.ts +14 -0
- package/dist/rpc/assert.js +21 -0
- package/dist/rpc/client.d.ts +186 -0
- package/dist/rpc/client.js +364 -0
- package/dist/rpc/errors.d.ts +24 -0
- package/dist/rpc/errors.js +47 -0
- package/dist/rpc/index.d.ts +11 -0
- package/dist/rpc/index.js +6 -0
- package/dist/rpc/messagePort.d.ts +34 -0
- package/dist/rpc/messagePort.js +2 -0
- package/dist/rpc/models.d.ts +134 -0
- package/dist/rpc/models.js +2 -0
- package/dist/rpc/modelsHelpers.d.ts +56 -0
- package/dist/rpc/modelsHelpers.js +117 -0
- package/dist/rpc/notify.d.ts +79 -0
- package/dist/rpc/notify.js +135 -0
- package/dist/rpc/protocol.d.ts +21 -0
- package/dist/rpc/protocol.js +17 -0
- package/dist/rpc/server.d.ts +39 -0
- package/dist/rpc/server.js +146 -0
- package/dist/rpc/types.d.ts +9 -0
- package/dist/rpc/types.js +2 -0
- package/dist/rpc.d.ts +2 -0
- package/dist/rpc.js +2 -0
- package/package.json +34 -21
- package/dist/lib/perf/performance.d.ts +0 -16
- package/dist/lib/perf/performance.js +0 -34
- package/dist/lib/util/memorizeLastCall.d.ts +0 -13
- package/dist/lib/util/memorizerWeak.d.ts +0 -6
|
@@ -3,9 +3,11 @@ import { isBinaryDoc } from './Document/isBinaryDoc.js';
|
|
|
3
3
|
import { documentToTextDocument, resolveDocument } from './Document/resolveDocument.js';
|
|
4
4
|
import { createTextDocument } from './Models/TextDocument.js';
|
|
5
5
|
import { createPerfTimer } from './perf/index.js';
|
|
6
|
+
import { cloneSettingsForExport } from './Settings/sanitizeSettings.js';
|
|
6
7
|
import { determineTextDocumentSettings } from './textValidation/determineTextDocumentSettings.js';
|
|
7
8
|
import { DocumentValidator } from './textValidation/index.js';
|
|
8
9
|
import { isError } from './util/errors.js';
|
|
10
|
+
import { memoizeLastCall } from './util/memoizeLastCall.js';
|
|
9
11
|
import { toUri } from './util/Uri.js';
|
|
10
12
|
/**
|
|
11
13
|
* Spell Check a file
|
|
@@ -73,6 +75,21 @@ export async function spellCheckDocument(document, options, settingsOrConfigFile
|
|
|
73
75
|
};
|
|
74
76
|
}
|
|
75
77
|
}
|
|
78
|
+
const memoizedCloneSettingsForExport = memoizeLastCall(cloneSettingsForExport);
|
|
79
|
+
function sanitizeSettingsForExport(settings) {
|
|
80
|
+
return settings ? memoizedCloneSettingsForExport(settings) : {};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Spell Check a Document.
|
|
84
|
+
* @param document - document to be checked. If `document.text` is `undefined` the file will be loaded
|
|
85
|
+
* @param options - options to control checking
|
|
86
|
+
* @param settings - default settings to use.
|
|
87
|
+
*/
|
|
88
|
+
export async function spellCheckDocumentRPC(document, options, settingsOrConfigFile) {
|
|
89
|
+
const result = { ...(await spellCheckDocument(document, options, settingsOrConfigFile)) };
|
|
90
|
+
result.settingsUsed = sanitizeSettingsForExport(result.settingsUsed);
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
76
93
|
async function spellCheckFullDocument(document, options, settingsOrConfigFile) {
|
|
77
94
|
// if (options.skipValidation) {
|
|
78
95
|
// return {
|
|
@@ -95,17 +112,18 @@ async function spellCheckFullDocument(document, options, settingsOrConfigFile) {
|
|
|
95
112
|
Object.assign(perf, Object.fromEntries(Object.entries(docValidator.perfTiming).map(([k, v]) => ['_' + k, v])));
|
|
96
113
|
const prep = docValidator._getPreparations();
|
|
97
114
|
if (docValidator.errors.length) {
|
|
115
|
+
const settingsUsed = prep?.localConfig ||
|
|
116
|
+
(satisfiesCSpellConfigFile(settingsOrConfigFile) ? settingsOrConfigFile.settings : settingsOrConfigFile);
|
|
98
117
|
return {
|
|
99
118
|
document,
|
|
100
119
|
options,
|
|
101
|
-
settingsUsed
|
|
102
|
-
(satisfiesCSpellConfigFile(settingsOrConfigFile)
|
|
103
|
-
? settingsOrConfigFile.settings
|
|
104
|
-
: settingsOrConfigFile),
|
|
120
|
+
settingsUsed,
|
|
105
121
|
localConfigFilepath: prep?.localConfigFilepath,
|
|
106
122
|
issues: [],
|
|
107
123
|
checked: false,
|
|
108
124
|
errors: docValidator.errors,
|
|
125
|
+
configErrors: docValidator.getConfigErrors(),
|
|
126
|
+
dictionaryErrors: docValidator.getDictionaryErrors(),
|
|
109
127
|
perf,
|
|
110
128
|
};
|
|
111
129
|
}
|
|
@@ -121,6 +139,8 @@ async function spellCheckFullDocument(document, options, settingsOrConfigFile) {
|
|
|
121
139
|
issues,
|
|
122
140
|
checked: docValidator.shouldCheckDocument(),
|
|
123
141
|
errors: undefined,
|
|
142
|
+
configErrors: docValidator.getConfigErrors(),
|
|
143
|
+
dictionaryErrors: docValidator.getDictionaryErrors(),
|
|
124
144
|
perf,
|
|
125
145
|
};
|
|
126
146
|
timer.end();
|
package/dist/lib/suggestions.js
CHANGED
|
@@ -4,7 +4,7 @@ import { finalizeSettings, getDefaultSettings, getGlobalSettingsAsync, mergeSett
|
|
|
4
4
|
import { calcSettingsForLanguageId, isValidLocaleIntlFormat, normalizeLocaleIntl, } from './Settings/LanguageSettings.js';
|
|
5
5
|
import { getDictionaryInternal, refreshDictionaryCache } from './SpellingDictionary/index.js';
|
|
6
6
|
import { createAutoResolveCache } from './util/AutoResolve.js';
|
|
7
|
-
import {
|
|
7
|
+
import { memoizeLastCall } from './util/memoizeLastCall.js';
|
|
8
8
|
import * as util from './util/util.js';
|
|
9
9
|
const emptySuggestionOptions = Object.freeze({});
|
|
10
10
|
const emptyCSpellSettings = Object.freeze({});
|
|
@@ -14,14 +14,14 @@ export async function* suggestionsForWords(words, options, settings) {
|
|
|
14
14
|
yield await suggestionsForWord(word, options, cspellSettings);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
const
|
|
17
|
+
const memoizeSuggestions = memoizeLastCall(cacheSuggestionsForWord);
|
|
18
18
|
function cacheSuggestionsForWord(options, settings) {
|
|
19
19
|
const cache = createAutoResolveCache();
|
|
20
20
|
return (word) => cache.get(word, (word) => _suggestionsForWord(word, options, settings));
|
|
21
21
|
}
|
|
22
22
|
export async function suggestionsForWord(word, options = emptySuggestionOptions, settings = emptyCSpellSettings) {
|
|
23
23
|
const cspellSettings = satisfiesCSpellConfigFile(settings) ? await resolveConfigFileImports(settings) : settings;
|
|
24
|
-
return
|
|
24
|
+
return memoizeSuggestions(options, cspellSettings)(word);
|
|
25
25
|
}
|
|
26
26
|
async function _suggestionsForWord(word, options, settings) {
|
|
27
27
|
const { languageId, locale: language, includeDefaultConfig = true, dictionaries } = options;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { cloneInto, copy0, copy1 } from '../util/clone.js';
|
|
2
|
+
export function cleanValidationIssue(issue) {
|
|
3
|
+
const cleanIssue = {};
|
|
4
|
+
cloneInto(issue, cleanIssue, ValidationIssueHandlers);
|
|
5
|
+
return cleanIssue;
|
|
6
|
+
}
|
|
7
|
+
const ValidationIssueHandlers = {
|
|
8
|
+
text: copy0,
|
|
9
|
+
offset: copy0,
|
|
10
|
+
message: copy0,
|
|
11
|
+
line: copy1,
|
|
12
|
+
length: copy0,
|
|
13
|
+
issueType: copy0,
|
|
14
|
+
hasPreferredSuggestions: copy0,
|
|
15
|
+
hasSimpleSuggestions: copy0,
|
|
16
|
+
isFlagged: copy0,
|
|
17
|
+
isFound: copy0,
|
|
18
|
+
suggestions: copy1,
|
|
19
|
+
suggestionsEx: copy1,
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=cleanValidationIssue.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CSpellUserSettings } from '@cspell/cspell-types';
|
|
2
|
-
import type { CSpellSettingsInternal } from '../Models/CSpellSettingsInternalDef.js';
|
|
3
2
|
import type { TextDocument, TextDocumentRef } from '../Models/TextDocument.js';
|
|
3
|
+
import type { CSpellSettingsInternal } from '../Settings/index.js';
|
|
4
4
|
/**
|
|
5
5
|
* Combines all relevant setting values into a final configuration to be used for spell checking.
|
|
6
6
|
* It applies any overrides and appropriate language settings by taking into account the document type (languageId)
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { CSpellUserSettings, MappedText, ParsedText } from '@cspell/cspell-types';
|
|
2
2
|
import type { ICSpellConfigFile } from 'cspell-config-lib';
|
|
3
|
-
import type { CSpellSettingsInternal, CSpellSettingsInternalFinalized } from '../Models/CSpellSettingsInternalDef.js';
|
|
4
3
|
import type { ExtendedSuggestion } from '../Models/Suggestion.js';
|
|
5
4
|
import type { TextDocument, TextDocumentRef } from '../Models/TextDocument.js';
|
|
6
5
|
import type { ValidationIssue } from '../Models/ValidationIssue.js';
|
|
6
|
+
import type { ImportFileRefWithError } from '../Settings/index.js';
|
|
7
|
+
import type { CSpellSettingsInternal, CSpellSettingsInternalFinalized } from '../Settings/index.js';
|
|
7
8
|
import type { SpellingDictionaryCollection } from '../SpellingDictionary/index.js';
|
|
8
9
|
import type { WordSuggestion } from '../suggestions.js';
|
|
9
10
|
import type { MatchRange } from '../util/TextRange.js';
|
|
@@ -101,6 +102,8 @@ export declare class DocumentValidator {
|
|
|
101
102
|
private genSuggestions;
|
|
102
103
|
private adjustSuggestions;
|
|
103
104
|
getFinalizedDocSettings(): CSpellSettingsInternal;
|
|
105
|
+
getConfigErrors(): ImportFileRefWithError[] | undefined;
|
|
106
|
+
getDictionaryErrors(): Map<string, Error[]> | undefined;
|
|
104
107
|
/**
|
|
105
108
|
* Returns true if the final result of the configuration calculation results
|
|
106
109
|
* in the document being enabled. Note: in some cases, checking the document
|
|
@@ -13,6 +13,7 @@ import { calcSuggestionAdjustedToToMatchCase } from '../suggestions.js';
|
|
|
13
13
|
import { catchPromiseError, toError } from '../util/errors.js';
|
|
14
14
|
import { AutoCache } from '../util/simpleCache.js';
|
|
15
15
|
import { uriToFilePath } from '../util/Uri.js';
|
|
16
|
+
import { cleanValidationIssue } from './cleanValidationIssue.js';
|
|
16
17
|
import { defaultMaxDuplicateProblems, defaultMaxNumberOfProblems } from './defaultConstants.js';
|
|
17
18
|
import { determineTextDocumentSettings } from './determineTextDocumentSettings.js';
|
|
18
19
|
import { textValidatorFactory } from './lineValidatorFactory.js';
|
|
@@ -245,7 +246,9 @@ export class DocumentValidator {
|
|
|
245
246
|
const spellingIssues = forceCheck || this.shouldCheckDocument() ? [...this._checkParsedText(this._parse())] : [];
|
|
246
247
|
const directiveIssues = this.checkDocumentDirectives();
|
|
247
248
|
// console.log('Stats: %o', this._preparations.textValidator.lineValidator.dict.stats());
|
|
248
|
-
const allIssues = [...spellingIssues, ...directiveIssues]
|
|
249
|
+
const allIssues = [...spellingIssues, ...directiveIssues]
|
|
250
|
+
.map(cleanValidationIssue)
|
|
251
|
+
.sort((a, b) => a.offset - b.offset);
|
|
249
252
|
return allIssues;
|
|
250
253
|
}
|
|
251
254
|
finally {
|
|
@@ -360,6 +363,20 @@ export class DocumentValidator {
|
|
|
360
363
|
assert(this._preparations, ERROR_NOT_PREPARED);
|
|
361
364
|
return this._preparations.docSettings;
|
|
362
365
|
}
|
|
366
|
+
getConfigErrors() {
|
|
367
|
+
const settings = this.getFinalizedDocSettings();
|
|
368
|
+
const errors = extractImportErrors(settings);
|
|
369
|
+
return errors.length ? errors : undefined;
|
|
370
|
+
}
|
|
371
|
+
getDictionaryErrors() {
|
|
372
|
+
assert(this._ready);
|
|
373
|
+
assert(this._preparations, ERROR_NOT_PREPARED);
|
|
374
|
+
const { dictionary } = this._preparations;
|
|
375
|
+
const errors = dictionary.dictionaries
|
|
376
|
+
.map((dict) => [dict.name, dict.getErrors?.()])
|
|
377
|
+
.filter((entry) => (entry[1] && entry[1].length > 0) || false);
|
|
378
|
+
return errors.length ? new Map(errors) : undefined;
|
|
379
|
+
}
|
|
363
380
|
/**
|
|
364
381
|
* Returns true if the final result of the configuration calculation results
|
|
365
382
|
* in the document being enabled. Note: in some cases, checking the document
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CSpellSettingsInternalFinalized } from '../
|
|
1
|
+
import type { CSpellSettingsInternalFinalized } from '../Settings/index.js';
|
|
2
2
|
import type { ValidationOptions } from './ValidationTypes.js';
|
|
3
3
|
export declare function settingsToValidateOptions(settings: CSpellSettingsInternalFinalized): ValidationOptions;
|
|
4
4
|
//# sourceMappingURL=settingsToValidateOptions.d.ts.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type Handler<T, K extends keyof T> = (src: Readonly<T>, dst: T, key: K) => void;
|
|
2
|
+
export type Handlers<T> = {
|
|
3
|
+
[key in keyof T]-?: Handler<T, key>;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Clones the properties from src to dst using the provided handlers.
|
|
7
|
+
* @param src
|
|
8
|
+
* @param dst
|
|
9
|
+
* @param handlers
|
|
10
|
+
* @param keys
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
export declare function cloneInto<T, K extends keyof T>(src: Readonly<T>, dst: Partial<T>, handlers: Handlers<T>, keys?: K[]): Pick<T, K>;
|
|
14
|
+
export declare function skip<T, K extends keyof T>(_src: Readonly<T>, _dst: T, _key: K): void;
|
|
15
|
+
/**
|
|
16
|
+
* Copy the property from src to dst.
|
|
17
|
+
* If the property is undefined, it is not copied.
|
|
18
|
+
* @param src - source object
|
|
19
|
+
* @param dst - destination object
|
|
20
|
+
* @param key - property key
|
|
21
|
+
*/
|
|
22
|
+
export declare function copy0<T, K extends keyof T>(src: Readonly<T>, dst: T, key: K): void;
|
|
23
|
+
/**
|
|
24
|
+
* Copy the property from src to dst.
|
|
25
|
+
* If the property is undefined, it is not copied.
|
|
26
|
+
* If the property is an array, a shallow copy of the array is made.
|
|
27
|
+
* If the property is a Set, a shallow copy of the Set is made.
|
|
28
|
+
* If the property is a Map, a shallow copy of the Map is made.
|
|
29
|
+
* If the property is an object, a shallow copy of the object is made.
|
|
30
|
+
* @param src - source object
|
|
31
|
+
* @param dst - destination object
|
|
32
|
+
* @param key - property key
|
|
33
|
+
*/
|
|
34
|
+
export declare function copy1<T, K extends keyof T>(src: Readonly<T>, dst: T, key: K): void;
|
|
35
|
+
//# sourceMappingURL=clone.d.ts.map
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clones the properties from src to dst using the provided handlers.
|
|
3
|
+
* @param src
|
|
4
|
+
* @param dst
|
|
5
|
+
* @param handlers
|
|
6
|
+
* @param keys
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export function cloneInto(src, dst, handlers, keys) {
|
|
10
|
+
const keysToProcess = keys || Object.keys(handlers);
|
|
11
|
+
for (const key of keysToProcess) {
|
|
12
|
+
if (src[key] === undefined)
|
|
13
|
+
continue;
|
|
14
|
+
const handler = handlers[key];
|
|
15
|
+
if (handler === skip)
|
|
16
|
+
continue;
|
|
17
|
+
handler(src, dst, key);
|
|
18
|
+
}
|
|
19
|
+
return dst;
|
|
20
|
+
}
|
|
21
|
+
export function skip(_src, _dst, _key) {
|
|
22
|
+
// do nothing
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Copy the property from src to dst.
|
|
26
|
+
* If the property is undefined, it is not copied.
|
|
27
|
+
* @param src - source object
|
|
28
|
+
* @param dst - destination object
|
|
29
|
+
* @param key - property key
|
|
30
|
+
*/
|
|
31
|
+
export function copy0(src, dst, key) {
|
|
32
|
+
const value = src[key];
|
|
33
|
+
if (value === undefined)
|
|
34
|
+
return;
|
|
35
|
+
dst[key] = value;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Copy the property from src to dst.
|
|
39
|
+
* If the property is undefined, it is not copied.
|
|
40
|
+
* If the property is an array, a shallow copy of the array is made.
|
|
41
|
+
* If the property is a Set, a shallow copy of the Set is made.
|
|
42
|
+
* If the property is a Map, a shallow copy of the Map is made.
|
|
43
|
+
* If the property is an object, a shallow copy of the object is made.
|
|
44
|
+
* @param src - source object
|
|
45
|
+
* @param dst - destination object
|
|
46
|
+
* @param key - property key
|
|
47
|
+
*/
|
|
48
|
+
export function copy1(src, dst, key) {
|
|
49
|
+
if (src[key] === undefined)
|
|
50
|
+
return;
|
|
51
|
+
const value = src[key];
|
|
52
|
+
if (value === undefined)
|
|
53
|
+
return;
|
|
54
|
+
if (Array.isArray(value)) {
|
|
55
|
+
dst[key] = [...value];
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (value instanceof Set) {
|
|
59
|
+
dst[key] = new Set(value);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (value instanceof Map) {
|
|
63
|
+
dst[key] = new Map(value);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (value instanceof RegExp) {
|
|
67
|
+
dst[key] = value;
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (typeof value === 'object') {
|
|
71
|
+
dst[key] = { ...value };
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
dst[key] = value;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=clone.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a function that memoizes the last call. If the next call is called with the same arguments, the
|
|
3
|
+
* the last value is returned.
|
|
4
|
+
* @param fn - function to memoize
|
|
5
|
+
* @returns a new function.
|
|
6
|
+
*/
|
|
7
|
+
export declare function memoizeLastCall<T>(fn: (...p: []) => T): (...p: []) => T;
|
|
8
|
+
export declare function memoizeLastCall<T, K0>(fn: (...p: [K0]) => T): (...p: [K0]) => T;
|
|
9
|
+
export declare function memoizeLastCall<T, K0, K1>(fn: (...p: [K0, K1]) => T): (...p: [K0, K1]) => T;
|
|
10
|
+
export declare function memoizeLastCall<T, K0, K1, K2>(fn: (...p: [K0, K1, K2]) => T): (...p: [K0, K1, K2]) => T;
|
|
11
|
+
export declare function memoizeLastCall<T, K0, K1, K2, K3>(fn: (...p: [K0, K1, K2, K3]) => T): (...p: [K0, K1, K2, K3]) => T;
|
|
12
|
+
export declare function memoizeLastCall<T, K>(fn: (...p: [...K[]]) => T): (...p: [...K[]]) => T;
|
|
13
|
+
//# sourceMappingURL=memoizeLastCall.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isArrayEqual } from './util.js';
|
|
2
|
-
export function
|
|
2
|
+
export function memoizeLastCall(fn) {
|
|
3
3
|
let last;
|
|
4
4
|
return (...p) => {
|
|
5
5
|
if (last && isArrayEqual(last.args, p)) {
|
|
@@ -11,4 +11,4 @@ export function memorizeLastCall(fn) {
|
|
|
11
11
|
return value;
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
|
-
//# sourceMappingURL=
|
|
14
|
+
//# sourceMappingURL=memoizeLastCall.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function memoizeWeak<T, K extends object>(fn: (...p: [...K[]]) => T): (...p: [...K[]]) => T;
|
|
2
|
+
export declare function memoizeWeak<T, K0 extends object, K1 extends object>(fn: (...p: [K0, K1]) => T): (...p: [K0, K1]) => T;
|
|
3
|
+
export declare function memoizeWeak<T, K0 extends object, K1 extends object, K2 extends object>(fn: (...p: [K0, K1, K2]) => T): (...p: [K0, K1, K2]) => T;
|
|
4
|
+
export declare function memoizeWeak<T, K0 extends object, K1 extends object, K2 extends object, K3 extends object>(fn: (...p: [K0, K1, K2, K3]) => T): (...p: [K0, K1, K2, K3]) => T;
|
|
5
|
+
export declare function memoizeWeak<T, K0 extends object>(fn: (...p: [K0]) => T): (...p: [K0]) => T;
|
|
6
|
+
//# sourceMappingURL=memoizeWeak.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// prettier-ignore
|
|
2
|
-
export function
|
|
2
|
+
export function memoizeWeak(fn) {
|
|
3
3
|
const r = {};
|
|
4
4
|
function find(p) {
|
|
5
5
|
let n = r;
|
|
@@ -35,4 +35,4 @@ export function memorizerWeak(fn) {
|
|
|
35
35
|
return v;
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
|
-
//# sourceMappingURL=
|
|
38
|
+
//# sourceMappingURL=memoizeWeak.js.map
|
package/dist/lib/util/text.js
CHANGED
|
@@ -27,7 +27,7 @@ export function splitWordWithOffset(wo, regExpWordBreaks) {
|
|
|
27
27
|
* Split camelCase words into an array of strings.
|
|
28
28
|
*/
|
|
29
29
|
export function splitWord(word, regExpWordBreaks) {
|
|
30
|
-
return word.split(regExpWordBreaks);
|
|
30
|
+
return word.split(new RegExp(regExpWordBreaks));
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
33
|
* This function lets you iterate over regular expression matches.
|
|
@@ -35,7 +35,7 @@ export function splitWord(word, regExpWordBreaks) {
|
|
|
35
35
|
export function match(reg, text) {
|
|
36
36
|
if (!text)
|
|
37
37
|
return [];
|
|
38
|
-
reg = reg.global ? reg : new RegExp(reg.source, reg.flags + 'g');
|
|
38
|
+
reg = reg.global ? new RegExp(reg) : new RegExp(reg.source, reg.flags + 'g');
|
|
39
39
|
return text.matchAll(reg);
|
|
40
40
|
}
|
|
41
41
|
export function matchStringToTextOffset(reg, text) {
|
|
@@ -78,6 +78,7 @@ export function cleanText(text) {
|
|
|
78
78
|
regExIgnoreCharacters.lastIndex = 0;
|
|
79
79
|
if (!regExIgnoreCharacters.test(text))
|
|
80
80
|
return text;
|
|
81
|
+
regExIgnoreCharacters.lastIndex = 0;
|
|
81
82
|
text = text.replace(regExIgnoreCharacters, (match) => ' '.repeat(match.length));
|
|
82
83
|
return text;
|
|
83
84
|
}
|
|
@@ -191,10 +192,11 @@ export function calculateTextDocumentOffsets(uri, doc, wordOffsets) {
|
|
|
191
192
|
});
|
|
192
193
|
}
|
|
193
194
|
export function removeAccents(text) {
|
|
195
|
+
regExAccents.lastIndex = 0;
|
|
194
196
|
return text.normalize('NFD').replace(regExAccents, '');
|
|
195
197
|
}
|
|
196
198
|
export const __testing__ = {
|
|
197
|
-
regExWords,
|
|
198
|
-
regExWordsAndDigits,
|
|
199
|
+
regExWords: regExWords,
|
|
200
|
+
regExWordsAndDigits: regExWordsAndDigits,
|
|
199
201
|
};
|
|
200
202
|
//# sourceMappingURL=text.js.map
|
|
@@ -2,8 +2,8 @@ export declare const regExUpperSOrIng: RegExp;
|
|
|
2
2
|
export declare const regExSplitWords: RegExp;
|
|
3
3
|
export declare const regExSplitWords2: RegExp;
|
|
4
4
|
export declare const regExpCamelCaseWordBreaksWithEnglishSuffix: RegExp;
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const
|
|
5
|
+
export declare const regExpCamelCaseWordBreaks_NOT_USED: RegExp;
|
|
6
|
+
export declare const regExpAllPossibleWordBreaks_NOT_USED: RegExp;
|
|
7
7
|
export declare const regExWords: RegExp;
|
|
8
8
|
export declare const regExWordsAndDigits: RegExp;
|
|
9
9
|
export declare const regExIgnoreCharacters: RegExp;
|
|
@@ -3,8 +3,8 @@ export const regExUpperSOrIng = /([\p{Lu}\p{M}]+(?:\\?['’])?(?:s|ing|ies|es|in
|
|
|
3
3
|
export const regExSplitWords = /(\p{Ll}\p{M}?)(\p{Lu})/gu;
|
|
4
4
|
export const regExSplitWords2 = /(\p{Lu}\p{M}?)((\p{Lu}\p{M}?)\p{Ll})/gu;
|
|
5
5
|
export const regExpCamelCaseWordBreaksWithEnglishSuffix = /(?<=\p{Ll}\p{M}?)(?=\p{Lu})|(?<=\p{Lu}\p{M}?)(?=\p{Lu}\p{M}?\p{Ll})(?!\p{Lu}\p{M}?(?:s|ing|ies|es|ings|ed|ning)(?!\p{Ll}))/gu;
|
|
6
|
-
export const
|
|
7
|
-
export const
|
|
6
|
+
export const regExpCamelCaseWordBreaks_NOT_USED = /(?<=\p{Ll}\p{M}?)(?=\p{Lu})|(?<=\p{Lu}\p{M}?)(?=\p{Lu}\p{M}?\p{Ll})/gu;
|
|
7
|
+
export const regExpAllPossibleWordBreaks_NOT_USED = /(?<=\p{Ll}\p{M}?)(?=\p{Lu})|(?<=\p{Lu}\p{M}?)(?=\p{Lu}\p{M}?\p{Ll})|(?<=\p{Lu}\p{M}?\p{Lu}\p{M}?)(?=\p{Ll})|(?<=\p{L}\p{M}?)(?=\P{L})|(?<=\P{L})(?=\p{L})/gu;
|
|
8
8
|
export const regExWords = /\p{L}\p{M}?(?:(?:\\?['’])?\p{L}\p{M}?)*/gu;
|
|
9
9
|
// Words can be made of letters, numbers, period, underscore, dash, plus, and single quote
|
|
10
10
|
export const regExWordsAndDigits = /[\p{L}\w'’`.+-](?:(?:\\(?=[']))?[\p{L}\p{M}\w'’`.+-])*/gu;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare class Future<T> {
|
|
2
|
+
#private;
|
|
3
|
+
constructor();
|
|
4
|
+
/**
|
|
5
|
+
* Indicates if the promise has been resolved or rejected.
|
|
6
|
+
*
|
|
7
|
+
* Use isRejected to determine if it was rejected.
|
|
8
|
+
*/
|
|
9
|
+
get isResolved(): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Indicates if the promise has been rejected.
|
|
12
|
+
*/
|
|
13
|
+
get isRejected(): boolean;
|
|
14
|
+
get promise(): Promise<T>;
|
|
15
|
+
resolve(value: T): void;
|
|
16
|
+
reject(reason?: unknown): void;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=Future.d.ts.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export class Future {
|
|
2
|
+
#isResolved = false;
|
|
3
|
+
#isRejected = false;
|
|
4
|
+
#promise;
|
|
5
|
+
#resolve;
|
|
6
|
+
#reject;
|
|
7
|
+
constructor() {
|
|
8
|
+
this.#reject = noop;
|
|
9
|
+
this.#resolve = noop;
|
|
10
|
+
this.#promise = new Promise((resolve, reject) => {
|
|
11
|
+
this.#resolve = resolve;
|
|
12
|
+
this.#reject = reject;
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Indicates if the promise has been resolved or rejected.
|
|
17
|
+
*
|
|
18
|
+
* Use isRejected to determine if it was rejected.
|
|
19
|
+
*/
|
|
20
|
+
get isResolved() {
|
|
21
|
+
return this.#isResolved;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Indicates if the promise has been rejected.
|
|
25
|
+
*/
|
|
26
|
+
get isRejected() {
|
|
27
|
+
return this.#isRejected;
|
|
28
|
+
}
|
|
29
|
+
get promise() {
|
|
30
|
+
return this.#promise;
|
|
31
|
+
}
|
|
32
|
+
resolve(value) {
|
|
33
|
+
if (this.#isResolved)
|
|
34
|
+
return;
|
|
35
|
+
this.#isResolved = true;
|
|
36
|
+
this.#resolve(value);
|
|
37
|
+
}
|
|
38
|
+
reject(reason) {
|
|
39
|
+
if (this.#isResolved)
|
|
40
|
+
return;
|
|
41
|
+
this.#isResolved = true;
|
|
42
|
+
this.#isRejected = true;
|
|
43
|
+
this.#reject(reason);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function noop() {
|
|
47
|
+
// do nothing
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=Future.js.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { MessagePortLike } from './messagePort.js';
|
|
2
|
+
import type { NotifyEvent } from './notify.js';
|
|
3
|
+
/**
|
|
4
|
+
* Wraps a {@link MessagePortLike} and exposes its key events through a
|
|
5
|
+
* {@link NotifyEmitter}-based interface.
|
|
6
|
+
*
|
|
7
|
+
* This class listens to the underlying port's `message`,
|
|
8
|
+
* `messageerror`, and `close` events and re-emits them as
|
|
9
|
+
* {@link NotifyEvent} instances, making it easier to subscribe to and manage
|
|
10
|
+
* notifications from a message port.
|
|
11
|
+
*/
|
|
12
|
+
export declare class MessagePortNotifyEvents<T extends MessagePortLike = MessagePortLike> {
|
|
13
|
+
#private;
|
|
14
|
+
constructor(port: T);
|
|
15
|
+
[Symbol.dispose](): void;
|
|
16
|
+
/**
|
|
17
|
+
* Register a handler to be called when a message is received.
|
|
18
|
+
*/
|
|
19
|
+
get onMessage(): NotifyEvent<unknown>;
|
|
20
|
+
/**
|
|
21
|
+
* Return a Promise that resolves on the next message.
|
|
22
|
+
* @param signal - A signal to abort the wait.
|
|
23
|
+
* @returns A Promise that resolves with the next message received.
|
|
24
|
+
*/
|
|
25
|
+
readonly awaitNextMessage: (signal?: AbortSignal) => Promise<unknown>;
|
|
26
|
+
/**
|
|
27
|
+
* Return a Promise that resolves on the close event.
|
|
28
|
+
* @param signal - A signal to abort the wait.
|
|
29
|
+
* @returns A Promise that resolves when the port is closed.
|
|
30
|
+
*/
|
|
31
|
+
readonly awaitClose: (signal?: AbortSignal) => Promise<Event>;
|
|
32
|
+
/**
|
|
33
|
+
* Post a message to the underlying port.
|
|
34
|
+
* @param message - The message to post.
|
|
35
|
+
*/
|
|
36
|
+
readonly postMessage: T['postMessage'];
|
|
37
|
+
/**
|
|
38
|
+
* Start the underlying port.
|
|
39
|
+
*/
|
|
40
|
+
start(): void;
|
|
41
|
+
/**
|
|
42
|
+
* Close the underlying port.
|
|
43
|
+
*/
|
|
44
|
+
close(): void;
|
|
45
|
+
/**
|
|
46
|
+
* Register a handler to be called when the port is closed.
|
|
47
|
+
*/
|
|
48
|
+
get onClose(): NotifyEvent<Event>;
|
|
49
|
+
/**
|
|
50
|
+
* Register a handler to be called when a message error is received.
|
|
51
|
+
*/
|
|
52
|
+
get onMessageError(): NotifyEvent<Error>;
|
|
53
|
+
get isClosed(): boolean;
|
|
54
|
+
get port(): T;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=MessagePortEvents.d.ts.map
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { NotifyEmitter } from './notify.js';
|
|
2
|
+
/**
|
|
3
|
+
* Wraps a {@link MessagePortLike} and exposes its key events through a
|
|
4
|
+
* {@link NotifyEmitter}-based interface.
|
|
5
|
+
*
|
|
6
|
+
* This class listens to the underlying port's `message`,
|
|
7
|
+
* `messageerror`, and `close` events and re-emits them as
|
|
8
|
+
* {@link NotifyEvent} instances, making it easier to subscribe to and manage
|
|
9
|
+
* notifications from a message port.
|
|
10
|
+
*/
|
|
11
|
+
export class MessagePortNotifyEvents {
|
|
12
|
+
#notifyMessage = new NotifyEmitter();
|
|
13
|
+
#notifyClose = new NotifyEmitter();
|
|
14
|
+
#notifyMessageError = new NotifyEmitter();
|
|
15
|
+
#port;
|
|
16
|
+
#disposed = false;
|
|
17
|
+
#closed;
|
|
18
|
+
constructor(port) {
|
|
19
|
+
this.#port = port;
|
|
20
|
+
this.#port.addListener('message', this.#notifyMessage.notify);
|
|
21
|
+
this.#port.addListener('messageerror', this.#notifyMessageError.notify);
|
|
22
|
+
this.#port.addListener('close', this.#notifyClose.notify);
|
|
23
|
+
this.#notifyClose.once((event) => (this.#closed = event));
|
|
24
|
+
}
|
|
25
|
+
[Symbol.dispose]() {
|
|
26
|
+
if (this.#disposed)
|
|
27
|
+
return;
|
|
28
|
+
this.#disposed = true;
|
|
29
|
+
this.#port.removeListener('message', this.#notifyMessage.notify);
|
|
30
|
+
this.#port.removeListener('messageerror', this.#notifyMessageError.notify);
|
|
31
|
+
this.#port.removeListener('close', this.#notifyClose.notify);
|
|
32
|
+
this.#notifyMessage[Symbol.dispose]();
|
|
33
|
+
this.#notifyClose[Symbol.dispose]();
|
|
34
|
+
this.#notifyMessageError[Symbol.dispose]();
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Register a handler to be called when a message is received.
|
|
38
|
+
*/
|
|
39
|
+
get onMessage() {
|
|
40
|
+
return this.#notifyMessage.onEvent;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Return a Promise that resolves on the next message.
|
|
44
|
+
* @param signal - A signal to abort the wait.
|
|
45
|
+
* @returns A Promise that resolves with the next message received.
|
|
46
|
+
*/
|
|
47
|
+
awaitNextMessage = (signal) => this.#notifyMessage.awaitNext(signal);
|
|
48
|
+
/**
|
|
49
|
+
* Return a Promise that resolves on the close event.
|
|
50
|
+
* @param signal - A signal to abort the wait.
|
|
51
|
+
* @returns A Promise that resolves when the port is closed.
|
|
52
|
+
*/
|
|
53
|
+
awaitClose = (signal) => {
|
|
54
|
+
if (this.#closed)
|
|
55
|
+
return Promise.resolve(this.#closed);
|
|
56
|
+
return this.#notifyClose.awaitNext(signal);
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Post a message to the underlying port.
|
|
60
|
+
* @param message - The message to post.
|
|
61
|
+
*/
|
|
62
|
+
postMessage = (message) => this.#port.postMessage(message);
|
|
63
|
+
/**
|
|
64
|
+
* Start the underlying port.
|
|
65
|
+
*/
|
|
66
|
+
start() {
|
|
67
|
+
this.#port.start?.();
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Close the underlying port.
|
|
71
|
+
*/
|
|
72
|
+
close() {
|
|
73
|
+
this.#port.close?.();
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Register a handler to be called when the port is closed.
|
|
77
|
+
*/
|
|
78
|
+
get onClose() {
|
|
79
|
+
return this.#notifyClose.onEvent;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Register a handler to be called when a message error is received.
|
|
83
|
+
*/
|
|
84
|
+
get onMessageError() {
|
|
85
|
+
return this.#notifyMessageError.onEvent;
|
|
86
|
+
}
|
|
87
|
+
get isClosed() {
|
|
88
|
+
return this.#closed !== undefined;
|
|
89
|
+
}
|
|
90
|
+
get port() {
|
|
91
|
+
return this.#port;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=MessagePortEvents.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Note: This code is here to avoid a dependency on Node's 'assert' module.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Asserts that a condition is true.
|
|
6
|
+
* @param condition - The condition to assert.
|
|
7
|
+
* @param msg - optional message for the assertion error.
|
|
8
|
+
* @throws {AssertionError} If the condition is false.
|
|
9
|
+
*/
|
|
10
|
+
export declare function assert(condition: unknown, msg?: string): asserts condition;
|
|
11
|
+
export declare class AssertionError extends Error {
|
|
12
|
+
constructor(message?: string);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=assert.d.ts.map
|