Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/cspell-lib/src/lib/Settings/InDocSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,20 @@ describe('Validate InDocSettings', () => {
expect([...InDoc.validateInDocumentSettings(text, {})]).toEqual([]);
});

test.each`
text | expected
${'cspell\u003Alocale en'} | ${'en'}
${'cspell\u003Alocale en-->'} | ${'en'}
${'<!-- cspell\u003Alocale en -->'} | ${'en'}
${'<!-- cspell\u003Alocale th,en -->'} | ${'th,en'}
${'<!--- cspell\u003Alanguage es-ES --->'} | ${'es-ES'}
${'/* cspell\u003Alocale en */'} | ${'en'}
${'/* cspell\u003Alocale en-US, nl-NL */'} | ${'en-US,nl-NL'}
${'/* cspell\u003Alocale en*/'} | ${'en'}
`('locale directive ignores comment closers: $text', ({ text, expected }) => {
expect(InDoc.getInDocumentSettings(text).language).toBe(expected);
});

test.each`
test | text | expected
${'Empty Doc'} | ${''} | ${{ id: 'in-doc-settings' }}
Expand Down
6 changes: 5 additions & 1 deletion packages/cspell-lib/src/lib/Settings/InDocSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,11 @@ function parseWords(acc: CSpellUserSettings, match: string): CSpellUserSettings
}

function parseLocale(acc: CSpellUserSettings, match: string): CSpellUserSettings {
const parts = match.trim().split(/[\s,]+/);
// Remove the closing marker of an HTML or block comment, it is not a locale.
const parts = match
.replace(/\s*(?:-{2,}>|\*+\/)\s*$/, '')
.trim()
.split(/[\s,]+/);
const language = parts.slice(1).join(',');
if (language) {
acc.language = language;
Expand Down
Loading