Skip to content

Commit

Permalink
fix: Add support for custom dictionaries (#982)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S committed Feb 21, 2021
1 parent d18706e commit 196921d
Show file tree
Hide file tree
Showing 3 changed files with 215 additions and 10 deletions.
81 changes: 78 additions & 3 deletions cspell.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,46 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"definitions": {
"CustomDictionaryPath": {
"description": "A File System Path to a dictionary file.",
"pattern": "^.*\\.txt$",
"type": "string"
},
"CustomDictionaryScope": {
"description": "Specifies the scope of a dictionary.",
"enum": [
"user",
"workspace",
"folder"
],
"type": "string"
},
"DictionaryDefinition": {
"anyOf": [
{
"$ref": "#/definitions/DictionaryDefinitionPreferred"
},
{
"$ref": "#/definitions/DictionaryDefinitionCustom"
},
{
"$ref": "#/definitions/DictionaryDefinitionAlternate"
}
]
},
"DictionaryDefinitionAlternate": {
"additionalProperties": false,
"deprecatedMessage": "Use `DictionaryDefinitionPreferred`",
"description": "Only for legacy dictionary definitions",
"properties": {
"description": {
"description": "Optional description",
"type": "string"
},
"file": {
"$ref": "#/definitions/FsPath",
"description": "Path to the file"
"$ref": "#/definitions/DictionaryPath",
"deprecatedMessage": "Use `path` instead.",
"description": "Path to the file, only for legacy dictionary definitions"
},
"name": {
"$ref": "#/definitions/DictionaryId",
Expand All @@ -42,6 +62,56 @@
],
"type": "object"
},
"DictionaryDefinitionCustom": {
"additionalProperties": false,
"description": "For Defining Custom dictionaries. They are generally scoped to a `user`, `workspace`, or `folder`. When `addWords` is true, indicates that the spell checker can add words to the file. Note: only plain text files with one word per line are supported at this moment.",
"properties": {
"addWords": {
"description": "When `true`, let's the spell checker know that words can be added to this dictionary.",
"type": "boolean"
},
"description": {
"description": "Optional description",
"type": "string"
},
"name": {
"$ref": "#/definitions/DictionaryId",
"description": "The reference name of the dictionary, used with program language settings"
},
"path": {
"$ref": "#/definitions/CustomDictionaryPath",
"description": "Path to custom dictionary text file."
},
"repMap": {
"$ref": "#/definitions/ReplaceMap",
"description": "Replacement pairs"
},
"scope": {
"anyOf": [
{
"$ref": "#/definitions/CustomDictionaryScope"
},
{
"items": {
"$ref": "#/definitions/CustomDictionaryScope"
},
"type": "array"
}
],
"description": "Defines the scope for when words will be added to the dictionary. Scope values: `user`, `workspace`, `folder`"
},
"useCompounds": {
"description": "Use Compounds",
"type": "boolean"
}
},
"required": [
"addWords",
"name",
"path"
],
"type": "object"
},
"DictionaryDefinitionPreferred": {
"additionalProperties": false,
"properties": {
Expand All @@ -54,7 +124,7 @@
"description": "The reference name of the dictionary, used with program language settings"
},
"path": {
"$ref": "#/definitions/FsPath",
"$ref": "#/definitions/DictionaryPath",
"description": "Path to the file"
},
"repMap": {
Expand All @@ -76,6 +146,11 @@
"description": "This matches the name in a dictionary definition",
"type": "string"
},
"DictionaryPath": {
"description": "A File System Path to a dictionary file.",
"pattern": "^.*\\.(?:txt|trie)(?:\\.gz)?$",
"type": "string"
},
"FsPath": {
"description": "A File System Path",
"type": "string"
Expand Down
81 changes: 78 additions & 3 deletions packages/cspell-types/cspell.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,46 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"definitions": {
"CustomDictionaryPath": {
"description": "A File System Path to a dictionary file.",
"pattern": "^.*\\.txt$",
"type": "string"
},
"CustomDictionaryScope": {
"description": "Specifies the scope of a dictionary.",
"enum": [
"user",
"workspace",
"folder"
],
"type": "string"
},
"DictionaryDefinition": {
"anyOf": [
{
"$ref": "#/definitions/DictionaryDefinitionPreferred"
},
{
"$ref": "#/definitions/DictionaryDefinitionCustom"
},
{
"$ref": "#/definitions/DictionaryDefinitionAlternate"
}
]
},
"DictionaryDefinitionAlternate": {
"additionalProperties": false,
"deprecatedMessage": "Use `DictionaryDefinitionPreferred`",
"description": "Only for legacy dictionary definitions",
"properties": {
"description": {
"description": "Optional description",
"type": "string"
},
"file": {
"$ref": "#/definitions/FsPath",
"description": "Path to the file"
"$ref": "#/definitions/DictionaryPath",
"deprecatedMessage": "Use `path` instead.",
"description": "Path to the file, only for legacy dictionary definitions"
},
"name": {
"$ref": "#/definitions/DictionaryId",
Expand All @@ -42,6 +62,56 @@
],
"type": "object"
},
"DictionaryDefinitionCustom": {
"additionalProperties": false,
"description": "For Defining Custom dictionaries. They are generally scoped to a `user`, `workspace`, or `folder`. When `addWords` is true, indicates that the spell checker can add words to the file. Note: only plain text files with one word per line are supported at this moment.",
"properties": {
"addWords": {
"description": "When `true`, let's the spell checker know that words can be added to this dictionary.",
"type": "boolean"
},
"description": {
"description": "Optional description",
"type": "string"
},
"name": {
"$ref": "#/definitions/DictionaryId",
"description": "The reference name of the dictionary, used with program language settings"
},
"path": {
"$ref": "#/definitions/CustomDictionaryPath",
"description": "Path to custom dictionary text file."
},
"repMap": {
"$ref": "#/definitions/ReplaceMap",
"description": "Replacement pairs"
},
"scope": {
"anyOf": [
{
"$ref": "#/definitions/CustomDictionaryScope"
},
{
"items": {
"$ref": "#/definitions/CustomDictionaryScope"
},
"type": "array"
}
],
"description": "Defines the scope for when words will be added to the dictionary. Scope values: `user`, `workspace`, `folder`"
},
"useCompounds": {
"description": "Use Compounds",
"type": "boolean"
}
},
"required": [
"addWords",
"name",
"path"
],
"type": "object"
},
"DictionaryDefinitionPreferred": {
"additionalProperties": false,
"properties": {
Expand All @@ -54,7 +124,7 @@
"description": "The reference name of the dictionary, used with program language settings"
},
"path": {
"$ref": "#/definitions/FsPath",
"$ref": "#/definitions/DictionaryPath",
"description": "Path to the file"
},
"repMap": {
Expand All @@ -76,6 +146,11 @@
"description": "This matches the name in a dictionary definition",
"type": "string"
},
"DictionaryPath": {
"description": "A File System Path to a dictionary file.",
"pattern": "^.*\\.(?:txt|trie)(?:\\.gz)?$",
"type": "string"
},
"FsPath": {
"description": "A File System Path",
"type": "string"
Expand Down
63 changes: 59 additions & 4 deletions packages/cspell-types/src/settings/CSpellSettingsDef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ export type DictionaryFileTypes = 'S' | 'W' | 'C' | 'T';

export type DictionaryDefinition =
| DictionaryDefinitionPreferred
| DictionaryDefinitionCustom
| DictionaryDefinitionAlternate
| DictionaryDefinitionLegacy;

Expand All @@ -254,18 +255,32 @@ export interface DictionaryDefinitionBase {

export interface DictionaryDefinitionPreferred extends DictionaryDefinitionBase {
/** Path to the file */
path: FsPath;
path: DictionaryPath;

/** @hidden */
/**
* Only for legacy dictionary definitions
* @deprecated
* @deprecatedMessage Use `path` instead.
* @hidden
*/
file?: undefined;
}

/**
* Only for legacy dictionary definitions
* @deprecated
* @deprecatedMessage Use `DictionaryDefinitionPreferred`
*/
export interface DictionaryDefinitionAlternate extends DictionaryDefinitionBase {
/** @hidden */
path?: undefined;

/** Path to the file */
file: FsPath;
/**
* Path to the file, only for legacy dictionary definitions
* @deprecated
* @deprecatedMessage Use `path` instead.
*/
file: DictionaryPath;
}

/**
Expand Down Expand Up @@ -293,6 +308,34 @@ export interface DictionaryDefinitionLegacy extends DictionaryDefinitionBase {
type?: DictionaryFileTypes;
}

/**
* Specifies the scope of a dictionary.
*/
export type CustomDictionaryScope = 'user' | 'workspace' | 'folder';

/**
* For Defining Custom dictionaries. They are generally scoped to a
* `user`, `workspace`, or `folder`.
* When `addWords` is true, indicates that the spell checker can add words
* to the file.
* Note: only plain text files with one word per line are supported at this moment.
*/
export interface DictionaryDefinitionCustom extends DictionaryDefinitionPreferred {
/** Path to custom dictionary text file. */
path: CustomDictionaryPath;

/**
* Defines the scope for when words will be added to the dictionary.
* Scope values: `user`, `workspace`, `folder`
*/
scope?: CustomDictionaryScope | CustomDictionaryScope[];

/**
* When `true`, let's the spell checker know that words can be added to this dictionary.
*/
addWords: boolean;
}

export interface LanguageSetting extends LanguageSettingFilterFields, BaseSetting {}

export interface LanguageSettingFilterFields
Expand Down Expand Up @@ -407,6 +450,18 @@ export type LanguageId = LanguageIdSingle | LanguageIdMultiple | LanguageIdMulti
/** A File System Path */
export type FsPath = string;

/**
* A File System Path to a dictionary file.
* @pattern ^.*\.(?:txt|trie)(?:\.gz)?$
*/
export type DictionaryPath = string;

/**
* A File System Path to a dictionary file.
* @pattern ^.*\.txt$
*/
export type CustomDictionaryPath = string;

export interface RegExpPatternDefinition {
/**
* Pattern name, used as an identifier in ignoreRegExpList and includeRegExpList.
Expand Down

0 comments on commit 196921d

Please sign in to comment.