Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function validateTextDocumentAsync(textDocument: TextDocument, options: CSpellUserSettings): Promise> {
const { diagnosticLevel = DiagnosticSeverity.Information.toString() } = options;
const severity = diagSeverityMap.get(diagnosticLevel.toLowerCase()) || DiagnosticSeverity.Information;
const limit = (options.checkLimit || defaultCheckLimit) * 1024;
const text = textDocument.getText().slice(0, limit);
const diags = genSequence(await validateText(text, options))
// Convert the offset into a position
.map(offsetWord => ({...offsetWord, position: textDocument.positionAt(offsetWord.offset) }))
// Calculate the range
.map(word => ({
...word,
range: {
start: word.position,
end: ({...word.position, character: word.position.character + word.text.length })
}
}))
// Convert it to a Diagnostic
.map(({text, range}) => ({
severity,
range: range,
message: `"${text}": Unknown word.`,
source: diagSource
languageId: cfg.options.languageId || undefined,
language: cfg.local || undefined,
});
const { filename, text } = fileInfo;
const info = calcFinalConfigInfo(configInfo, settingsFromCommandLine, filename, text);
const config = info.configInfo.config;
const source = info.configInfo.source;
cfg.debug(`Filename: ${filename}, Extension: ${path.extname(filename)}, LanguageIds: ${info.languageIds.toString()}`);
if (!info.configInfo.config.enabled) return 0;
const debugCfg = { config: {...config, source: null}, source };
cfg.debug(commentJson.stringify(debugCfg, undefined, 2));
const startTime = Date.now();
const wordOffsets = await cspell.validateText(text, info.configInfo.config);
const issues = cspell.Text.calculateTextDocumentOffsets(filename, text, wordOffsets);
const elapsed = (Date.now() - startTime) / 1000.0;
const dictionaries = config.dictionaries || [];
cfg.info(
`Checking: ${filename}, File type: ${config.languageId}, Language: ${config.language} ... Issues: ${issues.length} ${elapsed}S`,
MessageTypes.Info
);
cfg.info(`Dictionaries Used: ${dictionaries.join(', ')}`, MessageTypes.Info);
issues
.filter(cfg.uniqueFilter)
.forEach((issue) => cfg.logIssue(issue));
return issues.length;
}