Skip to content

Commit

Permalink
fix: Add trace options (#1939)
Browse files Browse the repository at this point in the history
- `--allow-compound-words`
- `--no-ignore-case`
- `--language-id` - for consistency
  • Loading branch information
Jason3S committed Nov 2, 2021
1 parent fa4ea3f commit 191fc52
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 9 deletions.
8 changes: 8 additions & 0 deletions packages/cspell-lib/samples/cspell.lang.config.json
@@ -0,0 +1,8 @@
{
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json",
"version": "0.2",
"import": [
"@cspell/dict-fr-fr/cspell-ext.json",
"@cspell/dict-nl-nl/cspell-ext.json"
]
}
8 changes: 6 additions & 2 deletions packages/cspell-lib/src/trace.ts
Expand Up @@ -23,21 +23,25 @@ export interface TraceOptions {
languageId?: LanguageId | LanguageId[];
locale?: LocaleId;
ignoreCase?: boolean;
allowCompoundWords?: boolean;
}

export async function traceWords(
words: string[],
settings: CSpellSettings,
options: TraceOptions | undefined
): Promise<TraceResult[]> {
const { languageId, locale: language, ignoreCase = true } = options || {};
const { languageId, locale: language, ignoreCase = true, allowCompoundWords } = options || {};

async function finalize(config: CSpellSettings): Promise<{
activeDictionaries: DictionaryId[];
config: CSpellSettings;
dicts: SpellingDictionaryCollection;
}> {
const withLocale = mergeSettings(config, { language });
const withLocale = mergeSettings(config, {
language,
allowCompoundWords: allowCompoundWords ?? config.allowCompoundWords,
});
const withLanguageId = calcSettingsForLanguageId(
withLocale,
languageId ?? withLocale.languageId ?? 'plaintext'
Expand Down
7 changes: 5 additions & 2 deletions packages/cspell/src/__snapshots__/app.test.ts.snap
Expand Up @@ -564,8 +564,11 @@ Array [
" looks for cspell.json in the current directory.",
" --locale <locale> Set language locales. i.e. \\"en,fr\\" for English",
" and French, or \\"en-GB\\" for British English.",
" --languageId <language> Force programming language for unknown",
" extensions. i.e. \\"php\\" or \\"scala\\"",
" --language-id <language> Use programming language. i.e. \\"php\\" or \\"scala\\"",
" --allow-compound-words Turn on allowCompoundWords",
" --no-allow-compound-words Turn off allowCompoundWords",
" --no-ignore-case Do not ignore case and accents when searching for",
" words",
" --no-color Turn off color.",
" --color Force color",
" -h, --help display help for command",
Expand Down
4 changes: 2 additions & 2 deletions packages/cspell/src/application.ts
Expand Up @@ -19,10 +19,10 @@ export function lint(files: string[], options: CSpellApplicationOptions, emitter

export async function trace(words: string[], options: TraceOptions): Promise<TraceResult[]> {
const { local } = options;
const { languageId, locale = local } = options;
const { languageId, locale = local, allowCompoundWords, ignoreCase } = options;
const configFile = await readConfig(options.config, undefined);
const config = cspell.mergeSettings(cspell.getDefaultSettings(), cspell.getGlobalSettings(), configFile.config);
const results = await traceWords(words, config, { languageId, locale });
const results = await traceWords(words, config, { languageId, locale, ignoreCase, allowCompoundWords });
return results;
}

Expand Down
11 changes: 9 additions & 2 deletions packages/cspell/src/commandTrace.ts
@@ -1,4 +1,4 @@
import { Command } from 'commander';
import { Command, Option as CommanderOption } from 'commander';
import * as App from './application';
import { TraceOptions } from './options';
import { emitTraceResults } from './traceEmitter';
Expand All @@ -23,7 +23,14 @@ export function commandTrace(prog: Command): Command {
'--locale <locale>',
'Set language locales. i.e. "en,fr" for English and French, or "en-GB" for British English.'
)
.option('--languageId <language>', 'Force programming language for unknown extensions. i.e. "php" or "scala"')
.option('--language-id <language>', 'Use programming language. i.e. "php" or "scala"')
.addOption(
new CommanderOption('--languageId <language>', 'Use programming language. i.e. "php" or "scala"').hideHelp()
)
.option('--allow-compound-words', 'Turn on allowCompoundWords')
.addOption(new CommanderOption('--allowCompoundWords', 'Turn on allowCompoundWords').hideHelp())
.option('--no-allow-compound-words', 'Turn off allowCompoundWords')
.option('--no-ignore-case', 'Do not ignore case and accents when searching for words')
.option('--no-color', 'Turn off color.')
.option('--color', 'Force color')
.arguments('<words...>')
Expand Down
5 changes: 4 additions & 1 deletion packages/cspell/src/options.ts
Expand Up @@ -63,7 +63,10 @@ export interface CSpellApplicationOptions extends BaseOptions {
gitignoreRoot?: string | string[];
}

export type TraceOptions = BaseOptions;
export interface TraceOptions extends BaseOptions {
allowCompoundWords?: boolean;
ignoreCase?: boolean;
}

export interface BaseOptions {
config?: string;
Expand Down

0 comments on commit 191fc52

Please sign in to comment.