Skip to content

Commit 7fcbef9

Browse files
authored
fix: Make sure open settings works as expected. (#4352)
1 parent ece48f5 commit 7fcbef9

File tree

8 files changed

+72
-35
lines changed

8 files changed

+72
-35
lines changed

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3831,20 +3831,20 @@
38313831
"order": 4,
38323832
"properties": {
38333833
"cSpell.blockCheckingWhenAverageChunkSizeGreaterThan": {
3834-
"default": 80,
3835-
"markdownDescription": "The maximum average length of chunks of text without word breaks.\n\n\nA chunk is the characters between absolute word breaks.\nAbsolute word breaks match: `/[\\s,{}[\\]]/`\n\n\n**Error Message:** _Average word length is too long._\n\n\nIf you are seeing this message, it means that the file contains mostly long lines\nwithout many word breaks.",
3834+
"default": 200,
3835+
"markdownDescription": "The maximum average length of chunks of text without word breaks.\n\n\nA chunk is the characters between absolute word breaks.\nAbsolute word breaks match: `/[\\s,{}[\\]]/`\n\n\n**Error Message:** _Average word length is too long._\n\n\nIf you are seeing this message, it means that the file contains mostly long lines\nwithout many word breaks.\n\n\nHide this message using `#cSpell.enabledNotifications#`",
38363836
"scope": "language-overridable",
38373837
"type": "number"
38383838
},
38393839
"cSpell.blockCheckingWhenLineLengthGreaterThan": {
3840-
"default": 10000,
3841-
"markdownDescription": "The maximum line length.\n\n\nBlock spell checking if lines are longer than the value given.\nThis is used to prevent spell checking generated files.\n\n\n**Error Message:** _Lines are too long._",
3840+
"default": 20000,
3841+
"markdownDescription": "The maximum line length.\n\n\nBlock spell checking if lines are longer than the value given.\nThis is used to prevent spell checking generated files.\n\n\n**Error Message:** _Lines are too long._\n\n\nHide this message using `#cSpell.enabledNotifications#`",
38423842
"scope": "language-overridable",
38433843
"type": "number"
38443844
},
38453845
"cSpell.blockCheckingWhenTextChunkSizeGreaterThan": {
3846-
"default": 500,
3847-
"markdownDescription": "The maximum length of a chunk of text without word breaks.\n\n\nIt is used to prevent spell checking of generated files.\n\n\nA chunk is the characters between absolute word breaks.\nAbsolute word breaks match: `/[\\s,{}[\\]]/`, i.e. spaces or braces.\n\n\n**Error Message:** _Maximum word length exceeded._\n\n\nIf you are seeing this message, it means that the file contains a very long line\nwithout many word breaks.",
3846+
"default": 1000,
3847+
"markdownDescription": "The maximum length of a chunk of text without word breaks.\n\n\nIt is used to prevent spell checking of generated files.\n\n\nA chunk is the characters between absolute word breaks.\nAbsolute word breaks match: `/[\\s,{}[\\]]/`, i.e. spaces or braces.\n\n\n**Error Message:** _Maximum word length exceeded._\n\n\nIf you are seeing this message, it means that the file contains a very long line\nwithout many word breaks.\n\n\nHide this message using `#cSpell.enabledNotifications#`",
38483848
"scope": "language-overridable",
38493849
"type": "number"
38503850
},
@@ -3927,7 +3927,7 @@
39273927
"Lines too Long": true,
39283928
"Maximum Word Length Exceeded": true
39293929
},
3930-
"markdownDescription": "Control which notifications are displayed.",
3930+
"markdownDescription": "Control which notifications are displayed.\n\nSee:\n- `#cSpell.blockCheckingWhenLineLengthGreaterThan#`\n- `#cSpell.blockCheckingWhenTextChunkSizeGreaterThan#`\n- `#cSpell.blockCheckingWhenAverageChunkSizeGreaterThan#`",
39313931
"properties": {
39323932
"Average Word Length too Long": {
39333933
"markdownDescription": "Enable notifications if the average word size is too high.",

packages/_server/spell-checker-config.schema.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3489,23 +3489,23 @@
34893489
"order": 4,
34903490
"properties": {
34913491
"cSpell.blockCheckingWhenAverageChunkSizeGreaterThan": {
3492-
"default": 80,
3493-
"description": "The maximum average length of chunks of text without word breaks.\n\n\nA chunk is the characters between absolute word breaks. Absolute word breaks match: `/[\\s,{}[\\]]/`\n\n\n**Error Message:** _Average word length is too long._\n\n\nIf you are seeing this message, it means that the file contains mostly long lines without many word breaks.",
3494-
"markdownDescription": "The maximum average length of chunks of text without word breaks.\n\n\nA chunk is the characters between absolute word breaks.\nAbsolute word breaks match: `/[\\s,{}[\\]]/`\n\n\n**Error Message:** _Average word length is too long._\n\n\nIf you are seeing this message, it means that the file contains mostly long lines\nwithout many word breaks.",
3492+
"default": 200,
3493+
"description": "The maximum average length of chunks of text without word breaks.\n\n\nA chunk is the characters between absolute word breaks. Absolute word breaks match: `/[\\s,{}[\\]]/`\n\n\n**Error Message:** _Average word length is too long._\n\n\nIf you are seeing this message, it means that the file contains mostly long lines without many word breaks.\n\n\nHide this message using `#cSpell.enabledNotifications#`",
3494+
"markdownDescription": "The maximum average length of chunks of text without word breaks.\n\n\nA chunk is the characters between absolute word breaks.\nAbsolute word breaks match: `/[\\s,{}[\\]]/`\n\n\n**Error Message:** _Average word length is too long._\n\n\nIf you are seeing this message, it means that the file contains mostly long lines\nwithout many word breaks.\n\n\nHide this message using `#cSpell.enabledNotifications#`",
34953495
"scope": "language-overridable",
34963496
"type": "number"
34973497
},
34983498
"cSpell.blockCheckingWhenLineLengthGreaterThan": {
3499-
"default": 10000,
3500-
"description": "The maximum line length.\n\n\nBlock spell checking if lines are longer than the value given. This is used to prevent spell checking generated files.\n\n\n**Error Message:** _Lines are too long._",
3501-
"markdownDescription": "The maximum line length.\n\n\nBlock spell checking if lines are longer than the value given.\nThis is used to prevent spell checking generated files.\n\n\n**Error Message:** _Lines are too long._",
3499+
"default": 20000,
3500+
"description": "The maximum line length.\n\n\nBlock spell checking if lines are longer than the value given. This is used to prevent spell checking generated files.\n\n\n**Error Message:** _Lines are too long._\n\n\nHide this message using `#cSpell.enabledNotifications#`",
3501+
"markdownDescription": "The maximum line length.\n\n\nBlock spell checking if lines are longer than the value given.\nThis is used to prevent spell checking generated files.\n\n\n**Error Message:** _Lines are too long._\n\n\nHide this message using `#cSpell.enabledNotifications#`",
35023502
"scope": "language-overridable",
35033503
"type": "number"
35043504
},
35053505
"cSpell.blockCheckingWhenTextChunkSizeGreaterThan": {
3506-
"default": 500,
3507-
"description": "The maximum length of a chunk of text without word breaks.\n\n\nIt is used to prevent spell checking of generated files.\n\n\nA chunk is the characters between absolute word breaks. Absolute word breaks match: `/[\\s,{}[\\]]/`, i.e. spaces or braces.\n\n\n**Error Message:** _Maximum word length exceeded._\n\n\nIf you are seeing this message, it means that the file contains a very long line without many word breaks.",
3508-
"markdownDescription": "The maximum length of a chunk of text without word breaks.\n\n\nIt is used to prevent spell checking of generated files.\n\n\nA chunk is the characters between absolute word breaks.\nAbsolute word breaks match: `/[\\s,{}[\\]]/`, i.e. spaces or braces.\n\n\n**Error Message:** _Maximum word length exceeded._\n\n\nIf you are seeing this message, it means that the file contains a very long line\nwithout many word breaks.",
3506+
"default": 1000,
3507+
"description": "The maximum length of a chunk of text without word breaks.\n\n\nIt is used to prevent spell checking of generated files.\n\n\nA chunk is the characters between absolute word breaks. Absolute word breaks match: `/[\\s,{}[\\]]/`, i.e. spaces or braces.\n\n\n**Error Message:** _Maximum word length exceeded._\n\n\nIf you are seeing this message, it means that the file contains a very long line without many word breaks.\n\n\nHide this message using `#cSpell.enabledNotifications#`",
3508+
"markdownDescription": "The maximum length of a chunk of text without word breaks.\n\n\nIt is used to prevent spell checking of generated files.\n\n\nA chunk is the characters between absolute word breaks.\nAbsolute word breaks match: `/[\\s,{}[\\]]/`, i.e. spaces or braces.\n\n\n**Error Message:** _Maximum word length exceeded._\n\n\nIf you are seeing this message, it means that the file contains a very long line\nwithout many word breaks.\n\n\nHide this message using `#cSpell.enabledNotifications#`",
35093509
"scope": "language-overridable",
35103510
"type": "number"
35113511
},
@@ -3594,8 +3594,8 @@
35943594
"Lines too Long": true,
35953595
"Maximum Word Length Exceeded": true
35963596
},
3597-
"description": "Control which notifications are displayed.",
3598-
"markdownDescription": "Control which notifications are displayed.",
3597+
"description": "Control which notifications are displayed.\n\nSee:\n- `#cSpell.blockCheckingWhenLineLengthGreaterThan#`\n- `#cSpell.blockCheckingWhenTextChunkSizeGreaterThan#`\n- `#cSpell.blockCheckingWhenAverageChunkSizeGreaterThan#`",
3598+
"markdownDescription": "Control which notifications are displayed.\n\nSee:\n- `#cSpell.blockCheckingWhenLineLengthGreaterThan#`\n- `#cSpell.blockCheckingWhenTextChunkSizeGreaterThan#`\n- `#cSpell.blockCheckingWhenAverageChunkSizeGreaterThan#`",
35993599
"properties": {
36003600
"Average Word Length too Long": {
36013601
"description": "Enable notifications if the average word size is too high.",

packages/_server/src/config/cspellConfig/SpellCheckerSettings.mts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,13 @@ export interface SpellCheckerBehaviorSettings {
441441

442442
/**
443443
* Control which notifications are displayed.
444+
*
445+
* See:
446+
* - `#cSpell.blockCheckingWhenLineLengthGreaterThan#`
447+
* - `#cSpell.blockCheckingWhenTextChunkSizeGreaterThan#`
448+
* - `#cSpell.blockCheckingWhenAverageChunkSizeGreaterThan#`
449+
*
450+
*
444451
* @title Enabled Notifications
445452
* @scope resource
446453
* @since 4.0.41

packages/_server/src/config/cspellConfig/SpellCheckerShouldCheckDocSettings.mts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ export interface SpellCheckerShouldCheckDocSettings {
1111
* **Error Message:** _Lines are too long._
1212
*
1313
*
14+
* Hide this message using `#cSpell.enabledNotifications#`
15+
*
1416
* @scope language-overridable
15-
* @default 10000
17+
* @default 20000
1618
*/
1719
blockCheckingWhenLineLengthGreaterThan?: number;
1820

@@ -33,8 +35,11 @@ export interface SpellCheckerShouldCheckDocSettings {
3335
* If you are seeing this message, it means that the file contains a very long line
3436
* without many word breaks.
3537
*
38+
*
39+
* Hide this message using `#cSpell.enabledNotifications#`
40+
*
3641
* @scope language-overridable
37-
* @default 500
42+
* @default 1000
3843
*/
3944
blockCheckingWhenTextChunkSizeGreaterThan?: number;
4045

@@ -52,8 +57,11 @@ export interface SpellCheckerShouldCheckDocSettings {
5257
* If you are seeing this message, it means that the file contains mostly long lines
5358
* without many word breaks.
5459
*
60+
*
61+
* Hide this message using `#cSpell.enabledNotifications#`
62+
*
5563
* @scope language-overridable
56-
* @default 80
64+
* @default 200
5765
*/
5866
blockCheckingWhenAverageChunkSizeGreaterThan?: number;
5967

packages/client/src/actionMenu.mts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import { createDisposableList } from 'utils-disposables';
44
import type { Disposable, QuickPickItem } from 'vscode';
55
import vscode from 'vscode';
66

7-
import { knownCommands } from './commands.mjs';
8-
import { extensionId } from './constants.js';
7+
import { generateOpenSettingsCommand, knownCommands } from './commands.mjs';
98
import { getClient } from './di.mjs';
109
import { updateEnabledFileTypeForResource, updateEnabledSchemesResource } from './settings/settings.mjs';
1110
import { handleErrors } from './util/errors.js';
@@ -58,7 +57,10 @@ async function actionMenu(options: ActionsMenuOptions) {
5857
command: 'workbench.action.openGlobalKeybindings',
5958
arguments: ['Spell:'],
6059
}),
61-
itemCommand({ title: '$(gear) Edit Settings...', command: 'workbench.action.openSettings', arguments: [extensionId] }),
60+
itemCommand({
61+
title: '$(gear) Edit Settings...',
62+
...generateOpenSettingsCommand(),
63+
}),
6264
].filter(isDefined);
6365

6466
return quickPickMenu({ items, title: 'Spell Checker Actions Menu' }).catch(() => undefined);
@@ -250,8 +252,7 @@ function itemDocFileType(uri: vscode.Uri | undefined, fileType: string | undefin
250252
item.buttons = [
251253
new CommandButtonItem(new vscode.ThemeIcon('gear'), {
252254
title: 'Edit Enable File Type in Settings',
253-
command: 'workbench.action.openSettings',
254-
arguments: [ConfigFields.enabledFileTypes],
255+
...generateOpenSettingsCommand(ConfigFields.enabledFileTypes),
255256
}),
256257
];
257258
return item;
@@ -268,8 +269,7 @@ function itemDocScheme(uri: vscode.Uri | undefined, schemeAllowed: boolean | und
268269
item.buttons = [
269270
new CommandButtonItem(new vscode.ThemeIcon('gear'), {
270271
title: 'Edit Enable Scheme in Settings',
271-
command: 'workbench.action.openSettings',
272-
arguments: [ConfigFields.enabledSchemes],
272+
...generateOpenSettingsCommand(ConfigFields.enabledSchemes),
273273
}),
274274
];
275275
return item;

packages/client/src/commands.mts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { actionAutoFixSpellingIssues, handleApplyLsTextEdits, handleFixSpellingI
1414
import type { ClientSideCommandHandlerApi } from './client/index.mjs';
1515
import type { Position as LsPosition, Range as LsRange, TextEdit as LsTextEdit } from './client/vscode-languageclient.js';
1616
import { actionSuggestSpellingCorrections } from './codeActions/actionSuggestSpellingCorrections.mjs';
17+
import { extensionSettings } from './constants.js';
1718
import * as di from './di.mjs';
1819
import { getCSpellDiags } from './diags.mjs';
1920
import { onCommandUseDiagsSelectionOrPrompt } from './promptUser.mjs';
@@ -147,7 +148,7 @@ export const commandHandlers = {
147148
'cSpell.editText': handleApplyLsTextEdits,
148149
'cSpell.logPerfTimeline': dumpPerfTimeline,
149150

150-
'cSpell.openSettings': callCommand('workbench.action.openSettings', () => [{ query: '@ext:streetsidesoftware.code-spell-checker' }]),
151+
'cSpell.openSettings': async () => executeOpenSettingsCommand(),
151152

152153
'cSpell.addWordToCSpellConfig': actionAddWordToCSpell,
153154
'cSpell.addIssuesToDictionary': addAllIssuesFromDocument,
@@ -181,7 +182,7 @@ export const commandHandlers = {
181182

182183
'cspell.showActionsMenu': handlerResolvedLater,
183184

184-
'cSpell.openIssuesPanel': callCommand('cSpellIssuesViewByFile.focus'),
185+
'cSpell.openIssuesPanel': genExecCommandFn('cSpellIssuesViewByFile.focus'),
185186
'cSpell.openFileInfoView': handleDisplayCSpellInfo,
186187
'cSpell.displayCSpellInfo': handleDisplayCSpellInfo,
187188
'cSpell.hideCSpellInfo': handleHideCSpellInfo,
@@ -601,10 +602,17 @@ function handleInsertWordsDirective(textEditor?: TextEditor, _edit?: TextEditorE
601602
}, 'handleInsertWordsDirective');
602603
}
603604

604-
function callCommand<T>(command: string, calcArgs?: () => unknown[]): () => Promise<T> {
605+
export type ExecuteCommand = Omit<Command, 'title'>;
606+
607+
async function execCommand<T = unknown>(command: ExecuteCommand): Promise<T> {
608+
const args = command.arguments || [];
609+
return commands.executeCommand<T>(command.command, ...args);
610+
}
611+
612+
function genExecCommandFn<T>(command: string | ExecuteCommand): () => Promise<T> {
605613
return async () => {
606-
const args = calcArgs?.() || [];
607-
return commands.executeCommand<T>(command, ...args);
614+
command = typeof command === 'string' ? { command } : command;
615+
return execCommand<T>(command);
608616
};
609617
}
610618

@@ -628,3 +636,15 @@ function handleReload() {
628636
function handleCmdExperimentalExecuteDocumentSymbolProvider() {
629637
return handleErrors(experimentWithSymbols(), 'handleCmdExperimentalExecuteDocumentSymbolProvider');
630638
}
639+
640+
export function generateOpenSettingsCommand(setting?: string): ExecuteCommand {
641+
const query = setting ? `${extensionSettings} ${setting}` : extensionSettings;
642+
return {
643+
command: 'workbench.action.openSettings',
644+
arguments: [{ query }],
645+
};
646+
}
647+
648+
export function executeOpenSettingsCommand(setting?: string) {
649+
return execCommand(generateOpenSettingsCommand(setting));
650+
}

packages/client/src/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import type { DiagnosticSource, ExtensionId } from 'code-spell-checker-server/api';
22

3+
export const officialExtensionId = 'streetsidesoftware.code-spell-checker';
34
export const extensionId: ExtensionId = 'cSpell';
45
export const diagnosticSource: DiagnosticSource = extensionId;
6+
export const extensionSettings = '@ext:streetsidesoftware.code-spell-checker';

packages/client/src/extension.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,10 @@ async function notifyUserOfBlockedFile(onBlockFile: OnBlockFile) {
349349
...actions,
350350
);
351351
if (result === openSettings) {
352-
await vscode.commands.executeCommand('workbench.action.openSettings', reason.settingsID);
352+
await commands.executeOpenSettingsCommand(reason.settingsID);
353353
}
354354
if (result === manageNotifications) {
355-
await vscode.commands.executeCommand('workbench.action.openSettings', 'cSpell.enabledNotifications');
355+
await commands.executeOpenSettingsCommand('cSpell.enabledNotifications');
356356
}
357357
} catch {
358358
// ignore

0 commit comments

Comments
 (0)