Dictionary configuration types for managing built-in and custom dictionaries, including inline dictionaries and replacement mappings.
Core dictionary definition types that support various dictionary formats and sources.
/**
* Union of all supported dictionary definition types
*/
type DictionaryDefinition =
| DictionaryDefinitionPreferred
| DictionaryDefinitionCustom
| DictionaryDefinitionAugmented
| DictionaryDefinitionSimple
| DictionaryDefinitionInline
| DictionaryDefinitionAlternate
| DictionaryDefinitionLegacy;
/**
* Base interface for all dictionary definitions
*/
interface DictionaryDefinitionBase {
/** Unique dictionary identifier */
name: DictionaryId;
/** Human-readable description */
description?: string;
/** File type indicators */
type?: DictionaryFileTypes;
/** Replacement mappings for words */
repMap?: ReplaceMap;
/** Custom suggestion costs */
suggestionCosts?: SuggestionCostMapDef;
/** Include NoSuggest flag words */
noSuggest?: boolean;
/** Use compounds */
useCompounds?: boolean;
}Standard dictionary definition pointing to a file path.
/**
* Standard dictionary with file path reference
* This is the most common dictionary definition type
*/
interface DictionaryDefinitionPreferred extends DictionaryDefinitionBase {
/** Path to dictionary file */
path: DictionaryPath;
}
/**
* Dictionary with additional metadata and caching info
*/
interface DictionaryDefinitionAugmented extends DictionaryDefinitionPreferred {
/** File modification time for caching */
mtime?: number;
/** File size for validation */
size?: number;
/** Dictionary format version */
version?: string;
}User-editable dictionary definition for project-specific dictionaries.
/**
* User-editable custom dictionary definition
*/
interface DictionaryDefinitionCustom extends DictionaryDefinitionBase {
/** Path to custom dictionary file */
path: CustomDictionaryPath;
/** Scope where custom dictionary applies */
scope?: CustomDictionaryScope;
/** Whether dictionary can be modified */
addWords?: boolean;
}
/**
* Simple dictionary definition with minimal configuration
*/
interface DictionaryDefinitionSimple extends DictionaryDefinitionBase {
/** Dictionary file path */
file: string;
}Dictionary definitions with words defined directly in configuration.
/**
* Union of all inline dictionary types
*/
type DictionaryDefinitionInline =
| DictionaryDefinitionInlineWords
| DictionaryDefinitionInlineFlagWords
| DictionaryDefinitionInlineIgnoreWords;
/**
* Inline dictionary with word list
*/
interface DictionaryDefinitionInlineWords extends DictionaryDefinitionBase {
/** List of words to include */
words: string[];
}
/**
* Inline dictionary with flagged (forbidden) words
*/
interface DictionaryDefinitionInlineFlagWords extends DictionaryDefinitionBase {
/** List of words to flag as incorrect */
flagWords: string[];
}
/**
* Inline dictionary with words to ignore
*/
interface DictionaryDefinitionInlineIgnoreWords extends DictionaryDefinitionBase {
/** List of words to ignore during spell checking */
ignoreWords: string[];
}Deprecated dictionary definition formats maintained for backward compatibility.
/**
* Alternative dictionary format (deprecated)
* @deprecated Use DictionaryDefinitionPreferred instead
*/
interface DictionaryDefinitionAlternate extends DictionaryDefinitionBase {
/** Dictionary file path */
file: string;
/** Dictionary format */
format?: string;
}
/**
* Legacy dictionary format (deprecated)
* @deprecated Use DictionaryDefinitionPreferred instead
*/
interface DictionaryDefinitionLegacy extends DictionaryDefinitionBase {
/** Dictionary file path */
file: string;
}Types for referencing dictionaries in configuration.
/**
* Dictionary reference (positive or negative)
*/
type DictionaryReference = DictionaryRef | DictionaryNegRef;
/**
* Positive dictionary reference (include dictionary)
*/
type DictionaryRef = DictionaryId;
/**
* Negative dictionary reference (exclude dictionary)
*/
type DictionaryNegRef = `!${DictionaryId}`;
/**
* Dictionary identifier string
*/
type DictionaryId = string;Path types for different dictionary locations and sources.
/**
* General dictionary file path
*/
type DictionaryPath = string;
/**
* Custom dictionary file path (user-editable)
*/
type CustomDictionaryPath = string;
/**
* Scope for custom dictionary application
*/
type CustomDictionaryScope = "user" | "workspace" | "folder";File type indicators for different dictionary formats.
/**
* Dictionary file type indicators
* S = Sorted, W = Words, C = Compound, T = Trie
*/
type DictionaryFileTypes = "S" | "W" | "C" | "T";Word replacement and mapping configuration for dictionaries.
/**
* Word replacement mapping
*/
type ReplaceMap = ReplaceEntry[];
/**
* Single replacement entry mapping incorrect to correct word(s)
*/
type ReplaceEntry = [string, string] | [string, string[]];Comprehensive metadata and linguistic information for dictionaries.
/**
* Comprehensive dictionary metadata and linguistic configuration
*/
interface DictionaryInformation {
/** Dictionary locale/language */
locale: string;
/** Character set used by dictionary */
characterSet?: CharacterSet;
/** Hunspell dictionary information */
hunspellInformation?: HunspellInformation;
/** Costs for spelling suggestions */
costs?: EditCosts;
/** Accent sensitivity */
accentSensitive?: boolean;
/** Case sensitivity */
caseSensitive?: boolean;
/** Additional dictionary properties */
[key: string]: any;
}
/**
* Character set definition for dictionary
*/
type CharacterSet = string;
/**
* Hunspell dictionary support information
*/
interface HunspellInformation {
/** Path to .aff file */
aff: string;
/** Path to .dic file */
dic: string;
/** Hunspell version compatibility */
version?: string;
}
/**
* Cost configuration for spelling suggestions
*/
interface EditCosts {
/** Character set specific costs */
characterSet?: CharacterSetCosts;
/** Pattern-based adjustments */
patterns?: PatternAdjustment[];
/** Base edit costs */
baseCost?: number;
/** First character cost multiplier */
firstCharacterCost?: number;
}
/**
* Character set cost configuration
*/
interface CharacterSetCosts {
/** Insertion costs by character */
insertCosts?: Record<string, number>;
/** Deletion costs by character */
deleteCosts?: Record<string, number>;
/** Substitution costs by character pair */
substituteCosts?: Record<string, Record<string, number>>;
/** Swap costs by character pair */
swapCosts?: Record<string, Record<string, number>>;
}
/**
* Pattern-based suggestion cost adjustment
*/
interface PatternAdjustment {
/** Pattern to match */
pattern: string | IRegExp;
/** Cost adjustment */
cost: number;
}
/**
* Regular expression type alias
*/
type IRegExp = RegExp;import type { CSpellUserSettings, DictionaryDefinition } from "@cspell/cspell-types";
// Using built-in dictionaries
const config: CSpellUserSettings = {
dictionaries: ["typescript", "node", "npm"]
};
// Custom dictionary definition
const customDict: DictionaryDefinition = {
name: "project-terms",
path: "./dictionaries/project-terms.txt",
description: "Project-specific terminology"
};
// Advanced configuration with custom dictionary
const advancedConfig: CSpellUserSettings = {
dictionaryDefinitions: [customDict],
dictionaries: ["typescript", "project-terms"],
overrides: [
{
filename: "**/*.md",
dictionaries: ["typescript", "project-terms", "markdown"]
}
]
};import type { DictionaryDefinitionInlineWords } from "@cspell/cspell-types";
// Inline dictionary with words
const inlineDict: DictionaryDefinitionInlineWords = {
name: "inline-words",
words: ["TypeScript", "JavaScript", "ESLint", "Prettier"]
};
// Configuration with inline dictionary
const configWithInline: CSpellUserSettings = {
dictionaryDefinitions: [inlineDict],
dictionaries: ["inline-words"]
};