Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'cspell-lib' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
[key in keyof Api.ServerMethodRequestResult]: (param: Api.ServerRequestMethodRequests[key]) => RequestResult;
};
const notifyMethodNames: Api.NotifyServerMethodConstants = {
onConfigChange: 'onConfigChange',
registerConfigurationFile: 'registerConfigurationFile',
};
const tds = CSpell;
const defaultCheckLimit = Validator.defaultCheckLimit;
// Turn off the spell checker by default. The setting files should have it set.
// This prevents the spell checker from running too soon.
const defaultSettings: CSpellUserSettings = {
...CSpell.mergeSettings(getDefaultSettings(), CSpell.getGlobalSettings()),
checkLimit: defaultCheckLimit,
enabled: false,
};
const defaultDebounce = 50;
function run() {
// debounce buffer
const validationRequestStream = new ReplaySubject(1);
const triggerUpdateConfig = new ReplaySubject(1);
const triggerValidateAll = new ReplaySubject(1);
const validationByDoc = new Map();
const blockValidation = new Map();
let isValidationBusy = false;
const disposables: Disposable[] = [];
const requestMethodApi: RequestMethodApi = {
async function run(): Promise {
header();
const configFiles = (await globP(cfg.configGlob, cfg.configGlobOptions)).filter(util.uniqueFn());
cfg.info(`Config Files Found:\n ${configFiles.join('\n ')}\n`, MessageTypes.Info);
const config = cspell.readSettingsFiles(configFiles);
const configInfo: ConfigInfo = { source: configFiles.join(' || '), config };
// Get Exclusions from the config files.
const { root } = cfg;
const globOptions = { root, cwd: root };
const exclusionGlobs = extractGlobExcludesFromConfig(root, configInfo.source, configInfo.config).concat(cfg.excludes);
const files = filterFiles(await findFiles(cfg.files, globOptions), exclusionGlobs);
return processFiles(fileLoader(files), configInfo);
}
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
async genSuggestions(doc: DocInfo, word: string): Promise {
const { settings, dictionary } = await this.getSettings(doc);
const { numSuggestions = defaultNumSuggestions } = settings;
if (word.length > maxWordLengthForSuggestions) {
return [];
}
const numSugs = word.length > wordLengthForLimitingSuggestions ? maxNumberOfSuggestionsForLongWords : numSuggestions;
const options: SuggestOptions = {
numChanges: maxEdits,
numSuggestions: numSugs,
// Turn off compound suggestions for now until it works a bit better.
compoundMethod: CompoundWordsMethod.NONE,
ignoreCase: !settings.caseSensitive,
};
return dictionary.suggest(word, options).map(s => ({...s, word: s.word.replace(regexJoinedWords, '')}));
}
function calcFinalConfigInfo(
configInfo: ConfigInfo,
settingsFromCommandLine: cspell.CSpellUserSettings,
filename: string,
text: string
): FileConfigInfo {
const ext = path.extname(filename);
const fileSettings = cspell.calcOverrideSettings(configInfo.config, path.resolve(filename));
const settings = cspell.mergeSettings(cspell.getDefaultSettings(), cspell.getGlobalSettings(), fileSettings, settingsFromCommandLine);
const languageIds = settings.languageId ? [settings.languageId] : cspell.getLanguagesForExt(ext);
const config = cspell.constructSettingsForText(settings, text, languageIds);
return {configInfo: {...configInfo, config}, filename, text, languageIds};
}
private async fetchUriSettings(uri: string): Promise {
log('Start fetchUriSettings:', uri);
const folder = await this.findMatchingFolder(uri);
const folderSettings = await this.fetchSettingsForUri(folder.uri);
const spellSettings = CSpell.mergeSettings(this.defaultSettings, this.importedSettings(), folderSettings.settings);
const fileUri = Uri.parse(uri);
const fileSettings = CSpell.calcOverrideSettings(spellSettings, fileUri.fsPath);
log('Finish fetchUriSettings:', uri);
return fileSettings;
}
export async function trace(words: string[], options: TraceOptions): Promise {
const configGlob = options.config || defaultConfigGlob;
const configGlobOptions = options.config ? {} : defaultConfigGlobOptions;
const configFiles = (await globP(configGlob, configGlobOptions)).filter(util.uniqueFn());
const config = cspell.mergeSettings(cspell.getDefaultSettings(), cspell.getGlobalSettings(), cspell.readSettingsFiles(configFiles));
const results = await traceWords(words, config);
return results;
}
async function getBaseSettings(doc: TextDocument) {
const settings = await getActiveSettings(doc);
return {...CSpell.mergeSettings(defaultSettings, settings), enabledLanguageIds: settings.enabledLanguageIds};
}
private resolveConfigImports(config: CSpellUserSettings, folderUri: string): CSpellUserSettings {
const uriFsPath = Uri.parse(folderUri).fsPath;
const imports = typeof config.import === 'string' ? [config.import] : config.import || [];
if (!imports.length) {
return config;
}
const importAbsPath = imports.map(file => path.resolve(file, uriFsPath));
return CSpell.mergeSettings(CSpell.readSettingsFiles(importAbsPath), config);
}
}
function readSettingsFiles(paths: string[]) {
log(`readSettingsFiles:`, paths);
const existingPaths = paths.filter(filename => fs.existsSync(filename));
return CSpell.readSettingsFiles(existingPaths);
}