Skip to content

Commit

Permalink
fix: Make sure to listen for all settings changes. (#484)
Browse files Browse the repository at this point in the history
* Make it easier to debug

* Have `cSpell` section name come from config.

* fix: Issue where new settings are not sent to the server
  • Loading branch information
Jason3S committed May 9, 2020
1 parent 075ec87 commit ffd9a97
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
3 changes: 2 additions & 1 deletion packages/_server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,9 @@ function run() {
const { uri, languageId } = params;
const fileEnabled = uri ? !await isUriExcluded(uri) : undefined;
const settings = await getActiveUriSettings(uri);
const languageEnabled = languageId && uri ? await isLanguageEnabled({ uri, languageId }, settings) : undefined;
return {
languageEnabled: languageId && uri ? await isLanguageEnabled({ uri, languageId }, settings) : undefined,
languageEnabled,
fileEnabled,
};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function handlerApplyTextEdits(client: LanguageClient) {
window.showInformationMessage('Spelling changes are outdated and cannot be applied to the document.');
}
const propertyFixSpellingWithRenameProvider: SpellCheckerSettingsProperties = 'fixSpellingWithRenameProvider';
const cfg = workspace.getConfiguration(CSpellSettings.sectionCSpell);
const cfg = workspace.getConfiguration(Settings.sectionCSpell);
if (cfg.get(propertyFixSpellingWithRenameProvider) && edits.length === 1) {
console.log(`${propertyFixSpellingWithRenameProvider} Enabled`);
const edit = edits[0];
Expand Down
17 changes: 16 additions & 1 deletion packages/client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { performance, toMilliseconds } from './util/perf';
performance.mark('cspell_start_extension');
import * as path from 'path';
performance.mark('import 1');
import {setEnableSpellChecking} from './settings';
import {setEnableSpellChecking, sectionCSpell} from './settings';
performance.mark('import 2');
import * as settings from './settings';
performance.mark('import 3');
Expand Down Expand Up @@ -152,8 +152,23 @@ export async function activate(context: ExtensionContext): Promise<ExtensionApi>
vscode.commands.registerCommand('cSpell.disableCurrentLanguage', commands.disableCurrentLanguage),
vscode.commands.registerCommand('cSpell.logPerfTimeline', dumpPerfTimeline),
settings.watchSettingsFiles(triggerGetSettings),

/*
* We need to listen for all change events and see of `cSpell` section changed.
* When it does, we have to trigger the server to fetch the settings again.
* This is to handle a bug in the language-server synchronize configuration. It will not synchronize
* if the section didn't already exist. This leads to a poor user experience in situations like
* adding a word to be ignored for the first time.
*/
vscode.workspace.onDidChangeConfiguration(handleOnDidChangeConfiguration),
);

function handleOnDidChangeConfiguration(event: vscode.ConfigurationChangeEvent) {
if (event.affectsConfiguration(sectionCSpell)) {
triggerGetSettings();
}
}

// infoViewer.activate(context, client);
settingsViewer.activate(context, client);

Expand Down
2 changes: 0 additions & 2 deletions packages/client/src/settings/CSpellSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { unique, uniqueFilter } from '../util';

const currentSettingsFileVersion = '0.1';

export const sectionCSpell = 'cSpell';

export const defaultFileName = 'cSpell.json';

export interface CSpellSettings extends CSpellUserSettingsWithComments {
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/statusbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as vscode from 'vscode';
import { CSpellClient } from './client';
import * as infoViewer from './infoViewer';
import { isSupportedUri, isSupportedDoc } from './util';
import { sectionCSpell } from './settings/CSpellSettings';
import { sectionCSpell } from './settings';


export function initStatusBar(context: ExtensionContext, client: CSpellClient) {
Expand Down

0 comments on commit ffd9a97

Please sign in to comment.