Skip to content

Commit

Permalink
feat: Add checkOnlyEnabledFileTypes option (#1954)
Browse files Browse the repository at this point in the history
* refactor: how enabled file types are calculated

* feat: Add `checkOnlyEnabledFileTypes` option

* Support `*` in `enableFiletypes`

* Update docs
  • Loading branch information
Jason3S authored May 17, 2022
1 parent 2ea2b84 commit 37cacc1
Show file tree
Hide file tree
Showing 8 changed files with 222 additions and 72 deletions.
53 changes: 47 additions & 6 deletions docs/_includes/generated-docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,8 @@ Scope

Description
: Show CSpell in-document directives as you type.
**Note:** VS Code must be restarted for this setting to take effect.

**Note:** VS Code must be restarted for this setting to take effect.

Default
: _`false`_
Expand Down Expand Up @@ -608,6 +609,7 @@ Default
| Setting | Scope | Description |
| ---------------------------------------------------------------------------- | -------- | ---------------------------------------------------------------------------------------------- |
| [`cSpell.allowedSchemas`](#cspellallowedschemas) | window | Control which file schemas will be checked for spelling (VS Code must be restarted for this… |
| [`cSpell.checkOnlyEnabledFileTypes`](#cspellcheckonlyenabledfiletypes) | resource | Check Only Enabled File Types |
| [`cSpell.enableFiletypes`](#cspellenablefiletypes) | resource | File Types to Check |
| [`cSpell.files`](#cspellfiles) | resource | Glob patterns of files to be checked. |
| [`cSpell.globRoot`](#cspellglobroot) | resource | The root to use for glop patterns found in this configuration. |
Expand Down Expand Up @@ -644,6 +646,29 @@ Default

---

### `cSpell.checkOnlyEnabledFileTypes`

Name
: `cSpell.checkOnlyEnabledFileTypes` -- Check Only Enabled File Types

Type
: boolean

Scope
: resource

Description
: By default, the spell checker checks only enabled file types. Use `cSpell.enableFiletypes`
to turn on / off various file types.

When this setting is `false`, all file types are checked except for the ones disabled by `cSpell.enableFiletypes`.
See `cSpell.enableFiletypes` on how to disable a file type.

Default
: _`true`_

---

### `cSpell.enableFiletypes`

Name
Expand All @@ -657,16 +682,25 @@ Scope

Description
: Enable / Disable checking file types (languageIds).
These are in additional to the file types specified by `cSpell.enabledLanguageIds`.
To disable a language, prefix with `!` as in `!json`,

Example:
These are in additional to the file types specified by `cSpell.enabledLanguageIds`.
To disable a language, prefix with `!` as in `!json`,


**Example: individual file types**
```
jsonc // enable checking for jsonc
!json // disable checking for json
kotlin // enable checking for kotlin
```


**Example: enable all file types**
```
* // enable checking for all file types
!json // except for json
```

Default
: _- none -_

Expand Down Expand Up @@ -793,7 +827,7 @@ Description
: Only spell check files that are in the currently open workspace.
This same effect can be achieved using the `files` setting.

```
```js
"cSpell.files": ["**"]
```

Expand Down Expand Up @@ -859,7 +893,8 @@ By default it is the first folder.

This is used to find the `cspell.json` file for the workspace.

Example: use the `client` folder

**Example: use the `client` folder**
```
${workspaceFolder:client}
```
Expand Down Expand Up @@ -899,8 +934,10 @@ Description
A chunk is the characters between absolute word breaks.
Absolute word breaks match: `/[\s,{}[\]]/`


**Error Message:** _Average Word Size is Too High._


If you are seeing this message, it means that the file contains mostly long lines
without many word breaks.

Expand All @@ -926,6 +963,7 @@ Description
Block spell checking if lines are longer than the value given.
This is used to prevent spell checking generated files.


**Error Message:** _Lines are too long._

Default
Expand All @@ -949,11 +987,14 @@ Description

It is used to prevent spell checking of generated files.


A chunk is the characters between absolute word breaks.
Absolute word breaks match: `/[\s,{}[\]]/`, i.e. spaces or braces.


**Error Message:** _Maximum Word Length is Too High._


If you are seeing this message, it means that the file contains a very long line
without many word breaks.

Expand Down
46 changes: 26 additions & 20 deletions package.json

Large diffs are not rendered by default.

46 changes: 26 additions & 20 deletions packages/_server/spell-checker-config.schema.json

Large diffs are not rendered by default.

70 changes: 64 additions & 6 deletions packages/_server/src/config/cspellConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface SpellCheckerSettings extends SpellCheckerShouldCheckDocSettings
* @markdownDescription
* Control which file schemas will be checked for spelling (VS Code must be restarted for this setting to take effect).
*
*
* Some schemas have special meaning like:
* - `untitled` - Used for new documents that have not yet been saved
* - `vscode-notebook-cell` - Used for validating segments of a Notebook.
Expand Down Expand Up @@ -90,9 +91,9 @@ export interface SpellCheckerSettings extends SpellCheckerShouldCheckDocSettings
showStatusAlignment?: 'Left' | 'Right';

/**
* Show CSpell in-document directives as you type.
* @markdownDescription
* Show CSpell in-document directives as you type.
*
* **Note:** VS Code must be restarted for this setting to take effect.
* @scope language-overridable
* @default false
Expand Down Expand Up @@ -125,18 +126,40 @@ export interface SpellCheckerSettings extends SpellCheckerShouldCheckDocSettings
* @uniqueItems true
* @markdownDescription
* Enable / Disable checking file types (languageIds).
*
* These are in additional to the file types specified by `cSpell.enabledLanguageIds`.
* To disable a language, prefix with `!` as in `!json`,
*
* Example:
*
* **Example: individual file types**
* ```
* jsonc // enable checking for jsonc
* !json // disable checking for json
* kotlin // enable checking for kotlin
* ```
*
*
* **Example: enable all file types**
* ```
* * // enable checking for all file types
* !json // except for json
* ```
*/
enableFiletypes?: EnableFileTypeId[];

/**
* @title Check Only Enabled File Types
* @scope resource
* @default true
* @markdownDescription
* By default, the spell checker checks only enabled file types. Use `cSpell.enableFiletypes`
* to turn on / off various file types.
*
* When this setting is `false`, all file types are checked except for the ones disabled by `cSpell.enableFiletypes`.
* See `cSpell.enableFiletypes` on how to disable a file type.
*/
checkOnlyEnabledFileTypes?: boolean;

/**
* @title Workspace Root Folder Path
* @scope resource
Expand All @@ -146,7 +169,8 @@ export interface SpellCheckerSettings extends SpellCheckerShouldCheckDocSettings
*
* This is used to find the `cspell.json` file for the workspace.
*
* Example: use the `client` folder
*
* **Example: use the `client` folder**
* ```
* ${workspaceFolder:client}
* ```
Expand Down Expand Up @@ -193,6 +217,7 @@ export interface SpellCheckerSettings extends SpellCheckerShouldCheckDocSettings
* Define custom dictionaries to be included by default.
* If `addWords` is `true` words will be added to this dictionary.
*
*
* **Example:**
*
* ```js
Expand All @@ -217,7 +242,8 @@ export interface SpellCheckerSettings extends SpellCheckerShouldCheckDocSettings
* Only spell check files that are in the currently open workspace.
* This same effect can be achieved using the `files` setting.
*
* ```
*
* ```js
* "cSpell.files": ["**"]
* ```
* @default false
Expand All @@ -243,6 +269,16 @@ export interface SpellCheckerSettings extends SpellCheckerShouldCheckDocSettings
'experimental.enableRegexpView'?: boolean;
}

interface InternalSettings {
/**
* Map of known and enabled file types.
* `true` - enabled
* `false` - disabled
* @hidden
*/
mapOfEnabledFileTypes?: Map<string, boolean>;
}

/**
* @title Named dictionary to be enabled / disabled
* @markdownDescription
Expand All @@ -256,13 +292,14 @@ type EnableCustomDictionary = boolean;
* Enable / Disable checking file types (languageIds).
* To disable a language, prefix with `!` as in `!json`,
*
*
* Example:
* ```
* jsonc // enable checking for jsonc
* !json // disable checking for json
* kotlin // enable checking for kotlin
* ```
* @pattern ^!?(?!\s)[\s\w_.\-]+$
* @pattern (^!*(?!\s)[\s\w_.\-]+$)|(^!*[*]$)
* @patternErrorMessage "Allowed characters are `a-zA-Z`, `.`, `-`, `_` and space."
*/
type EnableFileTypeId = string;
Expand All @@ -272,11 +309,14 @@ interface SpellCheckerShouldCheckDocSettings {
* @markdownDescription
* The maximum line length.
*
*
* Block spell checking if lines are longer than the value given.
* This is used to prevent spell checking generated files.
*
*
* **Error Message:** _Lines are too long._
*
*
* @scope language-overridable
* @default 10000
*/
Expand All @@ -285,13 +325,17 @@ interface SpellCheckerShouldCheckDocSettings {
* @markdownDescription
* The maximum length of a chunk of text without word breaks.
*
*
* It is used to prevent spell checking of generated files.
*
*
* A chunk is the characters between absolute word breaks.
* Absolute word breaks match: `/[\s,{}[\]]/`, i.e. spaces or braces.
*
*
* **Error Message:** _Maximum Word Length is Too High._
*
*
* If you are seeing this message, it means that the file contains a very long line
* without many word breaks.
*
Expand All @@ -303,11 +347,14 @@ interface SpellCheckerShouldCheckDocSettings {
* @markdownDescription
* The maximum average length of chunks of text without word breaks.
*
*
* A chunk is the characters between absolute word breaks.
* Absolute word breaks match: `/[\s,{}[\]]/`
*
*
* **Error Message:** _Average Word Size is Too High._
*
*
* If you are seeing this message, it means that the file contains mostly long lines
* without many word breaks.
*
Expand Down Expand Up @@ -338,8 +385,10 @@ export interface CustomDictionary {
* @markdownDescription
* The reference name of the dictionary.
*
*
* Example: `My Words` or `custom`
*
*
* If they name matches a pre-defined dictionary, it will override the pre-defined dictionary.
* If you use: `typescript` it will replace the built-in TypeScript dictionary.
*/
Expand All @@ -357,27 +406,34 @@ export interface CustomDictionary {
* @markdownDescription
* Define the path to the dictionary text file.
*
*
* **Note:** if path is `undefined` the `name`d dictionary is expected to be found
* in the `dictionaryDefinitions`.
*
*
* File Format: Each line in the file is considered a dictionary entry.
*
*
* Case is preserved while leading and trailing space is removed.
*
*
* The path should be absolute, or relative to the workspace.
*
*
* **Example:** relative to User's folder
*
* ```
* ~/dictionaries/custom_dictionary.txt
* ```
*
*
* **Example:** relative to the `client` folder in a multi-root workspace
*
* ```
* ${workspaceFolder:client}/build/custom_dictionary.txt
* ```
*
*
* **Example:** relative to the current workspace folder in a single-root workspace
*
* **Note:** this might no as expected in a multi-root workspace since it is based upon the relative
Expand All @@ -387,6 +443,7 @@ export interface CustomDictionary {
* ${workspaceFolder}/build/custom_dictionary.txt
* ```
*
*
* **Example:** relative to the workspace folder in a single-root workspace or the first folder in
* a multi-root workspace
*
Expand Down Expand Up @@ -733,7 +790,7 @@ type GlobDefX = GlobDef;

export interface CustomDictionaryWithScope extends CustomDictionary {}

export interface CSpellUserSettings extends SpellCheckerSettings, CSpellSettingsPackageProperties {}
export interface CSpellUserSettings extends SpellCheckerSettings, CSpellSettingsPackageProperties, InternalSettings {}

export type SpellCheckerSettingsProperties = keyof SpellCheckerSettings;
export type SpellCheckerSettingsVSCodePropertyKeys = `cspell.${keyof CSpellUserSettings}`;
Expand Down Expand Up @@ -891,6 +948,7 @@ type VSConfigFilesAndFolders = PrefixWithCspell<_VSConfigFilesAndFolders>;
type _VSConfigFilesAndFolders = Pick<
SpellCheckerSettingsVSCodeBase,
| 'allowedSchemas'
| 'checkOnlyEnabledFileTypes'
| 'enableFiletypes'
| 'files'
| 'globRoot'
Expand Down
Loading

0 comments on commit 37cacc1

Please sign in to comment.