Skip to content

Commit

Permalink
fix: Add enableCaseSensitive/disableCaseSensitive (#1951)
Browse files Browse the repository at this point in the history
* fix: Add `enableCaseSensitive`/`disableCaseSensitive`
   Support `enableCaseSensitive`/`disableCaseSensitive` in document settings.
  • Loading branch information
Jason3S authored Nov 4, 2021
1 parent 430bb61 commit 93387b7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions packages/cspell-lib/src/Settings/InDocSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ describe('Validate InDocSettings', () => {
test | text | expected
${'Empty Doc'} | ${''} | ${{ id: 'in-doc-settings' }}
${'sampleTextWithIncompleteInDocSetting'} | ${sampleTextWithIncompleteInDocSetting} | ${oc({ words: ['const'], ignoreWords: ['popoutlist', 'again'], dictionaries: ['php'] })}
${'enableCaseSensitive'} | ${'// cspell:enableCaseSensitive'} | ${oc({ caseSensitive: true })}
${'disableCaseSensitive'} | ${'// cspell:disableCaseSensitive'} | ${oc({ caseSensitive: false })}
`('extract setting: $test', ({ text, expected }) => {
expect(InDoc.getInDocumentSettings(text)).toEqual(expected);
});
Expand Down
6 changes: 6 additions & 0 deletions packages/cspell-lib/src/Settings/InDocSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function parseSettingMatch(matchArray: RegExpMatchArray): CSpellUserSettings[] {
const possibleSetting = match.trim();
const settingParsers: [RegExp, (m: string) => CSpellUserSettings][] = [
[/^(?:enable|disable)(?:allow)?CompoundWords/i, parseCompoundWords],
[/^(?:enable|disable)CaseSensitive/i, parseCaseSensitive],
[/^words?\s/i, parseWords],
[/^ignore(?:words?)?\s/i, parseIgnoreWords],
[/^ignore_?Reg_?Exp\s+.+$/i, parseIgnoreRegExp],
Expand All @@ -47,6 +48,11 @@ function parseCompoundWords(match: string): CSpellUserSettings {
return { id: 'in-doc-allowCompoundWords', allowCompoundWords };
}

function parseCaseSensitive(match: string): CSpellUserSettings {
const caseSensitive = /enable/i.test(match);
return { id: 'in-doc-caseSensitive', caseSensitive };
}

function parseWords(match: string): CSpellUserSettings {
const words = match.split(/[,\s]+/g).slice(1);
return { id: 'in-doc-words', words };
Expand Down
6 changes: 3 additions & 3 deletions packages/cspell-trie-lib/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/cspell-trie-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
},
"devDependencies": {
"@cspell/dict-en_us": "^2.1.3",
"@cspell/dict-es-es": "^2.0.2",
"@cspell/dict-es-es": "^2.1.0",
"@types/fs-extra": "^9.0.13",
"@types/node": "^16.11.6",
"jest": "^27.3.1",
Expand Down
2 changes: 2 additions & 0 deletions packages/cspell-trie-lib/src/lib/suggest-es.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ function getTrie() {
describe('Validate Spanish Suggestions', () => {
// cspell:locale en,es
// cspell:ignore Carmjen
// cspell:disableCaseSensitive
// cspell:ignore barcelona carmjen nino
test.each`
word | ignoreCase | expectedWords
${'carmjen'} | ${false} | ${['carmen', 'carmene', 'carmena', 'carmená', 'carmené', 'carmeno', 'carmenó', 'carmenen']}
Expand Down

0 comments on commit 93387b7

Please sign in to comment.