cspell-lib 6.0.0 → 6.1.1
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/LanguageIds.js +2 -2
- package/dist/Models/TextDocument.d.ts +3 -0
- package/dist/Models/TextDocument.js +35 -10
- package/dist/spellCheckFile.js +16 -47
- package/dist/textValidation/docValidator.d.ts +37 -3
- package/dist/textValidation/docValidator.js +73 -13
- package/dist/textValidation/index.d.ts +1 -0
- package/dist/textValidation/parsedText.d.ts +21 -0
- package/dist/textValidation/parsedText.js +46 -0
- package/dist/util/logger.d.ts +1 -0
- package/package.json +14 -14
package/dist/LanguageIds.js
CHANGED
|
@@ -24,7 +24,7 @@ exports.languageExtensionDefinitions = [
|
|
|
24
24
|
{ id: 'css', extensions: ['.css'] },
|
|
25
25
|
{ id: 'dhall', extensions: ['.dhall'] },
|
|
26
26
|
{ id: 'diff', extensions: ['.diff', '.patch', '.rej'] },
|
|
27
|
-
{ id: 'dockerfile', extensions: ['.dockerfile'] },
|
|
27
|
+
{ id: 'dockerfile', extensions: ['.dockerfile'], filenames: ['Dockerfile'] },
|
|
28
28
|
{ id: 'elixir', extensions: ['.ex', '.exs'] },
|
|
29
29
|
{ id: 'fsharp', extensions: ['.fs', '.fsi', '.fsx', '.fsscript'] },
|
|
30
30
|
{ id: 'go', extensions: ['.go'] },
|
|
@@ -46,7 +46,7 @@ exports.languageExtensionDefinitions = [
|
|
|
46
46
|
extensions: ['.json', '.jsonc', '.bowerrc', '.jshintrc', '.jscsrc', '.eslintrc', '.babelrc', '.webmanifest'],
|
|
47
47
|
},
|
|
48
48
|
{ id: 'jsonc', extensions: ['.jsonc'] },
|
|
49
|
-
{ id: 'jsonc', extensions: [], filenames: ['.code-workspace'] },
|
|
49
|
+
{ id: 'jsonc', extensions: ['.code-workspace'], filenames: ['.code-workspace'] },
|
|
50
50
|
{ id: 'jungle', extensions: ['.jungle'] },
|
|
51
51
|
{ id: 'less', extensions: ['.less'] },
|
|
52
52
|
{ id: 'literate haskell', extensions: ['.lhs'] },
|
|
@@ -44,6 +44,8 @@ export interface TextDocument {
|
|
|
44
44
|
positionAt(offset: number): Position;
|
|
45
45
|
offsetAt(position: Position): number;
|
|
46
46
|
lineAt(offset: number): TextDocumentLine;
|
|
47
|
+
getLine(lineNum: number): TextDocumentLine;
|
|
48
|
+
getLines(): Iterable<TextDocumentLine>;
|
|
47
49
|
}
|
|
48
50
|
export interface CreateTextDocumentParams {
|
|
49
51
|
uri: DocumentUri | string;
|
|
@@ -58,4 +60,5 @@ export interface TextDocumentContentChangeEvent {
|
|
|
58
60
|
}
|
|
59
61
|
export declare function createTextDocument({ uri, content, languageId, locale, version, }: CreateTextDocumentParams): TextDocument;
|
|
60
62
|
export declare function updateTextDocument(doc: TextDocument, edits: TextDocumentContentChangeEvent[], version?: number): TextDocument;
|
|
63
|
+
export declare const isTextDocument: (doc: TextDocument | unknown) => doc is TextDocument;
|
|
61
64
|
//# sourceMappingURL=TextDocument.d.ts.map
|
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.updateTextDocument = exports.createTextDocument = void 0;
|
|
29
|
+
exports.isTextDocument = exports.updateTextDocument = exports.createTextDocument = void 0;
|
|
30
30
|
const LanguageIds_1 = require("../LanguageIds");
|
|
31
31
|
const Uri = __importStar(require("./Uri"));
|
|
32
32
|
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
|
@@ -53,22 +53,43 @@ class TextDocumentImpl {
|
|
|
53
53
|
}
|
|
54
54
|
lineAt(offset) {
|
|
55
55
|
const position = this.vsTextDoc.positionAt(offset);
|
|
56
|
-
position.
|
|
57
|
-
|
|
56
|
+
return this.getLine(position.line);
|
|
57
|
+
}
|
|
58
|
+
getLine(lineNum) {
|
|
59
|
+
const position = { line: lineNum, character: 0 };
|
|
60
|
+
const end = { line: lineNum + 1, character: 0 };
|
|
58
61
|
const range = {
|
|
59
62
|
start: position,
|
|
60
|
-
end
|
|
63
|
+
end,
|
|
61
64
|
};
|
|
62
|
-
|
|
63
|
-
const
|
|
65
|
+
const lineOffset = this.vsTextDoc.offsetAt(position);
|
|
66
|
+
const text = this.vsTextDoc.getText(range);
|
|
64
67
|
return {
|
|
65
|
-
|
|
66
|
-
return _text !== null && _text !== void 0 ? _text : (_text = getText());
|
|
67
|
-
},
|
|
68
|
+
text,
|
|
68
69
|
offset: lineOffset,
|
|
69
70
|
position,
|
|
70
71
|
};
|
|
71
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Iterate over the lines of a document one-by-one.
|
|
75
|
+
* Changing the document between iterations can change the result
|
|
76
|
+
*/
|
|
77
|
+
*getLines() {
|
|
78
|
+
const range = {
|
|
79
|
+
start: { line: 0, character: 0 },
|
|
80
|
+
end: { line: 1, character: 0 },
|
|
81
|
+
};
|
|
82
|
+
while (this.vsTextDoc.offsetAt(range.end) > this.vsTextDoc.offsetAt(range.start)) {
|
|
83
|
+
const offset = this.vsTextDoc.offsetAt(range.start);
|
|
84
|
+
yield {
|
|
85
|
+
text: this.vsTextDoc.getText(range),
|
|
86
|
+
offset,
|
|
87
|
+
position: range.start,
|
|
88
|
+
};
|
|
89
|
+
++range.start.line;
|
|
90
|
+
++range.end.line;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
72
93
|
/**
|
|
73
94
|
* Apply edits to the text.
|
|
74
95
|
* Note: the edits are applied one after the other.
|
|
@@ -99,8 +120,12 @@ function createTextDocument({ uri, content, languageId, locale, version, }) {
|
|
|
99
120
|
}
|
|
100
121
|
exports.createTextDocument = createTextDocument;
|
|
101
122
|
function updateTextDocument(doc, edits, version) {
|
|
102
|
-
(0, assert_1.default)(doc
|
|
123
|
+
(0, assert_1.default)(isTextDocumentImpl(doc), 'Unknown TextDocument type');
|
|
103
124
|
return doc.update(edits, version);
|
|
104
125
|
}
|
|
105
126
|
exports.updateTextDocument = updateTextDocument;
|
|
127
|
+
function isTextDocumentImpl(doc) {
|
|
128
|
+
return doc instanceof TextDocumentImpl;
|
|
129
|
+
}
|
|
130
|
+
exports.isTextDocument = isTextDocumentImpl;
|
|
106
131
|
//# sourceMappingURL=TextDocument.js.map
|
package/dist/spellCheckFile.js
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.fileToDocument = exports.isBinaryFile = exports.isBinaryDoc = exports.determineFinalDocumentSettings = exports.spellCheckDocument = exports.spellCheckFile = void 0;
|
|
4
|
-
const cspell_glob_1 = require("cspell-glob");
|
|
5
4
|
const fs_extra_1 = require("fs-extra");
|
|
6
5
|
const vscode_uri_1 = require("vscode-uri");
|
|
7
|
-
const determineTextDocumentSettings_1 = require("./textValidation/determineTextDocumentSettings");
|
|
8
6
|
const LanguageIds_1 = require("./LanguageIds");
|
|
9
7
|
const TextDocument_1 = require("./Models/TextDocument");
|
|
10
|
-
const
|
|
8
|
+
const textValidation_1 = require("./textValidation");
|
|
9
|
+
const determineTextDocumentSettings_1 = require("./textValidation/determineTextDocumentSettings");
|
|
11
10
|
const errors_1 = require("./util/errors");
|
|
12
11
|
const util_1 = require("./util/util");
|
|
13
|
-
const validator_1 = require("./validator");
|
|
14
12
|
const defaultEncoding = 'utf8';
|
|
15
13
|
/**
|
|
16
14
|
* Spell Check a file
|
|
@@ -61,64 +59,35 @@ async function spellCheckDocument(document, options, settings) {
|
|
|
61
59
|
}
|
|
62
60
|
exports.spellCheckDocument = spellCheckDocument;
|
|
63
61
|
async function spellCheckFullDocument(document, options, settings) {
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
function catchError(p) {
|
|
72
|
-
return p.catch((error) => {
|
|
73
|
-
addPossibleError(error);
|
|
74
|
-
return undefined;
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
const useSearchForConfig = (!options.noConfigSearch && !settings.noConfigSearch) || options.noConfigSearch === false;
|
|
78
|
-
const pLocalConfig = options.configFile
|
|
79
|
-
? catchError((0, Settings_1.loadConfig)(options.configFile, settings))
|
|
80
|
-
: useSearchForConfig
|
|
81
|
-
? catchError(searchForDocumentConfig(document, settings, settings))
|
|
82
|
-
: undefined;
|
|
83
|
-
const localConfig = await pLocalConfig;
|
|
84
|
-
addPossibleError((_a = localConfig === null || localConfig === void 0 ? void 0 : localConfig.__importRef) === null || _a === void 0 ? void 0 : _a.error);
|
|
85
|
-
if (errors.length) {
|
|
62
|
+
const { uri, text: content, languageId, locale } = document;
|
|
63
|
+
const doc = (0, TextDocument_1.createTextDocument)({ uri, content, languageId, locale });
|
|
64
|
+
const docValOptions = options;
|
|
65
|
+
const docValidator = new textValidation_1.DocumentValidator(doc, docValOptions, settings);
|
|
66
|
+
await docValidator.prepare();
|
|
67
|
+
const prep = docValidator._getPreparations();
|
|
68
|
+
if (docValidator.errors.length) {
|
|
86
69
|
return {
|
|
87
70
|
document,
|
|
88
71
|
options,
|
|
89
|
-
settingsUsed: localConfig || settings,
|
|
90
|
-
localConfigFilepath:
|
|
72
|
+
settingsUsed: (prep === null || prep === void 0 ? void 0 : prep.localConfig) || settings,
|
|
73
|
+
localConfigFilepath: prep === null || prep === void 0 ? void 0 : prep.localConfigFilepath,
|
|
91
74
|
issues: [],
|
|
92
75
|
checked: false,
|
|
93
|
-
errors,
|
|
76
|
+
errors: docValidator.errors,
|
|
94
77
|
};
|
|
95
78
|
}
|
|
96
|
-
const
|
|
97
|
-
const config = localConfig ? (0, Settings_1.mergeSettings)(settings, localConfig) : settings;
|
|
98
|
-
const docSettings = determineFinalDocumentSettings(document, config);
|
|
99
|
-
const uri = vscode_uri_1.URI.parse(document.uri);
|
|
100
|
-
const shouldCheck = !matcher.match(uri.fsPath) && ((_c = docSettings.settings.enabled) !== null && _c !== void 0 ? _c : true);
|
|
101
|
-
const { generateSuggestions, numSuggestions } = options;
|
|
102
|
-
const validateOptions = (0, util_1.clean)({ generateSuggestions, numSuggestions });
|
|
103
|
-
const issues = shouldCheck ? await (0, validator_1.validateText)(document.text, docSettings.settings, validateOptions) : [];
|
|
79
|
+
const issues = docValidator.checkDocument();
|
|
104
80
|
const result = {
|
|
105
81
|
document,
|
|
106
82
|
options,
|
|
107
|
-
settingsUsed:
|
|
108
|
-
localConfigFilepath:
|
|
83
|
+
settingsUsed: docValidator.getFinalizedDocSettings(),
|
|
84
|
+
localConfigFilepath: prep === null || prep === void 0 ? void 0 : prep.localConfigFilepath,
|
|
109
85
|
issues,
|
|
110
|
-
checked:
|
|
86
|
+
checked: docValidator.shouldCheckDocument(),
|
|
111
87
|
errors: undefined,
|
|
112
88
|
};
|
|
113
89
|
return result;
|
|
114
90
|
}
|
|
115
|
-
async function searchForDocumentConfig(document, defaultConfig, pnpSettings) {
|
|
116
|
-
const { uri } = document;
|
|
117
|
-
const u = vscode_uri_1.URI.parse(uri);
|
|
118
|
-
if (u.scheme !== 'file')
|
|
119
|
-
return Promise.resolve(defaultConfig);
|
|
120
|
-
return (0, Settings_1.searchForConfig)(u.fsPath, pnpSettings).then((s) => s || defaultConfig);
|
|
121
|
-
}
|
|
122
91
|
async function readDocument(filename, encoding = defaultEncoding) {
|
|
123
92
|
const text = await (0, fs_extra_1.readFile)(filename, encoding);
|
|
124
93
|
const uri = vscode_uri_1.URI.file(filename).toString();
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { CSpellUserSettings } from '@cspell/cspell-types';
|
|
2
|
+
import { CSpellSettingsInternal } from '../Models/CSpellSettingsInternalDef';
|
|
2
3
|
import { TextDocument } from '../Models/TextDocument';
|
|
4
|
+
import { SpellingDictionaryCollection } from '../SpellingDictionary';
|
|
5
|
+
import { MatchRange } from '../util/TextRange';
|
|
6
|
+
import { ParsedText, SimpleRange } from './parsedText';
|
|
7
|
+
import { LineValidator, ValidationOptions, type LineSegment } from './textValidator';
|
|
3
8
|
import { ValidateTextOptions, ValidationIssue } from './validator';
|
|
4
9
|
export interface DocumentValidatorOptions extends ValidateTextOptions {
|
|
5
10
|
/**
|
|
@@ -41,15 +46,44 @@ export declare class DocumentValidator {
|
|
|
41
46
|
* The amount of time in ms to prepare for validation.
|
|
42
47
|
*/
|
|
43
48
|
get prepTime(): number;
|
|
44
|
-
checkText(range: SimpleRange, _text: string,
|
|
49
|
+
checkText(range: SimpleRange, _text: string, scope: string[]): ValidationIssue[];
|
|
50
|
+
check(parsedText: ParsedText): ValidationIssue[];
|
|
51
|
+
checkDocument(forceCheck?: boolean): ValidationIssue[];
|
|
45
52
|
get document(): TextDocument;
|
|
46
53
|
updateDocumentText(text: string): void;
|
|
54
|
+
private checkDocumentLines;
|
|
47
55
|
private addPossibleError;
|
|
48
56
|
private catchError;
|
|
49
57
|
private errorCatcherWrapper;
|
|
50
58
|
private suggest;
|
|
51
59
|
private genSuggestions;
|
|
60
|
+
getFinalizedDocSettings(): CSpellSettingsInternal;
|
|
61
|
+
/**
|
|
62
|
+
* Returns true if the final result of the configuration calculation results
|
|
63
|
+
* in the document being enabled. Note: in some cases, checking the document
|
|
64
|
+
* might still make sense, for example, the `@cspell/eslint-plugin` relies on
|
|
65
|
+
* `eslint` configuration to make that determination.
|
|
66
|
+
* @returns true if the document settings have resolved to be `enabled`
|
|
67
|
+
*/
|
|
68
|
+
shouldCheckDocument(): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Internal `cspell-lib` use.
|
|
71
|
+
*/
|
|
72
|
+
_getPreparations(): Preparations | undefined;
|
|
73
|
+
}
|
|
74
|
+
interface Preparations {
|
|
75
|
+
/** loaded config */
|
|
76
|
+
config: CSpellSettingsInternal;
|
|
77
|
+
dictionary: SpellingDictionaryCollection;
|
|
78
|
+
/** configuration after applying in-doc settings */
|
|
79
|
+
docSettings: CSpellSettingsInternal;
|
|
80
|
+
includeRanges: MatchRange[];
|
|
81
|
+
lineValidator: LineValidator;
|
|
82
|
+
segmenter: (lineSegment: LineSegment) => LineSegment[];
|
|
83
|
+
shouldCheck: boolean;
|
|
84
|
+
validateOptions: ValidationOptions;
|
|
85
|
+
localConfig: CSpellUserSettings | undefined;
|
|
86
|
+
localConfigFilepath: string | undefined;
|
|
52
87
|
}
|
|
53
|
-
export
|
|
54
|
-
export declare type SimpleRange = readonly [Offset, Offset];
|
|
88
|
+
export {};
|
|
55
89
|
//# sourceMappingURL=docValidator.d.ts.map
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.DocumentValidator = void 0;
|
|
7
7
|
const cspell_pipe_1 = require("@cspell/cspell-pipe");
|
|
8
8
|
const assert_1 = __importDefault(require("assert"));
|
|
9
|
+
const cspell_glob_1 = require("cspell-glob");
|
|
9
10
|
const TextDocument_1 = require("../Models/TextDocument");
|
|
10
11
|
const Settings_1 = require("../Settings");
|
|
11
12
|
const configLoader_1 = require("../Settings/configLoader");
|
|
@@ -18,6 +19,7 @@ const util_1 = require("../util/util");
|
|
|
18
19
|
const determineTextDocumentSettings_1 = require("./determineTextDocumentSettings");
|
|
19
20
|
const textValidator_1 = require("./textValidator");
|
|
20
21
|
const validator_1 = require("./validator");
|
|
22
|
+
const ERROR_NOT_PREPARED = 'Validator Must be prepared before calling this function.';
|
|
21
23
|
class DocumentValidator {
|
|
22
24
|
/**
|
|
23
25
|
* @param doc - Document to validate
|
|
@@ -37,7 +39,7 @@ class DocumentValidator {
|
|
|
37
39
|
return this._ready;
|
|
38
40
|
}
|
|
39
41
|
prepareSync() {
|
|
40
|
-
var _a, _b;
|
|
42
|
+
var _a, _b, _c;
|
|
41
43
|
// @todo
|
|
42
44
|
// Determine doc settings.
|
|
43
45
|
// Calc include ranges
|
|
@@ -57,7 +59,9 @@ class DocumentValidator {
|
|
|
57
59
|
const config = (0, Settings_1.mergeSettings)(settings, localConfig);
|
|
58
60
|
const docSettings = (0, determineTextDocumentSettings_1.determineTextDocumentSettings)(this._document, config);
|
|
59
61
|
const dict = (0, SpellingDictionary_1.getDictionaryInternalSync)(docSettings);
|
|
60
|
-
const
|
|
62
|
+
const matcher = new cspell_glob_1.GlobMatcher((localConfig === null || localConfig === void 0 ? void 0 : localConfig.ignorePaths) || [], { root: process.cwd(), dot: true });
|
|
63
|
+
const uri = this._document.uri;
|
|
64
|
+
const shouldCheck = !matcher.match(uri.fsPath) && ((_b = docSettings.enabled) !== null && _b !== void 0 ? _b : true);
|
|
61
65
|
const finalSettings = (0, Settings_1.finalizeSettings)(docSettings);
|
|
62
66
|
const validateOptions = (0, validator_1.settingsToValidateOptions)(finalSettings);
|
|
63
67
|
const includeRanges = (0, textValidator_1.calcTextInclusionRanges)(this._document.text, validateOptions);
|
|
@@ -72,6 +76,8 @@ class DocumentValidator {
|
|
|
72
76
|
includeRanges,
|
|
73
77
|
segmenter,
|
|
74
78
|
lineValidator,
|
|
79
|
+
localConfig,
|
|
80
|
+
localConfigFilepath: (_c = localConfig === null || localConfig === void 0 ? void 0 : localConfig.__importRef) === null || _c === void 0 ? void 0 : _c.filename,
|
|
75
81
|
};
|
|
76
82
|
this._ready = true;
|
|
77
83
|
this._preparationTime = timer.elapsed();
|
|
@@ -86,7 +92,7 @@ class DocumentValidator {
|
|
|
86
92
|
return this._prepared;
|
|
87
93
|
}
|
|
88
94
|
async _prepareAsync() {
|
|
89
|
-
var _a, _b;
|
|
95
|
+
var _a, _b, _c;
|
|
90
96
|
(0, assert_1.default)(!this._ready);
|
|
91
97
|
const timer = (0, timer_1.createTimer)();
|
|
92
98
|
const { options, settings } = this;
|
|
@@ -101,7 +107,9 @@ class DocumentValidator {
|
|
|
101
107
|
const config = (0, Settings_1.mergeSettings)(settings, localConfig);
|
|
102
108
|
const docSettings = (0, determineTextDocumentSettings_1.determineTextDocumentSettings)(this._document, config);
|
|
103
109
|
const dict = await (0, SpellingDictionary_1.getDictionaryInternal)(docSettings);
|
|
104
|
-
const
|
|
110
|
+
const matcher = new cspell_glob_1.GlobMatcher((localConfig === null || localConfig === void 0 ? void 0 : localConfig.ignorePaths) || [], { root: process.cwd(), dot: true });
|
|
111
|
+
const uri = this._document.uri;
|
|
112
|
+
const shouldCheck = !matcher.match(uri.fsPath) && ((_b = docSettings.enabled) !== null && _b !== void 0 ? _b : true);
|
|
105
113
|
const finalSettings = (0, Settings_1.finalizeSettings)(docSettings);
|
|
106
114
|
const validateOptions = (0, validator_1.settingsToValidateOptions)(finalSettings);
|
|
107
115
|
const includeRanges = (0, textValidator_1.calcTextInclusionRanges)(this._document.text, validateOptions);
|
|
@@ -116,16 +124,18 @@ class DocumentValidator {
|
|
|
116
124
|
includeRanges,
|
|
117
125
|
segmenter,
|
|
118
126
|
lineValidator,
|
|
127
|
+
localConfig,
|
|
128
|
+
localConfigFilepath: (_c = localConfig === null || localConfig === void 0 ? void 0 : localConfig.__importRef) === null || _c === void 0 ? void 0 : _c.filename,
|
|
119
129
|
};
|
|
120
130
|
this._ready = true;
|
|
121
131
|
this._preparationTime = timer.elapsed();
|
|
122
132
|
}
|
|
123
133
|
_updatePrep() {
|
|
124
134
|
var _a;
|
|
125
|
-
(0, assert_1.default)(this._preparations);
|
|
135
|
+
(0, assert_1.default)(this._preparations, ERROR_NOT_PREPARED);
|
|
126
136
|
const timer = (0, timer_1.createTimer)();
|
|
127
|
-
const
|
|
128
|
-
const docSettings = (0, determineTextDocumentSettings_1.determineTextDocumentSettings)(this._document, config);
|
|
137
|
+
const prep = this._preparations;
|
|
138
|
+
const docSettings = (0, determineTextDocumentSettings_1.determineTextDocumentSettings)(this._document, prep.config);
|
|
129
139
|
const dict = (0, SpellingDictionary_1.getDictionaryInternalSync)(docSettings);
|
|
130
140
|
const shouldCheck = (_a = docSettings.enabled) !== null && _a !== void 0 ? _a : true;
|
|
131
141
|
const finalSettings = (0, Settings_1.finalizeSettings)(docSettings);
|
|
@@ -134,7 +144,7 @@ class DocumentValidator {
|
|
|
134
144
|
const segmenter = (0, textValidator_1.mapLineSegmentAgainstRangesFactory)(includeRanges);
|
|
135
145
|
const lineValidator = (0, textValidator_1.lineValidatorFactory)(dict, validateOptions);
|
|
136
146
|
this._preparations = {
|
|
137
|
-
|
|
147
|
+
...prep,
|
|
138
148
|
dictionary: dict,
|
|
139
149
|
docSettings,
|
|
140
150
|
shouldCheck,
|
|
@@ -151,16 +161,19 @@ class DocumentValidator {
|
|
|
151
161
|
get prepTime() {
|
|
152
162
|
return this._preparationTime;
|
|
153
163
|
}
|
|
154
|
-
checkText(range, _text,
|
|
164
|
+
checkText(range, _text, scope) {
|
|
165
|
+
const text = this._document.text.slice(range[0], range[1]);
|
|
166
|
+
return this.check({ text, range, scope });
|
|
167
|
+
}
|
|
168
|
+
check(parsedText) {
|
|
155
169
|
(0, assert_1.default)(this._ready);
|
|
156
|
-
(0, assert_1.default)(this._preparations);
|
|
170
|
+
(0, assert_1.default)(this._preparations, ERROR_NOT_PREPARED);
|
|
171
|
+
const { range, text } = parsedText;
|
|
157
172
|
const { segmenter, lineValidator } = this._preparations;
|
|
158
173
|
// Determine settings for text range
|
|
159
174
|
// Slice text based upon include ranges
|
|
160
175
|
// Check text against dictionaries.
|
|
161
176
|
const offset = range[0];
|
|
162
|
-
const offsetEnd = range[1];
|
|
163
|
-
const text = this._document.text.slice(offset, offsetEnd);
|
|
164
177
|
const line = this._document.lineAt(offset);
|
|
165
178
|
const lineSeg = {
|
|
166
179
|
line,
|
|
@@ -182,6 +195,11 @@ class DocumentValidator {
|
|
|
182
195
|
});
|
|
183
196
|
return withSugs;
|
|
184
197
|
}
|
|
198
|
+
checkDocument(forceCheck = false) {
|
|
199
|
+
(0, assert_1.default)(this._ready);
|
|
200
|
+
(0, assert_1.default)(this._preparations, ERROR_NOT_PREPARED);
|
|
201
|
+
return forceCheck || this.shouldCheckDocument() ? [...this.checkDocumentLines()] : [];
|
|
202
|
+
}
|
|
185
203
|
get document() {
|
|
186
204
|
return this._document;
|
|
187
205
|
}
|
|
@@ -189,6 +207,26 @@ class DocumentValidator {
|
|
|
189
207
|
(0, TextDocument_1.updateTextDocument)(this._document, [{ text }]);
|
|
190
208
|
this._updatePrep();
|
|
191
209
|
}
|
|
210
|
+
*checkDocumentLines() {
|
|
211
|
+
(0, assert_1.default)(this._preparations, ERROR_NOT_PREPARED);
|
|
212
|
+
const { maxNumberOfProblems = textValidator_1.defaultMaxNumberOfProblems, maxDuplicateProblems = textValidator_1.defaultMaxDuplicateProblems } = this._preparations.validateOptions;
|
|
213
|
+
let numProblems = 0;
|
|
214
|
+
const mapOfProblems = new Map();
|
|
215
|
+
for (const line of this.document.getLines()) {
|
|
216
|
+
const { text, offset } = line;
|
|
217
|
+
const range = [offset, offset + text.length];
|
|
218
|
+
for (const issue of this.check({ text, range })) {
|
|
219
|
+
const { text } = issue;
|
|
220
|
+
const n = (mapOfProblems.get(text) || 0) + 1;
|
|
221
|
+
mapOfProblems.set(text, n);
|
|
222
|
+
if (n > maxDuplicateProblems)
|
|
223
|
+
continue;
|
|
224
|
+
yield issue;
|
|
225
|
+
if (++numProblems >= maxNumberOfProblems)
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
192
230
|
addPossibleError(error) {
|
|
193
231
|
if (!error)
|
|
194
232
|
return;
|
|
@@ -214,7 +252,7 @@ class DocumentValidator {
|
|
|
214
252
|
}
|
|
215
253
|
genSuggestions(text) {
|
|
216
254
|
var _a;
|
|
217
|
-
(0, assert_1.default)(this._preparations);
|
|
255
|
+
(0, assert_1.default)(this._preparations, ERROR_NOT_PREPARED);
|
|
218
256
|
const settings = this._preparations.docSettings;
|
|
219
257
|
const dict = this._preparations.dictionary;
|
|
220
258
|
const sugOptions = (0, util_1.clean)({
|
|
@@ -227,6 +265,28 @@ class DocumentValidator {
|
|
|
227
265
|
});
|
|
228
266
|
return dict.suggest(text, sugOptions).map((r) => r.word);
|
|
229
267
|
}
|
|
268
|
+
getFinalizedDocSettings() {
|
|
269
|
+
(0, assert_1.default)(this._ready);
|
|
270
|
+
(0, assert_1.default)(this._preparations, ERROR_NOT_PREPARED);
|
|
271
|
+
return this._preparations.docSettings;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Returns true if the final result of the configuration calculation results
|
|
275
|
+
* in the document being enabled. Note: in some cases, checking the document
|
|
276
|
+
* might still make sense, for example, the `@cspell/eslint-plugin` relies on
|
|
277
|
+
* `eslint` configuration to make that determination.
|
|
278
|
+
* @returns true if the document settings have resolved to be `enabled`
|
|
279
|
+
*/
|
|
280
|
+
shouldCheckDocument() {
|
|
281
|
+
(0, assert_1.default)(this._preparations, ERROR_NOT_PREPARED);
|
|
282
|
+
return this._preparations.shouldCheck;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Internal `cspell-lib` use.
|
|
286
|
+
*/
|
|
287
|
+
_getPreparations() {
|
|
288
|
+
return this._preparations;
|
|
289
|
+
}
|
|
230
290
|
}
|
|
231
291
|
exports.DocumentValidator = DocumentValidator;
|
|
232
292
|
async function searchForDocumentConfig(document, defaultConfig, pnpSettings) {
|
|
@@ -4,4 +4,5 @@ export { checkText, IncludeExcludeFlag, validateText } from './validator';
|
|
|
4
4
|
export type { CheckTextInfo, TextInfoItem, ValidateTextOptions, ValidationIssue } from './validator';
|
|
5
5
|
export { DocumentValidator } from './docValidator';
|
|
6
6
|
export type { DocumentValidatorOptions } from './docValidator';
|
|
7
|
+
export type { Offset, SimpleRange, ParsedText } from './parsedText';
|
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ValidationIssue } from './validator';
|
|
2
|
+
export declare type Offset = number;
|
|
3
|
+
export declare type SimpleRange = readonly [Offset, Offset];
|
|
4
|
+
export interface ParsedText {
|
|
5
|
+
/**
|
|
6
|
+
* Transformed text
|
|
7
|
+
*/
|
|
8
|
+
text: string;
|
|
9
|
+
/**
|
|
10
|
+
* Offset pair of the original text
|
|
11
|
+
*/
|
|
12
|
+
range: SimpleRange;
|
|
13
|
+
/**
|
|
14
|
+
* Relative map to the original text.
|
|
15
|
+
*/
|
|
16
|
+
map?: number[];
|
|
17
|
+
scope?: string[];
|
|
18
|
+
}
|
|
19
|
+
export declare function mapIssueBackToOriginalPos(parsedText: ParsedText, issue: ValidationIssue): ValidationIssue;
|
|
20
|
+
export declare function mapRangeBackToOriginalPos(offRange: SimpleRange, map: number[]): SimpleRange;
|
|
21
|
+
//# sourceMappingURL=parsedText.d.ts.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapRangeBackToOriginalPos = exports.mapIssueBackToOriginalPos = void 0;
|
|
4
|
+
function mapIssueBackToOriginalPos(parsedText, issue) {
|
|
5
|
+
if (!parsedText.map || parsedText.map.length === 0)
|
|
6
|
+
return issue;
|
|
7
|
+
const textOff = mapTextOffsetBackToOriginalPos(parsedText, issue);
|
|
8
|
+
return {
|
|
9
|
+
...issue,
|
|
10
|
+
...textOff,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
exports.mapIssueBackToOriginalPos = mapIssueBackToOriginalPos;
|
|
14
|
+
function mapTextOffsetBackToOriginalPos(parsedText, textOff) {
|
|
15
|
+
var _a;
|
|
16
|
+
if (!parsedText.map || !parsedText.map.length)
|
|
17
|
+
return textOff;
|
|
18
|
+
const off = textOff.offset - parsedText.range[0];
|
|
19
|
+
const range = mapRangeBackToOriginalPos([off, off + ((_a = textOff.length) !== null && _a !== void 0 ? _a : textOff.text.length)], parsedText.map);
|
|
20
|
+
return {
|
|
21
|
+
text: textOff.text,
|
|
22
|
+
offset: parsedText.range[0] + range[0],
|
|
23
|
+
length: range[1] - range[0],
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function mapRangeBackToOriginalPos(offRange, map) {
|
|
27
|
+
if (!map || !map.length)
|
|
28
|
+
return offRange;
|
|
29
|
+
const [start, end] = offRange;
|
|
30
|
+
let i = 0, j = 0, p = 1;
|
|
31
|
+
while (p < map.length && map[p] < start) {
|
|
32
|
+
i = map[p - 1];
|
|
33
|
+
j = map[p];
|
|
34
|
+
p += 2;
|
|
35
|
+
}
|
|
36
|
+
const iA = start - j + i;
|
|
37
|
+
while (p < map.length && map[p] < end) {
|
|
38
|
+
i = map[p - 1];
|
|
39
|
+
j = map[p];
|
|
40
|
+
p += 2;
|
|
41
|
+
}
|
|
42
|
+
const iB = end - j + i;
|
|
43
|
+
return [iA, iB];
|
|
44
|
+
}
|
|
45
|
+
exports.mapRangeBackToOriginalPos = mapRangeBackToOriginalPos;
|
|
46
|
+
//# sourceMappingURL=parsedText.js.map
|
package/dist/util/logger.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cspell-lib",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.1.1",
|
|
4
4
|
"description": "A library of useful functions used across various cspell tools.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -48,24 +48,24 @@
|
|
|
48
48
|
},
|
|
49
49
|
"homepage": "https://github.com/streetsidesoftware/cspell#readme",
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@cspell/cspell-bundled-dicts": "^6.
|
|
52
|
-
"@cspell/cspell-pipe": "^6.
|
|
53
|
-
"@cspell/cspell-types": "^6.
|
|
51
|
+
"@cspell/cspell-bundled-dicts": "^6.1.1",
|
|
52
|
+
"@cspell/cspell-pipe": "^6.1.1",
|
|
53
|
+
"@cspell/cspell-types": "^6.1.1",
|
|
54
54
|
"clear-module": "^4.1.2",
|
|
55
55
|
"comment-json": "^4.2.2",
|
|
56
56
|
"configstore": "^5.0.1",
|
|
57
57
|
"cosmiconfig": "^7.0.1",
|
|
58
|
-
"cspell-glob": "^6.
|
|
59
|
-
"cspell-io": "^6.
|
|
60
|
-
"cspell-trie-lib": "^6.
|
|
61
|
-
"fast-equals": "^3.0.
|
|
58
|
+
"cspell-glob": "^6.1.1",
|
|
59
|
+
"cspell-io": "^6.1.1",
|
|
60
|
+
"cspell-trie-lib": "^6.1.1",
|
|
61
|
+
"fast-equals": "^3.0.3",
|
|
62
62
|
"find-up": "^5.0.0",
|
|
63
63
|
"fs-extra": "^10.1.0",
|
|
64
64
|
"gensequence": "^3.1.1",
|
|
65
65
|
"import-fresh": "^3.3.0",
|
|
66
66
|
"resolve-from": "^5.0.0",
|
|
67
67
|
"resolve-global": "^1.0.0",
|
|
68
|
-
"vscode-languageserver-textdocument": "^1.0.
|
|
68
|
+
"vscode-languageserver-textdocument": "^1.0.5",
|
|
69
69
|
"vscode-uri": "^3.0.3"
|
|
70
70
|
},
|
|
71
71
|
"engines": {
|
|
@@ -83,14 +83,14 @@
|
|
|
83
83
|
"@types/configstore": "^5.0.1",
|
|
84
84
|
"@types/fs-extra": "^9.0.13",
|
|
85
85
|
"@types/jest": "^27.5.1",
|
|
86
|
-
"@types/node": "^17.0.
|
|
86
|
+
"@types/node": "^17.0.36",
|
|
87
87
|
"cspell-dict-nl-nl": "^1.1.2",
|
|
88
88
|
"jest": "^28.1.0",
|
|
89
89
|
"lorem-ipsum": "^2.0.4",
|
|
90
90
|
"rimraf": "^3.0.2",
|
|
91
|
-
"rollup": "^2.
|
|
92
|
-
"rollup-plugin-dts": "^4.2.
|
|
93
|
-
"ts-jest": "^28.0.
|
|
91
|
+
"rollup": "^2.75.4",
|
|
92
|
+
"rollup-plugin-dts": "^4.2.2",
|
|
93
|
+
"ts-jest": "^28.0.3"
|
|
94
94
|
},
|
|
95
|
-
"gitHead": "
|
|
95
|
+
"gitHead": "e871153bfebefa19b13754b431ce5e49a63da298"
|
|
96
96
|
}
|