Skip to content

Add dialect setting with optional fallback dialects#49

Open
sammcj wants to merge 1 commit into
MarkEdit-app:mainfrom
sammcj:language_preference
Open

Add dialect setting with optional fallback dialects#49
sammcj wants to merge 1 commit into
MarkEdit-app:mainfrom
sammcj:language_preference

Conversation

@sammcj
Copy link
Copy Markdown

@sammcj sammcj commented May 20, 2026

Adds two settings to extension.markeditProofreading that let you choose which English dialect Harper checks against, and optionally accept spellings from additional dialects.

Harper supports several English dialects, but the extension always used the default (American), so non-American spellings like "colour" and "organisation" were flagged as misspellings with no way to change it.

Closes #48

What changed

  • dialect: the English dialect Harper checks against. One of "American" (default), "British", "Australian", "Canadian", or "Indian". It is passed to Harper via setDialect, so it controls both which spellings
    are flagged and which spellings suggestions prefer.
  • dialectFallbacks: additional dialects whose spellings are also accepted (default []). A Spelling lint from the primary dialect is kept only if every fallback dialect also flags the same word; if any fallback accepts the word, it is not flagged. Suggestions always come from the primary dialect.

Example

{
  "extension.markeditProofreading": {
    "dialect": "Australian",
    "dialectFallbacks": ["American"]
  }
}

With this config, Australian spellings are suggested for genuine misspellings, while American spellings such as "color" and "organization" are accepted rather than flagged. With dialectFallbacks omitted, those American spellings would be flagged.

Implementation notes

  • Dialect names are parsed and validated in settings.ts as plain strings, which keeps that module free of the harper.js (WebAssembly) import so it stays fast to unit test. Invalid names, duplicates, and the primary dialect are dropped from the fallback list.
  • lint.ts maps the names to Harper's Dialect enum, sets the dialect on the linter, and creates one extra LocalLinter per fallback dialect used only to test whether a word is an accepted spelling there.
  • Fallback filtering runs one extra lint pass per fallback dialect and is skipped entirely when no fallbacks are configured. The keep/drop decision lives in a small pure helper (fallback.ts) so it can be unit tested without loading WebAssembly.

Behaviour and compatibility

Defaults preserve the previous behaviour: dialect defaults to "American" and dialectFallbacks to [], so existing installs lint exactly as before unless these settings are set.

Testing

  • New unit tests in tests/settings.test.ts cover dialect parsing, the default, an unrecognised dialect, and fallback list cleaning (invalid names, duplicates, primary dialect, non-array input).
  • New tests/fallback.test.ts covers the keep/drop helper.
  • yarn lint, yarn test (72 passing), and yarn build all pass.

Notes

Per the contribution guidelines, happy to scope this down if preferred: the dialect setting is a thin pass-through to Harper's native setDialect and stands on its own, while dialectFallbacks is the more opinionated part (it adds one lint pass per fallback). The two are cleanly separable if you would rather land dialect first.

Harper can lint against different English dialects, but the extension
always used the default (American), so non-American spellings like
"colour" and "organisation" were flagged as misspellings with no way to
change it.

Add a `dialect` setting accepting "American" (default), "British",
"Australian", "Canadian", or "Indian". It is passed to Harper via
`setDialect`, so it controls both which spellings are flagged and which
spellings suggestions prefer.

Add a `dialectFallbacks` setting listing additional dialects whose
spellings are also accepted. A Spelling lint from the primary dialect is
kept only if every fallback dialect also flags the same span; if any
fallback accepts the word it is not flagged. This lets you, for example,
prefer Australian suggestions while still accepting American spellings.
Suggestions always come from the primary dialect.

Implementation:
- Dialect names are parsed and validated in settings.ts as plain strings,
  keeping that module free of the harper.js (WebAssembly) import so it
  stays fast to unit test. Invalid names, duplicates, and the primary
  dialect are dropped from the fallback list.
- lint.ts maps the names to Harper's Dialect enum, sets the dialect on
  the linter, and creates one extra LocalLinter per fallback dialect used
  only to test whether a word is an accepted spelling there.
- Fallback filtering runs one extra lint pass per fallback dialect and is
  skipped entirely when none are configured. The keep/drop decision lives
  in a small pure helper (fallback.ts) so it can be unit tested without
  loading WebAssembly.

Defaults preserve the previous behaviour (American, no fallbacks). README
documents both settings; new unit tests cover settings parsing and the
fallback decision.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: configurable Harper dialect with optional fallback dialects

1 participant