Skip to content

add change spelling language command; apply dictionary changes live - #18766

Merged
kevinushey merged 4 commits into
mainfrom
feature/spellcheck-language-switch
Sep 11, 2026
Merged

kevinushey merged 4 commits into
mainfrom
feature/spellcheck-language-switch

Conversation

@kevinushey

@kevinushey kevinushey commented Sep 10, 2026 •

Copy link
Copy Markdown
Collaborator

Intent

Switching the spelling dictionary takes one step and takes effect immediately:

  • Edit > Change Spelling Language... (also in the Command Palette) opens a small picker with the installed dictionaries (plus the usual "Install more languages..." entry) and applies the choice on OK.
  • Dictionary changes -- from that dialog, from Global Options > Spelling, or from Project Options > Spelling -- now re-check open documents right away. No restart.

Fixes #12223.

Approach

Two things made the old flow need a restart:

  • RealtimeSpellChecker registered a no-op handler for spelling_dictionary_language changes and kept per-session correctWords / incorrectWords caches, so a stale "misspelled" verdict survived the switch. It now clears both caches and re-checks the document (invalidateAllWords()) when the language changes.
  • SpellingPreferencesPane.onApply() flagged a language change as requiring a desktop restart; that flag is dropped (custom-dictionary edits keep it).

The new changeSpellingLanguage command is handled in WorkbenchScreen next to showSpellingOptions; ChangeSpellingLanguageDialog reuses SpellingLanguageSelectWidget. The dialog persists whichever layer is currently in effect, so the picker and the server agree afterwards:

  • With no project override, it writes the global user pref and leaves the project alone.
  • When the project sets its own dictionary, it rewrites SpellingDictionary: in the .Rproj (the same write Project Options > Spelling performs) and leaves the global pref alone. Note that this produces a diff in the .Rproj if it is under version control.

Follow-up commits on this branch harden the live update:

  • SpellingService re-checks only after the server confirms the pref or project-config write, and tags in-flight check_spelling / suggestion requests with a dictionary generation so a slow response from the old dictionary is retried rather than cached.
  • Full pref-layer updates (full_layer) replace the layer wholesale in every editor window, so clearing a project override falls back to the global default instead of leaving a stale project value behind.
  • The installed-dictionary metadata returned by "Install more languages..." is written back into the shared spellingPrefsContext, so a reopened picker lists the new dictionaries.

Testing

New Playwright suite tests/panes/editor/spelling_language_switch.test.ts:

  • opens an Rmd containing "colour", confirms the realtime checker flags it under en_US, switches to en_GB through the dialog and sees the flag disappear without a reload, then switches back and sees it return;
  • with a project that sets SpellingDictionary: en_US, switches via the dialog and checks the .Rproj now reads SpellingDictionary: en_GB;
  • delays the old dictionary's check_spelling response and confirms it cannot restore stale results;
  • clears a project dictionary and confirms an open detached editor is re-checked;
  • installs more dictionaries and confirms they remain listed when the picker reopens.

New GWT unit tests in PrefsTests cover full-layer replacement. rmarkdown.test.ts and global_prefs_panels.test.ts still pass locally in desktop-dev mode.

Checklist

  • NEWS.md entry
  • e2e test
  • Commands.cmd.xml.MD5 updated

Edit > Change Spelling Language... (also in the command palette) opens a
small picker built on SpellingLanguageSelectWidget and applies the choice
immediately. Two things previously forced a restart: the realtime spell
checker ignored dictionary changes (no-op handler) and kept per-session
word caches, and the Spelling prefs pane flagged a language change as
requiring a desktop restart. Both are fixed.

Addresses #12223
@github-actions

github-actions Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

RStudio E2E - all platforms

1 test(s) failed

###################- 99% pass rate

Passed Failed Skipped Flaky
2786 1 186 6
Platform ✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
✅ auth-teardown 2 0 10 0
❌ desktop-linux 698 1 38 3
✅ desktop-macos 707 0 33 1
✅ desktop-windows 705 0 41 0
✅ server-linux 646 0 44 2
✅ setup 28 0 20 0
View / download the full report

View report online -- opens in the browser, no download needed. Available for 14 days.

Download playwright-report.zip -- extract and open index.html

Includes screenshots, traces, and step-by-step details for every test. Expires in 15 days.


All platforms - commit fbb5afba89688ab390e50dff242b83eba12e17b9 - Run #959

Persist the effective dictionary, recheck after confirmed preference changes, and reject stale spelling responses. Cover project overrides and delayed responses in the spelling tests.

Addresses #12223.
Replace complete preference layers in every editor window so removed project overrides fall back correctly. Retain installed dictionary metadata for reopened language pickers, with unit and desktop regression coverage.

Addresses #12223.

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No blocking issues. 0 blocking, 0 follow-up, 1 nit

🔴 must be resolved before merge. 🟠 is real but not merge-blocking — either address it here or open an issue to do so later. 🟡 is optional.

  • 🟡 src/gwt/src/org/rstudio/studio/client/common/spelling/ui/ChangeSpellingLanguageDialog.java:101 — PR description says the opposite of what this branch does when a project sets its own dictionary


// Persist the effective layer so the server and the picker agree, and
// leave the global default alone when this project overrides it.
if (language.hasProjectValue())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 The PR body says applying the change sets the global pref and leaves the .Rproj alone. When the project sets its own dictionary, this branch does the reverse.
Fix the "Approach" paragraph to match: when the project overrides the dictionary, the dialog rewrites SpellingDictionary: in the .Rproj and doesn't touch the global pref.

Why

The e2e test "a project dictionary change reaches the server and persists in the project" checks that the .Rproj gets written, so the code does this on purpose. Only the description is wrong. It still matters for reviewers, because the .Rproj is often under version control. Picking a language from an Edit-menu command now produces a diff in a committed file.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, the description was written against the first commit and the follow-ups changed this. Updated the PR body: with a project override the dialog rewrites SpellingDictionary: in the .Rproj (same write as Project Options > Spelling) and leaves the global pref alone, with a note that this shows up as a diff when the .Rproj is under version control. Without an override it writes only the global pref. Also refreshed the Testing section to cover the tests added since.

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nit but otherwise LGTM!

@kevinushey
kevinushey merged commit c71696e into main Sep 11, 2026
1 of 7 checks passed
@kevinushey
kevinushey deleted the feature/spellcheck-language-switch branch September 11, 2026 23:21
kevinushey added a commit that referenced this pull request Sep 13, 2026
Two linux CI flakes from the PR #18802 run (34712089464):

- spelling_language_switch "rechecks an open detached editor" looked up
  the satellite's Ace editor right after 'domcontentloaded', which is the
  popup's initial document -- GWT mounts the editor later. The lookup
  throws until then, and expect.poll propagates a throw instead of
  retrying, so the test died ~70ms after the popup opened. Red on
  desktop-linux since #18766 and now on linux-server too. Poll with
  toPass so the throw is retried.

- highlight_active_tabs read the selected tab's indicator geometry once.
  Selecting a partly hidden tab animates the strip to reveal it, and
  DocTabLayoutPanel keeps the clipped (position: absolute) variant until
  that scroll settles, so a one-shot read could see 'absolute' where the
  test expects 'fixed'. Poll the geometry until it settles.

This branch was previously deployed

1 inactive deployment
e2e-playwright — fbb5afba Deployed Sep 11, 2026 by kevinushey via windows / e2e-desktop-windows (5) #959
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] Easier way to switch spellchecker language

2 participants